|
我刚开始学avr,今天写了一个定时的程序试试效果,可出现了一个问题,请各位高手看看。
//ICC-AVR application builder : 2008-10-13 20:56:48
// Target : M8
// Crystal: 4.0000Mhz
#include
#include
int count;
void port_init(void)
{
DDRB=0xF0;
PORTB=0xFF;
}
void timer0_init(void)
{
TCCR0 = 0x00; //stop
TCNT0 = 0x3D; //set count
TCCR0 = 0x05; //start timer
}
#pragma interrupt_handler timer0_ovf_isr:10
void timer0_ovf_isr(void)
{
TCNT0 = 0x3D; //reload counter value
count++;
if(count==200)
{PORTB |= BIT(4);
count=0;
}
}
//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 = 0x00;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void main(void)
{
init_devices();
while (1) {
if ((PINB & BIT(0)) == 0) /*判断是否按下*/
{
PORTB &= ~BIT(4);/*点亮指示灯*/
timer0_init();
}
}
}
问题是灯亮了,但是一直不会灭。检查了好几次都不知道是什么原因,请各位给看看。
|
|