AVR Atmega16 Bật Tắt LED Bằng Nút Nhấn - CodeVision

Sơ đồ

Code

Chip type               : ATmega16

Program type            : Application

AVR Core Clock frequency: 8,000000 MHz

Memory model            : Small

External RAM size       : 0

Data Stack size         : 256

 

#include <mega16.h>

#include <delay.h>

#define BT PINA.1

 

void main(void)

{

    DDRA = 0b11111101;    // 1:out,0:in

    PORTA = 0b00000010;   // 1:high,0:low

while (1)

      {

          if(BT==0)

          {

            PORTA.0=~PORTA.0;

            while(BT==0);  

          }

      }

}

Demo: