#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar temp,aa,numdu,s;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void display(uchar ,uchar ,uchar,uchar);
void main()
{
numdu=0;
P2=0x0f;
s=0;
aa=0;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
display ( numdu,0,0, 0);
if(aa==20)
{
aa=0;
s=s+1;
if(s==20)
{ s=0;
numdu++;
display ( numdu,0,0, 0);
}
}
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa++;
}
void display(uchar numdu,uchar m2,uchar h1,uchar h2)
{
P2=0xef;
P0=table[numdu];
P2=0xdf;
P0=table[m2];
P2=0xbf;
P0=table[h1];
P2=0x7f;
P0=table[h2];
}
我的目的是四个数码管前面三个管显示零,最后一个数码管从0到9显示,但我调用的子程序display中的numdu不能累加啊,数码管就显示了四个零 |