| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 519 人关注过本帖
标题:这是电子钟程序,编译时没错,但6位码管没显示,我找不出程序的错,求大神看 ...
只看楼主 加入收藏
xuewuya
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-5-2
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
这是电子钟程序,编译时没错,但6位码管没显示,我找不出程序的错,求大神看一下
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
sbit beep=P2^3;
uchar h2,h1,f2,f1,s2,s1;
uchar pp,temp,key,ok;
uchar a0,a1,a2,a3,a4,a5,m,k,t;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
                        0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delayms(uint x)
{
  uint i,j;
  for(i=x;i>0;i--)
    for(j=50;j>0;j--);
}

 void delay(unsigned char z)     //延时
{
  uchar g,l,f;
  for(g=z;f>0;f--)
    for(l=125;l>0;l--);
 }
void display(uchar h2,uchar h1,uchar f2,uchar f1,uchar s2,uchar s1)
{
  dula=0;
  P0=table[h2];         //显示小时十位段码
  dula=1;

    wela=0;
  P0=0xfe;             //显示小时十位
  wela=1;
  delayms(10);

  dula=0;
  P0=table[h1]|0x80;    //显示小时个位段码及小数点
  dula=1;

  wela=0;
  P0=0xfd;                 //显示小时个位
  wela=1;
  delayms(10);

   dula=0;
   P0=table[f2];       //显示分钟十位段码
  dula=1;

    wela=0;
  P0=0xfb;                //显示分钟十位
  wela=1;
  delayms(10);

  dula=0;
   P0=table[f1]|0x80;     //显示分钟十位段码及小数点
  dula=1;

    wela=0;
  P0=0xf7;                 //显示分钟十位
  wela=1;
  delayms(10);

   dula=0;
   P0=table[s2];          //显示秒钟十位段码
  dula=1;

   wela=0;
  P0=0xef;                  //显示秒钟十位
  wela=1;
  delayms(10);

    dula=0;
   P0=table[s1];           //显秒钟个位段码
  dula=1;

   wela=0;
  P0=0xdf;                    //显示秒钟个位
  wela=1;
  delayms(10);
}

void keyscan0()               //键盘扫描
{
    dula=0;                    //关段选
  wela=0;                     //关位选
  while(1)
  {                             
    P3=0xfe;                    //键盘P3口赋值
    temp=P3;                  //把P3口值赋给变量temp
    temp=temp&0xf0;              //屏蔽temp低四位
    if(temp!=0xf0)                //读temp值
    {
      delay(10);                //防抖
      if(temp!=0xf0)            //再次读temp值
      {                             
        temp=P3;               //P3口值赋给temp
        switch(temp)             //读P3口值
        {
          case 0xee:
               ok=0;
               break;

          case 0xde:
               ok=1;
               break;
         }
         while(temp!=0xf0)          //等待按键释放
         {
           temp=P3;
           temp=temp&0xf0;
           beep=0;                  //蜂鸣器开
         }
         beep=1;                  //蜂鸣器关
         P1=0xfe;                   //指示灯亮
      }
    }
  }
  }
void keyscan()                   //键盘扫描
{
   dula=0;
   wela=0;
   while(1)
   {
    P3=0xfd;
    temp=P3;
    temp=temp&0xf0;
    if(temp!=0xf0)
    {
      delay(10);
      if(temp!=0xf0)
      {
        temp=P3;
        switch(temp)
        {
          case 0xed:
               key=4;
               break;

          case 0xdd:
               key=5;
               break;

          case 0xbd:
               key=6;
               break;

          case 0x7d:
               key=7;
               break;
         }
         while(temp!=0xf0)
         {
           temp=P3;
           temp=temp&0xf0;
           beep=0;
         }
         beep=1;
      }
      }
    P3=0xfb;
    temp=P3;
    temp=temp&0xf0;
    if(temp!=0xf0)
    {
      delay(10);
      if(temp!=0xf0)
      {
        temp=P3;
        switch(temp)
        {
          case 0xeb:
               key=8;
               break;

          case 0xdb:
               key=9;
               break;

          case 0xbb:
               key=10;
               break;

          case 0x7b:
               key=11;
               break;
         }
         while(temp!=0xf0)
         {
           temp=P3;
           temp=temp&0xf0;
           beep=0;
         }
         beep=1;
      }
      }
    P3=0xf7;
    temp=P3;
    temp=temp&0xf0;
    if(temp!=0xf0)
    {
      delay(10);
      if(temp!=0xf0)
      {
        temp=P3;
        switch(temp)
        {
          case 0xe7:
               key=12;
               break;

          case 0xd7:
               key=13;
               break;

          case 0xb7:
               key=14;
               break;

          case 0x77:
               key=15;
               break;
         }
         while(temp!=0xf0)
         {
           temp=P3;
           temp=temp&0xf0;
           beep=0;
         }
         beep=1;
      }
    }
  }
}


void main()
{
   TMOD=0x01;
   TH0=(65536-46080)/256;  //定时器装初值
   TL0=(65536-46080)%256;
   EA=1;
   ET0=1;
   TR0=1;
   while(1){
    keyscan();          //调用键盘扫描函数
     if(ok==0){
       TR0=0;
       keyscan();      //调用键盘扫描函数
       switch(key){
      case 2:
          m+=1;             //
          if(m==60)
          m=0;
         break;
      case 3:
         m-=1;
         if(m==0)
         m=60;
        break;
      case 4:
        k+=1;
        if(k==60)
         k=0;
        break;
      case 5:
        k-=1;
        if(k==0)
        k=60;
        break;
      case 6:
        t+=1;
        if(t==60)
         t=0;
        break;
      case 7:
        t-=1;
        if(t==0)
        t=60;
        break;
        }
            a5=m%10;
     a4=m/10;
     a3=k%10;
     a2=k/10;
     a1=t%10;
     a0=t/10;
      display(a0,a1,a2,a3,a4,a5);
      }
      else
      {
          TR0=1;
          if(pp==20)
     {
       pp=0;
       m++;
       if(m==60)
       {
         m=0;
         k++;
         if(k==60)
         {
          k=0;
          t++;
          if(t==24)
          {
          t=0;
                }
         }
       }
     }
           a5=m%10;
     a4=m/10;
     a3=k%10;
     a2=k/10;
     a1=t%10;
     a0=t/10;
      display(a0,a1,a2,a3,a4,a5);
   
     }
 
}
}

void time0() interrupt  1
{
  TH0=(65536-46080)/256;
  TL0=(65536-46080)%256;
  pp++;
        if(pp==20)
     {
       pp=0;
       m++;
       if(m==60)
       {
         m=0;
         k++;
         if(k==60)
         {
          k=0;
          t++;
          if(t==24)
          {
          t=0;
                }
         }
       }
      }
}
搜索更多相关主题的帖子: include 
2013-05-02 10:55
pauljames
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:千里冰封
威 望:9
帖 子:1555
专家分:10000
注 册:2011-5-8
收藏
得分:20 
没显示不一定就是软件的问题,你硬件有无问题?先用一个简单的代码去单独点亮。

经常不在线不能及时回复短消息,如有c/单片机/运动控制/数据采集等方面的项目难题可加qq1921826084。
2013-05-06 07:32
快速回复:这是电子钟程序,编译时没错,但6位码管没显示,我找不出程序的错,求 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020069 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved