求一个基于AT89C51单片机的0~59秒计时器C语言程序

2019-07-15 16:35发布

8位数码管的     STC89C52RC       我弄得不管怎么整就是不好使。。。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
11条回答
求大神指教
2019-07-16 07:24
#include<reg52.h>
#define  uchar unsigned char
#define  uint  unsigned int
uchar  num, num1,num2,shi,ge,count;
uint a=0xfe;
sbit  wela=P2^7;
sbit  dula=P2^6;
uchar  code table[]=
{0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,
};
void delay(uint z)
{        uint i,j;
        for(i=z;i>0;i--)
                for(j=110;j>0;j--);
}
void display(uchar shi,uchar ge)
{
dula=1;
P0=table[shi];
dula=0;
wela=0xfe;
wela=1;
P0=0xfe;
wela=0;
delay(5);

dula=1;
P0=table[ge];
dula=0;
wela=0xff;
wela=1;
P0=0xfd;
wela=1;
delay(5);
}
void display(uchar shi,uchar ge);
void delay(uint z);
void main()
{   TMOD=0x11;
    TH0=(65535-45872)/256;
        TL0=(65535-45872)%256;
        TH1=(65535-45872)/256;
        TL1=(65535-45872)%256;
        EA=1;
        ET0=1;
        ET1=1;
        TR1=1;
    TR0=1;
        while(1)
        {
        display(shi,ge);
        }
       
}
void T0_time()  interrupt 1
{
    TH0=(65535-45872)/256;
        TL0=(65535-45872)%256;
        num1++;
    if(num1==20)

            {num1=0;
             num++;
         if (num==60)
                 num=0;
                  shi=num/10;
                  ge=num%10; }
               
}
void T1_time()  interrupt 3
{ TH1=(65535-45872)/256;
        TL1=(65535-45872)%256;
        num2++;
        if(num2==20)
{
         count++;
         num2=0;
         if(count<8) a=a>>1;
         else a=a<<1;
         if(count==15)
         {
          count=0;
          a=0xfe;
          }
         P1=a;
        }
}
注意十位,个位的显示。

一周热门 更多>