//T2工作在CTC模式下产生方波信号// By AnalogMaster
#include<mega8.h>
#define uchar unsigned char
#define SEI SREG|=0x80
uchar i;
void IO_Init(void)
{
DDRB.3=1;
PORTB.3=0;
DDRD.1=1;
PORTD.1=0;
}
void Timer2CTC_Init(void)
{
TCCR2=0;
TCNT2=0;
OCR2=200;
TIMSK|=0x80;
TCCR2|=0x9a; //8M
SEI;
}
interrupt [TIM2_COMP] void timer2_comp_isr(void)
{
if (++i>250){i=0;PORTD.1=!PORTD.1;} //50ms
}
void main(void)
{
IO_Init();
Timer2CTC_Init();
while(1){;;}
}
文章评论(0条评论)
登录后参与讨论