#include
#include
#define uchar unsigned char
#define uint unsigned int
uint count;
void init()
{
DDRB|=_BV(PB4)|_BV(PB5)|_BV(PB6)|_BV(PB7);
PORTB&=~(_BV(PB4)|_BV(PB5)|_BV(PB6)|_BV(PB7));
TCNT0=155;//初值为55,即记数到255-155=100次溢出并进入定时器0中断函数
TIMSK|=_BV(TOIE0);//溢出中断使能,相当与52的ETO=1;
sei();//开总中断
TCCR0|=_BV(CS01);//8分频,并启动定时器0,8M晶振经过8分频后以1M的速度来记数,即每过1us记数一次,记数100次则为100us,即100us进入一次定时器0中断函数
}
int main()
{
init();
while(1);
}
SIGNAL(SIG_OVERFLOW0)//定时器0中断服务函数,实现LED 1s亮 1s灭
{
TCNT0=155;
count++;
if(count>=10000)
{
count=0;
PORTB^=_BV(PB4)|_BV(PB5)|_BV(PB6)|_BV(PB7);//取反
}
}
『本文转载自网络,版权归原作者所有,如有侵权请联系删除』