#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++;
}
温馨提示:内容为网友见解,仅供参考