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

📄 time.c

📁 abov公司的单片机器MC80F7208的演示程序,C代码,包含LCD,I2C,KEY,ADC,NVM,TIME等内容,适合初学者熟悉.
💻 C
📖 第 1 页 / 共 2 页
字号:
//===============================================================
//  	File name : Time.C 
//=============================================================== 

//---------------------------------------------------------------
//	Include file and variable 
//---------------------------------------------------------------

#include <hms800.h>				//
#include "MC80C7208.h"				// SFR define 
#define  USER_EXTERN extern			// extern variable define            
#include "Variable.h"				//

//---------------------------------------------------------------
//	external prototype function	
//---------------------------------------------------------------


//===============================================================
//     task  : time wait service
//     input : delay_count
//=============================================================== 

//---------------------------------------------------------------
//	N(4~250) mSec interrupt down counter  delay 
//--------------------------------------------------------------- 

void Wait_msec(uchar Value)
{	
	rTimer_4ms[TIME_Wait] = (ushort)Value/4;	// N = V ms / 4 ms		 
	while(rTimer_4ms[TIME_Wait])			// down counter in 4 msec interrupt 
		asm("	nop	");				
}

//---------------------------------------------------------------
//	N usec delay 	by 4MHz crystal 	
//
//	(caution!) It is available over 48us delay 
//--------------------------------------------------------------- 

void Wait_uSec(ushort Value)		 
{
	wDly_count = Value-30;		// 30 us 

 asm("
 	lsr	_wDly_count+1		; 4	1/8 
	ror	_wDly_count			; 4
 	lsr	_wDly_count+1		; 4
	ror	_wDly_count			; 4
 	lsr	_wDly_count+1		; 4
	ror	_wDly_count			; 4

 Rpt_dly:
	decw	_wDly_count			; 6
	nop					; 2
	nop					; 2
	nop					; 2
	bne	Rpt_dly			; 4	500ns x 16 = 8us  
    ");
}


//===============================================================
//	task	: Time clock update 
//=============================================================== 

//---------------------------------------------------------------
//	task  : Timer0 4mSec time interval interrupt
//	input : 4msec cycle   
//	output: 4mSec x N
//---------------------------------------------------------------
	
void T0_Int_Handler(void)
{
	uchar m;
	
	for(m=0;m<5;m++)				//
	{						//					
		if(rTimer_4ms[m]) 		//
			rTimer_4ms[m]--;		// 
	}						//				

	if (!(rTimer_4ms[TIME_Sec]))		//
	{	rTimer_4ms[TIME_Sec] = 125;	// 500ms 

		if (f_Flicker)			//
		{	f_Flicker	= OFF;	//
			p_Yellow	= OFF;	//
		}
		else					//
		{	f_Flicker	= ON;		//
			p_Yellow	= ON;		//
		}
		f_OnLcd = ON;			// LCD Display 
	} 						//
}

//===============================================================
//	task	: Real Time Clock and Calendar Update   
//=============================================================== 

//--------------------------------------------------------------- 
// 辣斥 棺 1岿1老狼 夸老  (index = 2000 ~ 2099)
//--------------------------------------------------------------- 

//uchar Year_table[] __attribute__((section (".text"))) =  

CODE uchar Year_table[]=
{	
	0x86, // 2000 辣崔  1岿1老(配夸老)  
	0x01, //					       
	0x02, //						  
	0x03, //						 
	0x84, // 2004. 辣崔  1岿1老(格夸老) 
	0x06, //						
	0x00, // 2006	  1岿1老(配夸老) 					
	0x01, // 2007					
	0x82, // 2008					 
	0x04, //						
	0x05, //						
	0x06, //						
	0x80, // 2012					 
	0x02, //						
	0x03, //						
	0x04, //						
	0x85, // 2016					
	0x00, //						
	0x01, //						
	0x02, //						
	0x83, // 2020					
	0x05, //						
	0x06, //						
	0x00, //						
	0x81, // 2024					
	0x03, //						
	0x04, //						
	0x05, //						
	0x86, // 2028					
	0x01, //						
	0x02, //						
	0x03, //						
	0x84, // 2032					
	0x06, //						
	0x00, //						
	0x01, //						
	0x82, // 2036					
	0x04, //						
	0x05, //						
	0x06, //						
	0x80, // 2040					
	0x02, //						
	0x03, //						
	0x04, //						
	0x85, // 2044					
	0x00, //						
	0x01, //						
	0x02, //						
	0x83, // 2048					
	0x05, //						
	0x06, //						
	0x00, //						
	0x81, // 2052					
	0x03, //						
	0x04, //						
	0x05, //						
	0x86, // 2056					
	0x01, //						
	0x02, //						
	0x03, //						
	0x84, // 2060					
	0x06, //						
	0x00, //						
	0x01, //						
	0x82, // 2064					
	0x04, //	    					
	0x05, //						
	0x06, //						
	0x80, // 2068					
	0x02, //						
	0x03, //						
	0x04, //						
	0x85, // 2072					
	0x00, //						
	0x01, //						
	0x02, //						
	0x83, // 2076					
	0x05, //						
	0x06, //						
	0x00, //						
	0x81, // 2080					
	0x03, //						
	0x04, //						
	0x05, //						
	0x86, // 2084					
	0x01, //						
	0x02, //						
	0x03, //						
	0x84, // 2086					
	0x06, //						
	0x00, //						
	0x01, //						
	0x82, // 2090					
	0x04, //    						
	0x05, //						
	0x06, //						
	0x80, // 2094					
	0x02, //						
	0x03, //						
	0x04, //						
	0x85, // 2098					
	0x00  // 2099					
};


//-------------------------------------------------------------- 

CODE ushort Month_Day_table[] = 
{ 			// 捞傈岿 鳖瘤 朝楼荐 钦拌 
	0, 		// -
	0, 		// 1岿  31
	31,		// 2岿  28
	59, 		// 3岿  31
	90, 		// 4岿  30
	120, 		// 5岿  31
	151, 		// 6岿  30
	181, 		// 7岿  31
	212, 		// 8岿  31	 
	243, 		// 9岿  30
	273, 		// 10岿 31 
	304, 		// 11岿 30 
	334, 		// 12岿 31 
	365  		// - 
};

//---------------------------------------------------------------
//	task	: Search week day 
//	input	: rYear, rMonth, rDate, Month_Day_table, Year_table 
//	output: rWeek 
//---------------------------------------------------------------

void Check_Week_Day(void)
{
	i = Year_table[rYear];			// 2000~2099 
	j = Month_Day_table[rMonth];		// 捞傈岿 鳖瘤 sum of date 
	if(!(rYear & 0x03))			// 4斥付促 辣斥牢啊?  
	{	if (rMonth > 2) 			// 2岿 29老牢啊? 
			j++;				// 366老涝聪促. 
	}						// 
	
	j += (ushort)(i & 0x07);		// 1岿 1老狼 夸老阑 歹茄促.  
	j += (ushort)rDate;			// 秦寸岿狼 朝楼甫 歹茄促. 

	rWeek = j % 7;				// 醚 老荐 / 7 = 唱赣瘤啊 公郊 夸老捞促. 
}

//--------------------------------------------------------------- 
// maximum day ( index[month] = 1 ~ 12 )
//--------------------------------------------------------------- 

CODE uchar Month_table[] =
{	
	0,
	31,	// 1岿 
	28,	// 2
	31,	// 3
	30,	// 4
	31,	// 5
	30,	// 6
	31,	// 7
	31,	// 8
	30,	// 9
	31,	// 10
	30,	// 11
	31	// 12 standard 
};

uchar Check_Last_Date(void)
{
	i = Month_table[rMonth];		//
	if(!(rYear & 0x03)) 			// 概 4斥付促 辣斥牢啊?
	{	if (rMonth == 2)			// 辣斥 2岿崔篮 29老涝聪促 !!!
			i = 29;			//
	}
	
	if(rDate > i) return 1;			// last day + 1 
	else		  return 0;			//
}

//--------------------------------------------------------------- 
//	task	: Calculate Clock display data 
//	input	: rHour, rMinute 
//	output: 
//--------------------------------------------------------------- 

void Clock_Hex_Decimal(void)
{
/*
	if (f_AmPm)					// PM11:59  or 23:59 
	{ 	if(rHour > 11)			// 
		{	f_AM = OFF;			//
			i = rHour - 12; 		//PM12 ~ PM11
		}					//
		else	f_AM = ON;			//AM12 ~ AM11
		
		if (i == 0) i = 12;		// 00 --> 12 

		if (i > 9) 				//
		{	rLcd_Buf[0] = 1;		//
			rLcd_Buf[1] = i - 10;	//
		} 
		else					// 
		{	rLcd_Buf[0] = SPACE;	//
			rLcd_Buf[1] = i;		//
		}					// 
	}
	else
*/
//	{
		i = rHour;				; 
		rLcd_Buf[0] = i/10;		// 00 ~ 23 
		rLcd_Buf[1] = i%10;		//
//	}
	
	rLcd_Buf[2] = rMinute/10;		// 00 ~ 59 
	rLcd_Buf[3] = rMinute%10;		//	
}

//--------------------------------------------------------------- 
//	task	: Calculate Alram display data 
//	input	: rAlram_Hour, rAlram_Minute 
//	output: 
//--------------------------------------------------------------- 
void Alram_Hex_Decimal(void)
{
	i = rAlram_Hour;
	rLcd_Buf[0] = i/10;			// 00 ~ 23 
	rLcd_Buf[1] = i%10;			//
	
	i = rAlram_Minute;
	rLcd_Buf[2] = i/10;			// 00 ~ 59 
	rLcd_Buf[3] = i%10;			//	
}


//==================================================================
//	Melody Control 
//==================================================================
//	Buzzer sound ( Sound Frequency & Length )  
//     Melody sound ( 4MHz Oscillator base )
//--------------------------------------------------------------- 
//     [Frequency]
//--------------------------------------------------------------- 
//     澜钎     C(档)   D(饭)   E(固)   F(颇)   G(贾)   A(扼)   B(矫)
//	Octave 1 130.810 146.830 164.810 174.610 196.600 220.000 246.940
//	Octave 2 261.630 293.660 329.630 349.230 392.000 440.000 493.880
//	Octave 3 523.250 587.330 659.260 698.460 783.990 880.000 987.770
//	Octave 4 1046.50 1174.70 1318.50 1396.90 1568.00 1760.00 1975.50
//
//--------------------------------------------------------------- 
//	[Length] 
//--------------------------------------------------------------- 
//	Largo		4000 = 160 x 25 mSec  (Adagio, Rento) 酒林 蠢府霸 
//	Andante  	3700 = 148 x 25 mSec                  蠢府霸 
//	Andantino	3350 = 134 x 25 mSec                  炼陛 蠢府霸 
//	Moderato	3000 = 120 x 25 mSec                  焊烹 狐福霸 
//	Allegretto  2700 = 108 x 25 mSec                  炼陛 狐福霸 
//	Allegro  	2350 =  94 x 25 mSec                  狐福霸 
//    Vivache	2000 =  80 x 25 mSec  (Presto)        酒林 狐福霸  
//
//	柯 澜钎 :  /1	
//	2盒澜钎 :  /2    
//    4盒澜钎 :  /4
//	8盒澜钎 :  /8
//	16盒澜钎:  /16
//	桨钎 	  : 
//--------------------------------------------------------------- 
//	25mSec T2 interrupt Count 扁霖 Length 
//--------------------------------------------------------------- 
#define	EOT   	0xFF		// end of table
#define	PAUSE  	0x0A 		// PAUSE (桨钎)
/*
#define	Largo		160 		//  
#define	Andante	148 		//  
#define	Andantino	134 		//  
#define	Moderato	120 		// 
#define	Allegretto	108 		//  
#define	Allegro	94 		//  
#define	Vivache	80 		//  
*/
//--------------------------------------------------------------- 
//	16mSec T2 interrupt Count 扁霖 Length 
//--------------------------------------------------------------- 
#define	Largo		250 		//  
#define	Andante	231 		//  
#define	Andantino	210 		//  
#define	Moderato	187 		// 
#define	Allegretto	169 		//  
#define	Allegro	145 		//  
#define	Vivache	125 		//  

⌨️ 快捷键说明

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