但是实际运行时发现有问题
#include"reg51.h"
#define uchar unsigned char
#define uint unsigned int
sbit led1=P1^0;
sbit led2=P1^1;
sbit led3=P1^2;
sbit led4=P1^3;
sbit led5=P1^4;
sbit led6=P1^5;
sbit led7=P1^6;
sbit led8=P1^7;
uchar num1;
void main()
{
TMOD=0x01;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;
ET0=1;
TR0=1;
led1=1;
led2=1;
led3=1;
led4=1;
led5=1;
led6=1;
led7=1;
led8=1;
while(1)
{
if((num1==4)||(num1==8)||(num1==12)||(num1==16)||(num1==20))
{
led1=~led1;
}
if((num1==24)||(num1==28)||(num1==32)||(num1==36)||(num1==40))
{ led1=1;
led2=~led2;
}
if((num1==44)||(num1==48)||(num1==52)||(num1==56)||(num1==60))
{ led2=1;
led3=~led3;
}
if((num1==64)||(num1==68)||(num1==72)||(num1==76)||(num1==80))
{ led3=1;
led4=~led4;
}
if((num1==84)||(num1==88)||(num1==92)||(num1==96)||(num1==100))
{ led4=1;
led5=~led5;
}
if((num1==104)||(num1==108)||(num1==112)||(num1==116)||(num1==120))
{ led5=1;
led6=~led6;
}
if((num1==124)||(num1==128)||(num1==132)||(num1==136)||(num1==140))
{ led6=1;
led7=~led7;
}
if((num1==144)||(num1==148)||(num1==152)||(num1==156))
{ led7=1;
led8=~led8;
}
if(num1==160)
{
led8=~led8;
led8=1;
num1=0;
}
}
}
void T0_time()interrupt 1
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
num1++;
}
|