点击查看代码
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit LED=P0^0;
uchar T_Count=0;
//主程序
void main()
{
TMOD=0x00;
//定时器0工作方式0
TH0= (8192-5000)/32;//5ms定时
TL0= (8192-5000) %32;
IE=0x82;//允许T0中断
TR0=1;
while (1);
}
//T0中断函数
voidLED_FLash () interrupt 1
{
TH0= (8192-5000)/32;//恢复初值
TL0= (8192-5000) %32;
if (++T_Count==100)//0.5s开关一次LED
{
LED=~LED;
T_Count=0;
}
}