标题:AT89C51电子时钟问题
只看楼主
a462410594
Rank: 2
等 级:论坛游民
帖 子:75
专家分:64
注 册:2011-11-17
结帖率:90%
已结贴  问题点数:20 回复次数:3 
AT89C51电子时钟问题
实现电子时钟的功能,并可以通过按键调时间
#include<reg51.h>
unsigned char i=20,led0=0,led1=0,led2=0,led3=0,led4=0,led5=0,sec=0,min=0,min1=0,min2=0,hour1=0,hour2,hour=0;unsigned char display[10]={0x3f,0x6,0x5b,0x4f,0x66,0x6d,0x7d,0x7,0x7f,0x6f};                                               
void delay(unsigned char x)         //延时函数程序
{      
     unsigned char k;   
    while(x--)               
    for(k=0;k<125;k++)
     {}
}
void button()
{  
         switch(P0)        //BUTTON            
     {        
        case 0xfe:P2=0xfc;    P1=led2;  delay(1);          //led2 min1                 
          min1++;                 
         if(min1==10)                  
         {                        
                  min1=0;         
          }         
              led2=display[min1];     break;
                   case 0xfd: P2=0xfb;    P1=led3;  delay(1);         //led3 min2                 
           min2++;                    
   if(min2==10)                    
       {                          
          min2=0;                           
           }                  
      led3=display[min2];     break;      
                  case 0xfb: P2=0xf9;    P1=led4;  delay(1);           //led4 hour1                       
      hour1++;                    
   if(hour1==2)                    
       {                        
         hour1=0;                     
          }               
         led4=display[hour1];  break;              
                case 0xf7:         P2=0xf8;    P1=led5;  delay(1);         //led5 hour2           
                  hour2++;                  
     if(hour2==10)                       
    {                        
         hour2=0;                  
                   }                 
       led5=display[hour2];                break;      
  } }               
void main( )   //主函数
{        
TMOD=0x01;  
                        TH0=0x3c;      
       TL0=0xb0;         
    EA=1;               
              ET0=1;     
                               TR0=1;      
                      while(1) //74LS138选址   
            {         
           button();                        
           P2=0xff;    P1=led0;  delay(1);                 
             P2=0xfe;    P1=led1;  delay(1);
               P2=0xfc;    P1=led2;  delay(1);            
             P2=0xfb;    P1=led3;  delay(1);
               P2=0xf9;    P1=led4;  delay(1);        
             P2=0xf8;    P1=led5;  delay(1);              
               }      
  }        

void  T0_int(void)  interrupt 1  //中断程序{      
TH0=0x3c;                        
   TL0=0xb0;         
i--;                                 
  if(i<=0)              
  {                       
sec++;                  
      if(sec==60)                 
               {                  
                sec=0;         
                        min++;         
                      }                  
     led0=display[sec%10];         
               led1=display[sec/10];      
                 if(min==60)              
             {                        
    min=0;                       
      hour++;                    
       }                     
  led2=display[min%10];         
              led3=display[min/10];         
               if(hour==24)                    
       {                          
   hour=0;                     
      }                    
    led4=display[hour%10];        
                led5=display[hour/10];      
             i=20;                           
     }}
可以正常的运行,但就是按键不了,求解答
搜索更多相关主题的帖子: 电子 时钟 display include button 
2012-12-06 17:22
于祥
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:5
帖 子:1047
专家分:4132
注 册:2011-4-24
得分:20 
这个我不太相信仿真

最基础的往往是你最容易忽略的!
2012-12-07 16:27
lvx6509
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-12-24
得分:0 
我是新手,我正想学习kel c编程,请多多指教!
2012-12-24 16:52
rifvpww
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-2-25
得分:0 
去掉按键中的三个电阻试试
2013-02-25 14:30



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-389915-1-1.html




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

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