1、#include <reg52.h>
2、#define uchar unsigned char
3、#define uint unsigned int
4、sbit LED = P0^0;uchar T_Count = 0;void main(){TMOD = 0x01;TH0 = (65535-50000)/256;TL0 = (65535-50000)%256;IE = 0x82;TR0 = 1;while(1);}
5、void LED_Flash() interrupt 1{TH0 = (65535-50000)/256;TL0 = (65535-50000)%256;if(++T_Count == 20){LED = !LED;T_Count = 0;}}
6、这个程序是1秒钟LED灯会亮与灭显示。
1单片机,拥有两个定时器,用来中断计数,分别是T0和T1。而52单片机和51单片机的定时器是一样的,只是52比51多了一个定时器/计数器T2,它们的设置都大同小异。