#include <reg52.h>
typedef unsigned char u8;
typedef unsigned int u16;
sbit led = P1^0;
u8 timer;
void main (void)
{
TMOD = 0x01;//设置TMOD,使得T0工作在16位定时。
TH0 = (65535-50000) / 256;
TL0 = (65535-50000) % 256;
EA = 1; //开放总中断
ET0 = 1;//开放定时器0的溢出中断
TR0 = 1;//开始定时
while(1) //作用就是让程序结束 否则程序一直在这运行;
{
;
}
}
//实现方式一
void timer0_service(void) interrupt 1
{
TH0 = (65535-50000) / 256;
TL0 = (65535-50000) % 256;
//50ms已经设置好了
timer ++;
if (timer == 20)
{
timer = 0;
led = ~led;
}
}