编译器是atmel studio 7
#include <avr/io.h>
#include <avr/interrupt.h>
unsigned int i=0;
int main(void)
{
DDRG|=_BV(PG0);
TCCR0|=_BV(CS02)|_BV(CS00); //1024分频
TCNT0=256-F_CPU/1024*0.001; //定时1ms
tiMSK|=0x01; //开定时器中断
sei();
while (1)
{
}
}
ISR(TIMER0_OVF_vect){
TCNT0=256-F_CPU/1024*0.001; //重装定时1ms
i++;
if(i>300){
PORTG^=_BV(PE0);
i=0;
}
}
#include <avr/io.h>
#include <avr/interrupt.h>
unsigned int i=0;
unsigned char Timer0Flag=0;
int main(void)
{
DDRG|=_BV(PG0);
TCCR0|=_BV(CS02)|_BV(CS00); //1024分频
TCNT0=256-F_CPU/1024*0.001; //定时1ms
TIMSK|=0x01; //开定时器中断
sei();
while (1)
{
if(Timer0Flag){
PORTG^=_BV(PE0);
Timer0Flag=0;
}
}
}
ISR(TIMER0_OVF_vect){
TCNT0=256-F_CPU/1024*0.001; //重装定时1ms
i++;
if(i>300){
//PORTG^=_BV(PE0);
Timer0Flag=1;
i=0;
}
}
这就奇怪了,亲娘不认自己的儿子啊!你用的IDE是正式版吗,如果是BETA版的,出现这样的问题很正常。
一周热门 更多>