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

📄 timer0.bak

📁 由单片机搞的软时钟
💻 BAK
字号:
/**************************************************************************
  
                   		THE 1602 CHAR LED LIB
  
             		COPYRIGHT (c)   2008 BY chenss.
                       		--  ALL RIGHTS RESERVED  --
  
   File Name:       timer0.h
   Author:          net.xicp.chenss
   Created:         2008/1/25
   Modified:		NO
   Revision: 		1.0
  
***************************************************************************/

#ifndef _TIMER0_H_
#define _TIMER0_H_

#include<reg52.h>
#include"buffer.h"

void MonCarry(void);


void oneSec(void) interrupt 1 using 1
{
	count0+=1;
	
	if(count0==400)
	{
		time[2]+=1;
		count0=0;
		isCarry=1;
	}


	count3+=1;
	if(count3==200)
	{
		count3=0;
		if(isFlick)
		{
			isFlicker=~isFlicker;
		}

		if(keyIndex==33&canFlickerSet)
		{
			isFlickerSet=~isFlickerSet;
		}else if(keyIndex==33)
			{
				isFlickerSet=0;
			}
	}


	if(startTimer)
	{
		count1+=1;
		if(count1==4)
		{
			count1=0;
			if(isLongTime)
			{
				count2+=1;
				if(count2==100)
				{
					count2=0;
					timer[2]+=1;
					isTimerCarry=1;
				}
			}else
			{
				timer[2]+=1;
				isTimerCarry=1;
			}
		}
	}

	
}

void initTimer0(void)
{
	EA=1;
	ET0=1;
	TMOD&=0xf0;
	TMOD|=0x02;
//	TH0=0x4c;
	TL0=0x6;
	PT0=1;
	TR0=1;
}

void carry(void)
{
	if(time[2]>=60)
	{
		time[2]=0;
		time[1]+=1;
	}

	if(time[1]>=60)
	{
		time[1]=0;
		if(isCarry){time[0]+=1;}
	}

	if(time[0]>=24)
	{
		time[0]=0;
		if(isCarry)
		{
			date[2]+=1;
			week[2]=1;
		}
	}

	if(week[2]>=8)
	{
		week[2]=1;
	}

	if(date[0]%4==0&date[1]==2)
	{
		if(date[2]>=30)
		{
			date[2]=1;
			if(isCarry){date[1]+=1;}
			
		}

	}else
	{
		 MonCarry();
	}	
			
		
	if(date[1]>=13)
	{
		date[1]=1;
		if(isCarry){date[0]+=1;}
		
	}

	if(date[0]>=100)
	{
		date[0]=0;
	}
}

void MonCarry(void)
{
	uchar nowMon,maxDay;
	nowMon=date[1];
	maxDay=coMonthMaxList[nowMon];
	if(date[2]>=maxDay)
	{
		date[2]=1;
		if(isCarry){date[1]+=1;}
	}
}


void TimerCarry(void)
{
	if(isLongTime)
	{
		if(timer[2]==60)
		{
			timer[2]=0;
			timer[1]+=1;
		}
		if(timer[1]==60)
		{
			timer[1]=0;
			timer[0]+=1;
		}
		if(timer[0]==23)
		{
			timer[0]=0;
		}
	}else
	{
		
		if(timer[2]==100)
		{
			timer[2]=0;
			timer[1]+=1;
		}
		if(timer[1]==60)
		{
			isLongTime=1;
			timer[1]=0;
			timer[0]+=1;
		}
		if(timer[0]==60)
		{
			isLongTime=1;
			timer[0]=1;
		}
	}

}
//************************************************************************
#endif

⌨️ 快捷键说明

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