⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 time.c.bak

📁 本程序是用51单片机设计的一个时钟程序,对于想了解单片机的C语言和汇编语言的开发人员是一个不错的例程.
💻 BAK
字号:
/*
**********************************************************************************
*           此模块为0.5s定时程序,每隔0.5sDot_Value值变一次                      *
**********************************************************************************
*/
#include <reg668.h>
#include <constant.h>

extern bit Dot_Value;
extern bit Time250msFlag;
extern unsigned char formflag;
extern bit Adjust;
//extern bit timerflag,songflag;
//extern unsigned char segflag;
extern unsigned char CountTime0;
//extern unsigned char Disp_array[Eight];
//extern unsigned char hout,mint;
unsigned char mon,dat,hou,min,sec;
unsigned int yea;
//bit flash250ms=0;

void Time_Half_Second (void) interrupt 1 using 1	//使用Timer0产生10ms中断。
{
	TH0=0x88;
	TL0=0x33;					//40 加快3min per day
	if (CountTime0%25==0)
	{
		Time250msFlag=1;
	}
	CountTime0 += 1;
	if (CountTime0==50)				//50次10ms中断,产生0.5s信号
	{
		Dot_Value =~ Dot_Value;
		CountTime0 = 0x00;
		if (Dot_Value==1 && Adjust==0)		//校时时计时器停止计时
		{
			sec++;				//秒计数器加"1"
			if (sec>=60)
			{
				sec=0x00;
				min++;
				if (min>=60)
				{
					min=0x00;
					hou++;
					if (hou>=24)
					{
						hou=0x00;
						dat++;
						switch (mon)
						{
							case 1:
							case 3:
							case 5:
							case 7:
							case 8:
							case 10:
							case 12:
								if (dat>31)
								{
									dat=0x01;
									mon++;
									if (mon>12)
									{
										mon=0x01;
										yea++;
									}
								}
								break;
							case 4:
							case 6:
							case 9:
							case 11:
								if (dat>30)
								{
									dat=0x01;
									mon++;
								}
								break;
							case 2:
								if (yea%4==0&&yea%100!=0||yea%400==0)
								{
									if (dat>29)
									{
										dat=0x01;
										mon++;
									}
								}
								else
								{
									if (dat>28)
									{
										dat=0x01;
										mon++;
									}
								}
								break;
							default:
								mon=0x01;
								break;
						}
					}
				}
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -