求各位前辈指导 51单片机时钟问题

[复制链接]
 楼主| agz1989 发表于 2013-6-6 21:59 | 显示全部楼层 |阅读模式
#include<AT89X51.h>
#define uchar unsigned char
uchar code table[]={0xc0,0xf9,0xc4,0xb0,0x99
,0x92,0x82,0xf8,0x80,0x90}; //共阳数码管
uchar time,num,hour,min,sec;
void delay(uchar x)
{
TMOD=0x01;
TR0=1;
while(x--)
{
  TH0=0x1c;
  TL0=0x18;
  while(!TF);
  TF0=0;
  time++;
}
TR0=0;
}
void write(uchar num,chose)
{
uchar i;

for(i=0;i<2;i++)
    {
         P0=0xff;
     P2=~chose;//位选

     if(i==0)
       {
        P0=table[num%10];//段选
       }
     else
         P0=table[num/10];//段选
     
         chose=chose<<1;
     delay(5);
    }
}
void display()
{
P0=0xff;
P2=0xdb;
P0=0xbf;
delay(5);
}//-隔开时,分,秒显示
void time_add()
{
if(time==1000)
   {
    sec++;
        if(sec==60)
          {
           sec=0;
           min++;
           if(min==60)
             {
                    min=0;
                    hour++;
                    if(hour==24)
                      {
                              hour=0;
                     }
                    }
      }
   }   
}
void main()
{
hour=23;
min=37;
sec=50;
while(1)
{
  write(sec,0x01);
  write(min,0x08);
  write(hour,0x40);
  display();
  time_add();
}
}

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
xyz549040622 发表于 2013-6-6 22:10 | 显示全部楼层
什么情况也不说,让人家看什么,建议罗列出你的疑问
NE5532 发表于 2013-6-6 22:32 | 显示全部楼层
是啊,楼主介绍一下遇到啥问题了呢。
 楼主| agz1989 发表于 2013-6-7 09:38 | 显示全部楼层
显示乱码,乱码变化
NE5532 发表于 2013-6-7 11:08 | 显示全部楼层
先调试一位的显示,再调动态显示固定数据,再调时钟,不要胡子眉毛一把抓。推荐本版精华帖“程序调试黑宝书”
您需要登录后才可以回帖 登录 | 注册

本版积分规则

22

主题

45

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部