//假设晶振12MHZ,P1控制LED低电平亮
#include "reg51.h"
unsigned int YSJS=0;
unsigned int P1BUF=0X03;
void main(void)
{
TMOD |= 0X10; //定时器1工作于方式1,16位定时器
TH1 = 0XFF; //定时器1定时时间=500uS
TL1 = 0X06;
ET1 = 1; //使能定时器1中断
EA =1; //开总中断
P1 = P1BUF;
while(1)
{
}
}
void TIMER1(void) interrupt 3 //定时器1中断函数使用默认寄存器组
{
TH1 = 0XFF; //定时器1定时时间=500us
TL1 = 0X06;
YSJS++;
if(YSJS==2000) //500uS*2000=1000000us=1s
{
P1 = P1BUF;
YSJS = 0
P1BUF = P1BUF<<2;
IF(P1BUF==0)P1BUF=0X03;
}
}