2020-04-07

数码管显示时间

7段八位共阴数码管
89C51
P0口接上拉电阻接到段选位,
P2口控制位选

/*7seg_pex8_CC_smg_Clock01*/
/*2020.4.7*/

#include<reg52.h>
#define uchar unsigned char;
#define uint unsigned int;
 
uchar tcount;
uchar hr;
uchar minite;
uchar sec;
uchar code seg1=[0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};

void delay_ms(unsigned int n)
{
     unsigned int i;
     unsigned int j;
    for(i=0;i<n;i++)
        for(j=0;j<123;j++);
}
void SMG_Clock_display()
{
     P0=seg1[sec % 10];
   P2=0x01;
   delay_ms(2);
   P2=0x00;
   P0=seg1[sec / 10];
   P2=0x02;
   delay_ms(2);
   P2=0x00;
     P0=0x40;
   P2=0x04;
   delay_ms(2);
   P2=0x00;
     P0=seg1[minite % 10];
   P2=0x08;
   delay_ms(2);
   P2=0x00;
     P0=seg1[minite / 10];
   P2=0x10;
   delay_ms(2);
   P2=0x00;
     P0=0x20;
   P2=0x20;
   delay_ms(2);
   P2=0x00;
     P0=seg1[hr % 10];
   P2=0x40;
   delay_ms(2);
   P2=0x00;
     P0=seg1[hr / 10];
   P2=0x80;
   delay_ms(2);
   P2=0x00;
}
 
/*       定时器初始化            */
void Timer0Init()                                             
{
    TMOD=0x01;            
    TH0=(65536-5000)/ 256;                        
    TL0=(65536-5000)%256;
      EA=1;                
      ET0=1;            
      TR0=1;        
}
void timer0() interrupt 1
{
    TH0=(65536-5000)/ 256;    
   TL0=(65536-5000)% 256;
    tcount++; 
    if(tcount== 200)                
    {
        tcount=0;
        sec++;
        if(sec == 60)
        {
            sec=0;
            minite++;
            if(minite == 60)
            {
            minite=0;
            hr++;
            if(hr == 24)
            hr=0;
            }
        }
    }
}
void main()
{
    Timer0Init();
    SMG_Clock_display();
    while(1);
}

没有用的!不知道问题在哪里,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值