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

📄 main.c

📁 abov公司的单片机器MC80F7208的演示程序,C代码,包含LCD,I2C,KEY,ADC,NVM,TIME等内容,适合初学者熟悉.
💻 C
字号:
//******************************************************************  
//	Low Cost LCD Remote Controller Demo Program 
//******************************************************************  
//	Project : Demo Program (LCD Remote Controller)    
//	Device  : MC80F7208L (64 LQFP) 
//	Date	  : '06.03.15 ~ '06.03.31 
//	Author  : Byeong Jin Lim 
//
//	File	  : 
//		    Variable.h 	Global variable define 
//		    Main.C		main frame structure
//		    Key.C		Key scan and execute  
//		    Time.C		Real Time Clock 
//		    Lcd.C		LCD display 
//		    Nvm.C		Eeprom interface 
//		    Int.S		Interrupt Assembly file 
//
//	Function:
//		    Remote Control signal out (NEC format)
//		    4 x 2 key matrix
//		    LCD display message 
//		    Real Time Clock 
//		    Alarm sound 
//		    Operating Frequency 4MHz, Voltage 5.0V 
//
//	History : 
//	
//	1. 06-03-15 .Demo Program coding start 
//	2. 06-06-27 .Revision 
// 	3. 06-11-08 .Melody function append 

//******************************************************************  

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

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

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

extern void Process_Key();			// Key.c				  	

extern void Process_Lcd();			// Lcd.c				  	
extern void Lcd_Clear();			//
extern void Clock_Hex_Decimal();		//
extern void Clock_Display();			//

extern void Process_Time();			// Time.c				  	
extern void Wait_usec(ushort);		// 

extern void Check_NVM_Initial();		// Nvm.c (Eeprom)
extern void Rd_Option();			//


//================================================================== 
//	Peripheral Register Initialize    
//==================================================================  

static void Initial( void )						
{

Program_Start:

	RPR		= 0x00;			// when setg, Ram Page is 1     
	SCMR		= 0x00;			// System Clock Mode Register		 
	CKCTLR	= 0x1F;			// BITR clock (=fxin/1024)  	 
	WTMR		= 0x8C;			// watch timer ensable, WDT load disable  	
	WDTR		= 0xFF;			//

//-----------------------------------------  
//	Port Initialize   
//-----------------------------------------   

	R0		= 0xFF;			// R07=1,	R06_1,	-	R04_1, 	R01  		         
	R0IO		= 0xFF;			// output,  output, 	- 	output,	output 				 		    
	R0PU		= 0x00;			// pullup,	pullup,	-	pullup,	without	 				 
	R0OD		= 0x00;			//  
	R0FUNC	= 0x00;			// INT1     INT0  		Buzzer 
	
	R1		= 0x00;			// R10	  		         
	R1IO		= 0x01;			// output	 				 		    
	R1PU		= 0x00;			// 		 				 
	R1OD		= 0x00;			//  	
	R1FUNC	= 0x00;			// PWM1O disable  		 

	R2		= 0x3F;			// R25/R24:Strobe    R23~R20:ADC  	  		         
	R2IO		= 0x30;			// output            input	 				 		    
	R2PU		= 0x00;			// without pullup		 				 
	R2OD		= 0x00;			// CMOS 

	R3PU		= 0xF0;			// pullup 		 				 
	R3OD		= 0xF0;			// open drain 
	R3		= 0xF0;			// R37~R34 (high)	  		         
	R3IO		= 0x0F;			// output  				 		    
	KSMR		= 0xF0;			// KS7~KS4 Key scan select   				 		    

	R5		= 0x00;			//   							 
	R5IO		= 0xFF;			//							 
	R5PSR		= 0x00;			// R5 LCD Segment out

	R6		= 0x00;			//  							 
	R6IO		= 0xFF;			//  							 
	R6PSR		= 0x00;			// R6 LCD Segment out

	R7PSR		= 0x00;			// R7 LCD Segment out 
	
	PFDR		= 0x80;			// 1100_0000b = 3V LVD Reset  

//-----------------------------------------  
//	System stabilization delay 
//-----------------------------------------  

	Wait_uSec(30000);				// 30 ms stability delay 

//	WDTR		= 0xFF;			//
//-----------------------------------------  
//	LCD initialize 
//-----------------------------------------   

	Lcd_Clear();				// LCD display off 

//-----------------------------------------  
//	EEPROM virgin check and initialize 
//-----------------------------------------  

//	Check_NVM_Initial(); 			// read virgin ID and initialize 

//	Rd_Option();				// last backed-up data load

	rCustom_Code= 0x04;			// test 
	rStop_Timer= 250;				// STOP mode in after 5sec delay  

	rLcd_Mode	= MODE_CLOCK;		//
	Clock_Hex_Decimal();			// 	
	Clock_Display();				//

	rMelody_Mode = BEEP_JjangGa;		// 
//-----------------------------------------  
//	Time interval interrupt start 
//-----------------------------------------  
	WTMR		= 0xCC;			// watch timer ensable, WDT load disable  	
	WTR  		= 0xF7;	 		// 0x80 | (119+1) = (1盒) 

	TM0		= 0x00;			//
	TDR0		= 124;			// T0 4ms interval ( 32 x 125 )   
	TM0		= 0x13;			// T0 psc = 4MHz/128 = 32us 	4ms interval 	

	TM2		= 0x00;			//
	TDR2		= 249;			// 64us x 250 = 16ms interval   
	TM2		= 0x13;			// T2 start   

	IENH		= 0x00;			//  
	IENM		= 0x80;			// T0E(7)   
	IENL		= 0x10;			// WTE(4)    					 

	IEDS		= 0x00;			// INT1 rising edge = 0000_1000b       
	IRQH		= 0;				// Clear All Interrupt Pending	 
	IRQM		= 0;				//   
	IRQL		= 0;				//						 

	WTMR		= 0x8C;			// watch timer ensable, WDT load disable  	

	asm("	
		clrg					;
		EI					; Enable global interrupt			 
		nop					; 
	   ");		
}

//================================================================== 
//	Main Subroutine  
//================================================================== 

main(void)
{
	Initial();					// start-up initialize 

	while (1)					//
	{	
		WDTR	= 0x9F;			// watchdog timer refresh ( 2 sec )	

		Process_Time();			// Clock count up	and measurement 	

		Process_Key();			// key  scan & execute  

		Process_Lcd();			// LCD display time check 

	/*
		if (!(rStop_Timer))		// for power saving mode control 
		{
			TM0	= 0x00;		// timer stop

			R2	= 0x0F;		// --00 xxxxb 
	
			p_Yellow = ON;		// lamp off 
			
			IENH	= 0x80;		// KSE(7) Key interrupt for wake up  
			IENM	= 0x00;		//    
			IENL	= 0x10;		// WTE(4)    					 

			IRQH	= 0;			// Clear All Interrupt Pending	 
			IRQM	= 0;			//   
			IRQL	= 0;			//   
			SSCR  = 0x5A;		// STOP ready !!!

			asm("				; 
				nop			;
				nop			;
				stop			;
				nop			; idle !!!
				nop			;
			  ");				// 
			  
			TDR0	= 124;		// T0 4ms interval ( 32 x 125 )   
			TM0	= 0x13;		// T0 psc = 4MHz/128 = 32us 	4ms interval 

			IENH	= 0x00;		//  
			IENM	= 0x80;		// T0E(7)   

			rStop_Timer = 250; 	// 20ms x 50 = 5sec delay before STOP mode in 
		}					//

	*/
	}						//
}							//

//==================================================================  
//	the end of Main.c								  							

⌨️ 快捷键说明

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