這個程序流水燈循環的時候,不按照循環走,按下按鍵就全部亮了,我加過延時函數了,也是一次全部亮。求助各位學霸。
單片機源程序如下:
#include<reg52.h>
#define u8 unsigned char
sbit S7=P3^0;
sbit S6=P3^1;
sbit S5=P3^2;
sbit S4=P3^3;
u8 code LedChar[18] =
{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x80,0xc6,0xc0,0x86,0x8e,
0xbf,0x7f};
void LedXun_huan();
void InitSystem();
void Chosse573(u8 i);
void InitSystem()
{
Chosse573(5);
P0=0X00;
}
void Delay(u8 t)
{
while(t)
{
t--;
}
}
void Chosse573(u8 i)
{
switch(i)
{
case 4: P2=(P2&0X1F)|0X80;break;
case 5: P2=(P2&0X1F)|0XA0;break;
case 6: P2=(P2&0X1F)|0XC0;break;
case 7: P2=(P2&0X1F)|0XE0;break;
}
}
void KeyDriver()
{
if(S7==0)
{
Delay(500);
if(S7==0)
LedXun_huan();
}
}
void LedXun_huan()
{
u8 i;
Chosse573(4);
for(i=0;i<8;i++)
{
P0=~(0x01<<i);
}
}
void main()
{
InitSystem();
while(1)
{
KeyDriver();
}
}
|