基于51单片机数码管万年历按键可调(Proteus仿真设计)

Posted perseverance52

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基于51单片机数码管万年历按键可调(Proteus仿真设计)相关的知识,希望对你有一定的参考价值。

基于51单片机数码管万年历按键可调(Proteus仿真设计)


  • AT89C5274S37374L138
  • Proteus仿真

实例代码

#include<reg51.h>
#include<absacc.h>
#define uchar unsigned char 
#define uint  unsigned int
//#define ture  1
//#define fault 0

sbit SET=P1^7;

void delay(uchar k);
uchar monthday(uchar a,uchar b);
void display();

uchar code dayofmonth[]={31,28,31,30,31,30,31,31,30,31,30,31};
uchar code scan[]={0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,
                   0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,
				   0xf8,0xf9,0xfa,0xfb,0xfc,0xfd};      //扫描的译码信号
uchar i;
uchar code table[]={0xBF,0x86,0xDB,0xCF,0xE6,0xED,0xFD,0x87,0xFF,0xEF,0xC0}; //段码表
uchar  buffer[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
uchar  shuju=0;
uchar  state=0;
uchar  qxiang;

typedef  struct  
         {
		 uchar year[2];
		 uchar month;
		 uchar day;
		 uchar week;
		 }date;
typedef  struct  
        {
	    uchar hour;
		uchar minute;
		uchar second;
		}time;
uchar  count=0;
date today={{18,20},11,14,3};			//设置日期初值
time now={14,30,00};					//设置时间初值
void main()
{
TMOD=0x01;
TL0=(65536-1000)%256;
TH0=(65536-1000)/256;
IE=0x82;	    //EA=1;ET0=1总中断允许和定时器中断允许
TR0=1;	        //定时器启动计数
display();
while(1)
    {
	 P1=0xff;
     shuju=P1&0xff;
	 qxiang=shuju&0x80;
		switch(qxiang)
	    {
		 case(0x80):switch(shuju)
			      {
				 case(0xfe) :			   //秒调整
		            {
					 EA=1;
					 EX0=1;           //总中断允许,外中断0允许
					 IT0=1;           //中断0为负跳变触发
			         }break;
	           	 case(0xfd)	:			 //分调整
		            {
					 EA=1;
					 EX0=1;                  
					 IT0=1;                  
			         }break;
	           	 case(0xfb) :			//时调整
		            {
					 EA=1;
					 EX0=1;
					 IT0=1;					
			         }break;
                 case(0xf7) :			 //星期调整
		            {
					 EA=1;
					 EX0=1;
					 IT0=1;
			         }break;
                 case(0xef) :			 //日调整
	 	            {
					 EA=1;
					 EX0=1;
					 IT0=1;
			         }break;
                 case(0xdf):			 //月调整
	 	            {
					 EA=1;
					 EX0=1;
					 IT0=1;
			         }break;
                 case(0xbf):			 //年调整
		            {
					 EA=1;
					 EX0=1;
					 IT0=1;
			         }break;
			     default:				 //时钟正常计时
	                {
					EA=1;
					TR0=1;
					EX0=0;
					}break;
				}break;
		 case(0x00) :switch(shuju)
					     {
			   case(0x7e):
	                {
					 EA=1;
					 EX0=1;
					 IT0=1;
					}break;
	           case(0x7d):
	                {
					 EA=1;
					 EX0=1;
					 IT0=1;
					}break;
	           case(0x7b):
	                {
					 EA=1;
					 EX0=1;
					 IT0=1;
					}break;
	           case(0x77):
	                {
				   	 EA=1;
					 EX0=1;
					 IT0=1;
					}break;
	           case(0x6f):
	                {
					 EA=1;
					 EX0=1;
					 IT0=1;
					
					}break;
	           case(0x5f):
	                {
					 EA=1;
					 EX0=1;
					 IT0=1;
					}break;
	           case(0x3f):
	                {
					 EA=1;
					 EX0=1;
					 IT0=1;
					}break;
	           default:					
	                {
					EA=1;
					TR0=1;
					EX0=0;
					}break;
		    	}break;       
		}
	}
}

void int0()  interrupt 0 using 0   //中断服务程序,调节时间
{
  uchar result,z; 
  result=shuju;
       	switch(qxiang)
	    {
		 case(0x80):   switch(result)
					   {
                       	case(0xfe) :					  //秒调整	+
	                         {
	                           now.second++;
	                           if(now.second>=60)
	                              {
		                            now.second=0;
		                           }
	                           display();
	                          }break;
                         case(0xfd) :		             //分调整  +
	                         {
	                            now.minute++;
	                            if(now.minute>=60)
	                             {
		                           now.minute=0;
		                          }
	                             display();
	                         }break;
                            case(0xfb) :		   //时调整	+
	                          {
	                             now.hour++;
	                             if(now.hour>=24)
	                                {
		                              now.hour=0;
	                             	}
	                                display();
	                          }break;
                             case(0xf7)	:		  //星期调整 +
	                              {		   
	                                 today.week++;
	                                  if(today.week>=8)
	                                      {
		                                    today.week=1;
		                                   }
	                                  display();
	                              }break;
	                          case(0xef) :			//日调整	 +
	                              {
	                                 today.day++;
	                                 z = monthday(today.year[1],today.year[0]);
	                                 if((z==1)&&(today.month==2))
									    {
										  if(today.day>=30)
			                                 today.day=1;
										}
		                              else if (today.day>dayofmonth[today.month-1])
		                                            today.day=1;
	                                  display();
	                                }break;	  
   		                          case(0xdf) :			 //月调整	+
		
		                            {
	                                	today.month++;
	           	                        if(today.month>=13)
		                                   {
			                                 today.month=1;
			                                }
		                                display();
		                               } break;
		                       case(0xbf) :			//年调整 +
		                             {
	                                   today.year[0]=today.year[0]+1;
		                               if(today.year[0]>=100)
		                                   {
			                                 today.year[0]=0;
			                                 today.year[1]=today.year[1]+1;
			                                 if(today.year[1]>=100)
			                                    {
				                                   today.year[1]=0;
				                                 }
			                                 }
		                                 display();
	 	                              }break;
		                       default:				 //时钟正常计时
	                                 {
									 EA=1;
					                 TR0=1;
					                 EX0=0;
									 }break;
					         }break; 
	    case(0x00): switch(result)
			{
			  case(0x7e):				           //秒调整-
	                  {
	   	               if(now.second>0)
		                  now.second=now.second-1;
		               else now.second=59;
		                    display();
	                  }break;
              case(0x7d):						    //分调整-
	                  {
	   	              if(now.minute>0)
		                 now.minute=now.minute-1;
		              else now.minute=59;
		                   display();
	                  }break;
              case(0x7b) :					       //  时调整-
	                  {
	                  if(now.hour>0)
		                 now.hour=now.hour-1;
		              else now.hour=23;
		                   display();
	                  }break;
	          case(0x77) :					  //	 周调整-
	                  {
	                  if(today.week>1)
		                 today.week=today.week-1;
		              else today.week=7;
		                   display();
	                  }break;
	          case(0x6f):						 //	   日调整-
	                  {
	                  z = monthday(today.year[1],today.year[0]);
	   	              if((z==1)&&(today.month==2))
		                {
		                if(today.day>1)
		                   today.day=today.day-1;
		        	    else today.day=29;
		                }
		               else {
			                if(today.day>1)
			                   today.day=today.day-1;
			                else today.day=dayofmonth[today.month-1];
		                    }
		               display();
	                   }break;
	           case(0x5f):						//	月调整-
	                   {
	   	               if(today.month>1)
		                  today.month=today.month-1;
		               else today.month=12;
		               display();
	                   }break;
	           case(0x3f) :	                    // 年调整-
	                   {
	   	               if(today.year[0]>0)
		                  today.year[0]=today.year[0]-1;
		               else 
		                   {
			               today.year[0]=99;
			               today.year[1]=today.year[1]-1;
			               }
	               	   display();
	                   }break;
	            default:						 //时钟正常计时
	                   {
				       EA=1;
					   TR0=1;
					   EX0=0;	
					   }break;
	         }break;
		}
}
//定时器中断程序 
void  timer0_int() interrupt 1 using 1
{
uchar c;
 TL0=(65536-1000)%256;		  
 TH0=(65536-1000)/256;
 TR0=1;
 count++;
 if(count==35)
    {
	count=0;
	now.second=now.second+1;
	 if(now.second>=60)
	    {
		now.second=0;
		now.minute++;
		if(now.minute>=60)
		   {
		   now.minute=0;
		   now.hour++;
		   if(now.hour>=24)
		      {
			  now.hour=0;
			  today.week++;
			  today.day++;
			  if(today.week>=8)
			     {
				 today.week=1;
				 }
			  c=monthday( today.year[1], today.year[0]);
			  if((c==1)&&(today.month==2))
			     {
				 if(today.day>=30)
				   {
				    today.day=1;
					today.month++;
				   }
				 }
			  else if(today基于51单片机的温度监控Proteus仿真_报警值可调

基于51单片机的交通灯Proteus仿真设计_带紧急开关+可调时间(源码+仿真+报告)

Proteus仿真51单片机+DAC0832+数码管制作0-25V电压可调

Proteus仿真4X4矩阵按键扫描组成的简易加法器

51单片机 按键控制数码管加减+Proteus仿真

Proteus VSM Studio汇编 + 8位数码管时钟按键可调