#include <REGX52.H>
#define uchar unsigned char;
#define uint unsigned int;
uchar step = 0, Timer = 0;
uint i = 0, j = 0;
void main()
{
TMOD = 0x01;
TH0 = -9;
ET0 = 1;
EA = 1;
TR0 = 1;
step = 0;
i = 0;
j = 0;
while(1)
{
P0 = 0x00;
while (step == 0)
{
if (Timer == 100)
{
P0 = 0x01 << i;
i = i + 1;
if (i == 8)
{
i = 0;
}
Timer = 0;
j++;
break;
}
}
while (step == 1)
{
if (Timer == 100)
{
P0 = 0x80 | (0x01 << i);
i = i + 1;
if (i == 6)
{
j = 7;
}
i = i & 7;
Timer = 0;
break;
}
}
while (step == 2)
{
if (Timer == 100)
{
P0 = 0xC0 | (0x01 << i);
i = i + 1;
if (i == 5)
{
j = 7;
}
Timer = 0;
break;
}
}
while (step == 3)
{
if (Timer == 100)
{
P0 = 0xE0 | (0x01 << i);
i = i + 1;
if (i == 4)
{
j = 7;
}
Timer = 0;
break;
}
}
while (step == 4)
{
if (Timer == 100)
{
P0 = 0xF0 | (0x01 << i);
i = i + 1;
if (i == 3)
{
j = 7;
}
Timer = 0;
break;
}
}
while (step == 5)
{
if (Timer == 100)
{
P0 = 0xF8 | (0x01 << i);
i = i + 1;
if (i == 2)
{
j = 7;
}
Timer = 0;
break;
}
}
while (step == 6)
{
if (Timer == 100)
{
P0 = 0xFC | (0x01 << i);
i = i + 1;
if (i == 1)
{
j = 7;
}
Timer = 0;
break;
}
}
while (step == 7)
{
if (Timer == 100)
{
P0 = 0xFE;
Timer = 0;
j = 7;
break;
}
}
while (step == 8)
{
if (Timer == 100)
{
P0 = 0xFF;
Timer = 0;
j = 7;
break;
}
}
while (step == 9)
{
if (Timer == 100)
{
P0 = ~P0;
Timer = 0;
}
j = 7;
i = 0;
break;
}
}
if (j == 7)
{
step++;
j = 0;
if (step == 10)
{
step = 0;
}
}
}
void IntT0() interrupt 1
{
TH0 = -9;
Timer++;
}
想做一个小鸟归巢的花样流水灯程序,但不知道哪里有问题导致protues仿真效果不正确...
|