www.pudn.com > MP3DIY.rar > interrupt.c


//=========================================================== 
//   Project Name(项目名称):  SPCA755 rebuild 
//   File Name(模块名称): interrupt.c 
//   Built Date(创建日期):2004-09-14 
//   Abstract(模块描述): 中断功能函数模块 
//   Revision History(版本信息): 
//   Rev      Date           Author       Comment(修改说明) 
//   1.0      2004-09-14      XYQ         created 
//================================================================================================ 
#include "..\userdefine.h" 
#include "interrupt.h" 
#include "userinit.h" 
#include "user.h" 
#include "main.h" 
//================================================================================================ 
data U8 gc_KeyValue=0; 
data U8 gc_BatteryValue=0xff; 
data U8 gc_ADCOldKey=0; 
data U8 gc_LongKeyDelay=0; 
data U8 gc_LongKeyTimer=0; 
data U8 gc_QuarterTimer=0; 
data U8 gc_BlinkTimer; 
data U8 gc_SysSecondTimer; 
//================================================================================================ 
data U8 gc_SecondTimer; 
data U8 gc_minuteTimer; 
data U8 gc_basetimerx4;//lyh add 
//================================================================================================ 
#define K_USE_SPCA759_KEYB 
 
//================================================================================================ 
void UserExtInterrupt() interrupt 0 using 1 
{ 
 
	INTR_Int0();	 
	 
} 
 
void User_Timer() interrupt 1 using 2 
{//每7.8ms会进行中断一次(into this intterrupt per 7.8ms) 
	//该函数用户不能删除,否则定时器会不准确 
	 
 
	TIMER0_Routine();//the function must call here(该函数在此必须调用,该函数为设置定时器初值) 
 
	gc_QuarterTimer = (gc_QuarterTimer >= 3)?0:gc_QuarterTimer+1; 
 
	switch(gc_QuarterTimer) 
	{ 
		case 0: 
			if (gc_SysSecondTimer) 
			{ 
				gc_SysSecondTimer--; 
			}else{ 
				gc_SysSecondTimer = SECONDTIMER_VALUE; 
			} 
			break; 
		case 1:			 
	 
			gc_BatteryValue = USER_READSAR(2);  //read SAR output 
			 
			if (USB_PlugDetect()) 
    		{ 
     			gc_BatteryValue = 0xff; 
    		} 
 
			if (gc_BlinkTimer)gc_BlinkTimer--; 
 
			if (gc_LongKeyTimer) gc_LongKeyTimer++;			 
			break;  
		case 2: 
			if (!gc_KeyValue) 
			{//if oldevent haven't been deal with, not to get new keyValue 
			  
				if (1) 
				{ 
					data U8 tc_ADCCurrentKey; 
	 
					tc_ADCCurrentKey = USER_READSAR(0);  //read SAR output 
					 
			#if 0 
				#ifdef K_USE_SPCA759_KEYB 
					if (tc_ADCCurrentKey>240) tc_ADCCurrentKey=0; 
					else if(tc_ADCCurrentKey>171) tc_ADCCurrentKey=1; 
					else if(tc_ADCCurrentKey>149) tc_ADCCurrentKey=2; 
					else if(tc_ADCCurrentKey>124) tc_ADCCurrentKey=3; 
					else if(tc_ADCCurrentKey>96) tc_ADCCurrentKey=4; 
					else if(tc_ADCCurrentKey>66) tc_ADCCurrentKey=5; 
					else if(tc_ADCCurrentKey>36) tc_ADCCurrentKey=6; 
					else if(tc_ADCCurrentKey>11) tc_ADCCurrentKey=7; 
					else tc_ADCCurrentKey = 8; 
				/*	if (tc_ADCCurrentKey>240) tc_ADCCurrentKey=0; 
					else if(tc_ADCCurrentKey>217) tc_ADCCurrentKey=1; 
					else if(tc_ADCCurrentKey>182) tc_ADCCurrentKey=2; 
					else if(tc_ADCCurrentKey>139) tc_ADCCurrentKey=3; 
					else if(tc_ADCCurrentKey>104) tc_ADCCurrentKey=4; 
					else if(tc_ADCCurrentKey>75) tc_ADCCurrentKey=5; 
					else if(tc_ADCCurrentKey>41) tc_ADCCurrentKey=6; 
					else if(tc_ADCCurrentKey>14) tc_ADCCurrentKey=7; 
					else tc_ADCCurrentKey = 8;*/ 
				#else 
					if (tc_ADCCurrentKey>240) tc_ADCCurrentKey=0; 
					else if(tc_ADCCurrentKey>220) tc_ADCCurrentKey=1; 
					else if(tc_ADCCurrentKey>202) tc_ADCCurrentKey=2; 
					else if(tc_ADCCurrentKey>181) tc_ADCCurrentKey=3; 
					else if(tc_ADCCurrentKey>147) tc_ADCCurrentKey=4; 
					else if(tc_ADCCurrentKey>105) tc_ADCCurrentKey=5; 
					else if(tc_ADCCurrentKey>61) tc_ADCCurrentKey=6; 
					else if(tc_ADCCurrentKey>20) tc_ADCCurrentKey=7; 
					else tc_ADCCurrentKey = 8; 
				#endif 
			#else//MoonBox key value V2.0 
 
					if (tc_ADCCurrentKey>240) tc_ADCCurrentKey=0; 
					else if(tc_ADCCurrentKey>217) tc_ADCCurrentKey=7; 
					else if(tc_ADCCurrentKey>182) tc_ADCCurrentKey=8; 
					else if(tc_ADCCurrentKey>139) tc_ADCCurrentKey=5;  
					else if(tc_ADCCurrentKey>104) tc_ADCCurrentKey=4; //VOL+ 
					else if(tc_ADCCurrentKey>75) tc_ADCCurrentKey=6;  //MODE 
					else if(tc_ADCCurrentKey>41) tc_ADCCurrentKey=2;  //LAST 
					else if(tc_ADCCurrentKey>14) tc_ADCCurrentKey=1;  //NEXT 
					else tc_ADCCurrentKey = 3;                        //PLAY 
/* 
					if (tc_ADCCurrentKey>240) tc_ADCCurrentKey=0;					 
					else if(tc_ADCCurrentKey>210) tc_ADCCurrentKey=1; 
					else if(tc_ADCCurrentKey>180) tc_ADCCurrentKey=2; 
					else if(tc_ADCCurrentKey>140) tc_ADCCurrentKey=3; 
					else if(tc_ADCCurrentKey>96) tc_ADCCurrentKey=4; 
					else if(tc_ADCCurrentKey>66) tc_ADCCurrentKey=5; 
					else if(tc_ADCCurrentKey>36) tc_ADCCurrentKey=6; 
					else if(tc_ADCCurrentKey>11) tc_ADCCurrentKey=7; 
					else tc_ADCCurrentKey = 8;*/ 
			#endif 
				 
				 
					if ((gc_ADCOldKey & 0x0f) == tc_ADCCurrentKey) 
					{//按键未释放 
						if (tc_ADCCurrentKey != KEY_NONEKEY) 
						{ 
							if (gc_LongKeyTimer > gc_LongKeyDelay) 
							{ 
								gc_ADCOldKey = gc_ADCOldKey | 0x10;		//长按键 
								gc_KeyValue = gc_ADCOldKey & 0x7f; 
								gc_LongKeyTimer = REPEATKEY_DELAYVALUE;	//设置重复按键延时起始值 
								gc_LongKeyDelay = (gc_LongKeyDelay < MIN_REPEATKEYDELAY)?MIN_REPEATKEYDELAY:gc_LongKeyDelay-3;	//加速重复按键 
							} 
							else 
							{ 
								gc_ADCOldKey |= 0x80;  
							} 
						} 
					} 
					else if (tc_ADCCurrentKey == KEY_NONEKEY){//按键释放 
						if ((gc_ADCOldKey & 0x90) == 0x80) 
						{ 
							gc_KeyValue = gc_ADCOldKey & 0x7f;		//获取短按键值 
						}else if ((gc_ADCOldKey & 0x90) == 0x90){ 
							gc_KeyValue = (gc_ADCOldKey | 0x20) & 0x7f;//key value will be 0x3x 
						} 
						gc_ADCOldKey = KEY_NONEKEY; 
						gc_LongKeyTimer = 0;			//关闭按键计时器 
						gc_LongKeyDelay = 0;			//复位重复按键延时值 
					} 
					else{//有键按下 
						gc_ADCOldKey = tc_ADCCurrentKey; 
						gc_LongKeyTimer = 1;			//触发按键计时器 
						if (!gc_LongKeyDelay) gc_LongKeyDelay = MAX_REPEATKEYDELAY;  //若外部未初始化重复按键延时初始值则默认初始化 
					} 
				}else{ 
					gc_ADCOldKey = KEY_NONEKEY; 
				} 
			}			 
			break; 
		case 3: 
			gc_SecondTimer--; 
			if (!gc_SecondTimer) 
			{ 
				gc_SecondTimer = SECONDTIMER_VALUE; 
				if(gw_PowerOffTimer) 
				{ 
                   // printf("gw_PowerOffTimer =%x \n",gw_PowerOffTimer);  
					gw_PowerOffTimer--;//lizhn modify       
				} 
		 
				if(gc_Busy_Timer) 
				{ 
					gc_Busy_Timer--;//lyh add 		 
				}          
		        if(gc_FileNameRollTimer) 
				{ 
					gc_FileNameRollTimer--;//lyh add    0.125s  
				} 
			 	if (gc_minuteTimer) 
				{ 
					gc_minuteTimer--; 
				}else{ 
					gc_minuteTimer = MINUTETIMER_VALUE; 
				} 
		    } 
		    gb_UIEvent=TRUE;//lyh add 
		    gc_basetimerx4--;//lyh add 
		    if(!gc_basetimerx4) 
		    { 
		       gc_basetimerx4=BASETIMERX4_VALUE; 
			   /* 
		       if(gc_Busy_Timer)gc_Busy_Timer--;//lyh add           0.125s   
		       if(gc_FileNameRollTimer)gc_FileNameRollTimer--;//lyh add    0.125s*/  
		       if(gc_Battery_Detect_Timer)gc_Battery_Detect_Timer--;//lyh add 0.125s 
		    }	 
		    break; 
	} 
	 
}