每按键一次,变换一次数字从 0~8。程序检测无错,谁能帮我看看这程序能否运行?还能不能再进行改进。
#include <reg52.h>#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
sbit key1=P3^4;
uchar code table[]=
{
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f
};
void delayms(uint xms)
{
uint a,b;
for (a=xms;a>0;a--)
for (b=110;b>0;b--);
}
uchar sum=0,num;
void main()
{
while (1)
{
P0=0xaa;
wela=1;
wela=0;
P0=table[sum];
dula=1;
dula=0;
delayms(500);
}
}
void keycan()
{
if (key1==1)
delayms(10);
if (key1==1)
{
sum++;
if (sum==8)
sum=0;
while (!key1);
}
}