本帖最后由 雷雷 于 2014-1-19 20:28 编辑
大侠帮我看一下,为什么我这个一直在加,我只想按一下键再加
#include<reg51.h>
unsigned int shu[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned int huan[8];
unsigned int a,b,c,d,number,k,g,count;
void delay(unsigned char i) //*************一毫秒延时****************//
{
unsigned int j;
for(i;i > 0;i--)
for(j = 0;j < 200;j++);
}
bit key() //*************按键扫描*********************//
{
static bit wei = 1;
if((P2^7 == 0)&&(wei != 0))
{
wei = 0;
return 1;
}
else
wei = P2^7;
return 0;
}
int main() //************主程序***************//
{
while(1)
{
if(g == 0x00)
{
while(1)
{
if(key())
{number++;
}
for(k = 0;k < 8;k++)
{
huan[0] = shu[number/1000];
huan[1] = shu[number%1000/100];
huan[2] = shu[number%100/10];
huan[3] = shu[number%10];
huan[4] = shu[a];
huan[5] = shu;
huan[6] = shu[c];
huan[7] = shu[d];
P1 = 0xff;
P0 = huan[k];
P1 = ~(1 << k);
delay(1);
}
}
}
}
} |