怎樣用定時器編寫壹個LED燈間隔1秒鐘亮滅C程序?
#include <reg51.h>
#define uchar unsigned char
sbit LED=P1^0;
uchar time;
void InitTimer0(void)
{
TMOD = 0x01; ? //定時器0,工作方式1
TH0 = 0x3c;
TL0 = 0xb0; //50ms中斷壹次
EA = 1;
ET0 = 1;
TR0 = 1;
}
void main(void)
{
InitTimer0();
while(1)
if(time==20) //中斷20次,1s
{
time=0;
LED=!LED; P1.0上的LED1s亮滅壹次
}
}
void Timer0Interrupt(void) interrupt 1
{
TH0 = 0x3c;
TL0 = 0xb0;
time++;
}