功能上電后顯示0000,然后每個1秒數碼管值加1,加到9999時從0000重新開始。
#include <REGX52.H>
#define uchar unsigned char
#define uint unsigned int
uchar code duanma[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//段碼
uchar code weima[]={0xef,0xeb,0xe7,0xe3};//位碼
//0xff;0xfb;0xf7;0xf3;0xef;0xeb;0xe7;0xe3
uchar dispbuf[];
uint count;
void delayms(uint xms)//延時函數
{
uchar i, j;
while(xms--)
{
i = 2;j = 199;
do{while (--j);}
while (--i);
}
}
void duan(void)
{
dispbuf[3]=count/1000;
dispbuf[2]=count/100%10;
dispbuf[1]=count/10%10;
dispbuf[0]=count%10;
}
void wei(void)
{
uchar x;
for(x=0;x<4;x++)
{
P0=duanma[dispbuf[x]];
P2=weima[x];
delayms(1);
}
}
void main()
{
uint k;
while(1)
{
if(++k==220)
{
k=0;
if(++count==10000)count=0;
}
duan();
wei();
}
}
是哪里有問題啊? |