#include <reg51.h>
unsigned char timer;
//系统时钟: 12Mhz
//高电平点亮.
void delay(unsigned int delaytime)
{ timer = delaytime;
while(timer!=0)
{}
}
void main()
{
unsigned light=1;
TMOD = 0X11; //timer1 mode 1,timer0 mode 1
PCON = 0x00; //SMOD = 0
TH0=(0xffff-10000)/256;
TL0=(0xffff-10000)%256;
TR0=1;
ET0=1;
EA =1;
while(1)
{ P1=light;
delay(1000) ;//延时1秒.
light <<=1;
if(light ==0)
light =1;
}
}
void T0_service(void) interrupt 1 using 1
{ //1毫秒中断1次.
TH0=(0xffff-1000)/256;
TL0=(0xffff-1000)%256;
if(timer>0)timer--;
}
温馨提示:内容为网友见解,仅供参考