程序来自网络,略微修改了一下。
#include
sbit LED_0 = P0^0;
sbit LED_1 = P0^7;
unsigned Count = 0;
unsigned i = 0;
void Time_Init();
void main(void)
{
Time_Init();
LED_0 = 0;
LED_1 = 1;
while(1);
}
void Time_Init(void)
{
TMOD = 0x02; //¶¨Ê±Æ÷0, ·½Ê½2
TH0 = 0x9C;
TL0 = 0x9C;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void INT_Time0() interrupt 1 using 1
{
Count++;
i++;
if (Count == 100) {Count = 0;}
if (1 + i == 99) {i = 0;}
if (Count > 1 + i)
{
LED_0 = 1;
LED_1 = 0;
}
else
{
LED_0 = 0;
LED_1 = 1;
}
}