//AVR T1 作普通定时器
#include <mega8.h>
#define uchar unsigned char
#define LEDDIR DDRC.2
#define LED PORTC.2
#define SEI SREG|=0x80
uchar i;
void IO_Init(void)
{
LEDDIR="1";
LED="0";
}
void Timer1_time_Init(void)
{
TCCR1A=0;
TCCR1B=0;
TCNT1H=255;
TCNT1L=56;
TIMSK|=0x04;
TIFR="0";
SEI;
TCCR1A=0x00;
TCCR1B=0x02;
}
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
TCNT1H=255;
TCNT1L=56;
if (++i>=250){i=0; LED=!LED;}
}
void main(void)
{
IO_Init();
Timer1_time_Init();
while(1){;;}
}
文章评论(0条评论)
登录后参与讨论