您当前的位置:五五电子网电子知识单片机-工控设备AVR单片机ATMega16单片机外部中断的使用 正文
ATMega16单片机外部中断的使用

ATMega16单片机外部中断的使用

点击数:7198 次   录入时间:03-04 11:58:51   整理:http://www.55dianzi.com   AVR单片机

// Crystal: 7.3728MHz ,功能:学习外部中断0的程序
      #include <iom16v.h>
      #include <macros.h>

      #define LED_COM    PORTA ^= (1 << PA6)           // 
      void port_init(void)
      {
       PORTA = 0x40;
       DDRA  = 0x40;
       PORTB = 0x00;
       DDRB  = 0x00;
       PORTC = 0x00; //m103 output only
       DDRC  = 0x00;
       PORTD = 0x04;
       DDRD  = 0x00;
      }

      #pragma interrupt_handler int0_isr:2
      void int0_isr(void)
      {
        LED_COM;
      }

      //call this routine to initialize all peripherals
      void init_devICes(void)
      {
       //stop errant interrupts until set up
       CLI(); //dISAble all interrupts
       port_init();

       MCUCR = 0x00;
       GICR  = 0x40;
       TIMSK = 0x00; //timer interrupt sources
       SEI(); //re-enable interrupts
       //all peripherals are now initialized
      }

      void main()
      {
        init_devices();
        while(1)
        {
         ;
        }

      }




本文关键字:单片机  AVR单片机单片机-工控设备 - AVR单片机