编译器是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;
}
}
一周热门 更多>