C51 1秒定时器
#include <reg52.h>
sbit LED = P1^1;
unsigned char count;
void main()
{
TMOD = 0x01; //工作方式1 ,T/C 0 是一个16位定时器 / 计数器
TH0 = 0x3c;
TL0 = 0xb0;
EA = 1;
ET0 = 1;
TR0 = 1;
LED = 0;
while(1)
{
}
}
void T1_timer() interrupt 1
{
TH0 = 0x3c;
TL0 = 0xb0;
count++;
if(count == 4)
LED = 0;
else if(count == 20)
{
LED = 1;
count = 0;
}
}