单片机 > 单片机程序设计 > 详情

AVR外部中断实验程序

发布时间:2020-08-26 发布时间:
|

简介:用按键控制 1位led数码管显示,只是简单的测试对外部中断的响应。
程序没加按键消抖处理,果然抖得厉害。


/*****************************************************

This program was produced by the

CodeWizardAVR V2.05.5a Evaluation


Date : 2011/12/13

Author : Freeware, for evaluation and

non-commercial use only




Chip type : ATmega16

Program type : Application

AVR Core Clock frequency: 4.000000 MHz

Memory model : Small

External RAM size : 0

Data Stack size : 256

*****************************************************/


#include


flash unsigned char led_7[16] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};


unsigned char counter;



// External Interrupt 0 service routine

interrupt [EXT_INT0] void ext_int0_isr(void)

{

if(++counter >=16) counter = 0;



}


// External Interrupt 1 service routine

interrupt [EXT_INT1] void ext_int1_isr(void)

{

if (counter) -- counter;

else counter = 15 ;


}




void main(void)

{



PORTA=0xFF;

DDRA=0xFF;




// External Interrupt(s) initialization

// INT0: On

// INT0 Mode: Falling Edge

// INT1: On

// INT1 Mode: Falling Edge

// INT2: Off

GICR|=0xC0;

MCUCR=0x0A;

MCUCSR=0x00;

GIFR=0xC0;


counter = 0;


// Global enable interrupts

#asm("sei")


while (1)

{

PORTA = led_7[counter];


}

}



『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
ARM JTAG 调试原理