程序没加按键消抖处理,果然抖得厉害。
/*****************************************************
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 <mega16.h>
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];
}
}