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


//=========================================================== 
//   Project Name(项目名称):  SPCA755 rebuild 
//   File Name(模块名称): user.c 
//   Built Date(创建日期):2004-09-14 
//   Abstract(模块描述): 用户函数模块 
//   Revision History(版本信息): 
//   Rev      Date           Author       Comment(修改说明) 
//   1.0      2004-09-14      XYQ         created 
//============================================================ 
//============================================================ 
#include "..\userdefine.h" 
#include "user.h" 
#include "userinit.h" 
#include "interrupt.h" 
#include "..\LCM\lcd501.h" 
#include "main.h" 
//================================================================================================ 
 
//****************************Note:以下函数必须保留,用户不能删除以下函数变量定义********************** 
//********************************************************************************************** 
#if ((K_CARD_TYPE &0x02)== 0x02) 
bit data gb_USBCardST0; 
bit data gb_USBCardST1; 
 
U8 xdata gc_MlunCardType; 
#endif 
 
#if ((K_CARD_TYPE &0x01)== 0x01) 
void	Mlun_NAND_Initialize(); 
#endif 
 
#if ((K_CARD_TYPE &0x02)== 0x02) 
void	Mlun_SD_Initialize(); 
#endif 
 
#if ((K_CARD_TYPE &0x04)== 0x04) 
void Mlun_SMC_Initialize(); 
#endif 
 
#if ((K_CARD_TYPE &0x08)== 0x08) 
void	Mlun_CF_Initialize(); 
#endif 
#if (K_CARD_TYPE &0x10 == 0x10) 
void	Mlun_MS_Initialize();//memory stick 
#endif 
 
#if ((K_CARD_TYPE &0x20) == 0x20) 
void	Mlun_XD_Initialize();//XD stick 
#endif 
 
code void (code *MlunMediaInitialize[K_CARD_TOTAL])()= 
{ 
	#if((K_CARD_TYPE &0x01)== 0x01) 
	Mlun_NAND_Initialize, 
	#endif 
	#if((K_CARD_TYPE &0x02)== 0x02) 
	Mlun_SD_Initialize, 
	#endif 
	#if((K_CARD_TYPE &0x04)== 0x04) 
	Mlun_SMC_Initialize, 
	#endif 
	#if((K_CARD_TYPE &0x08)== 0x08) 
	Mlun_CF_Initialize, 
	#endif 
	#if((K_CARD_TYPE &0x10)== 0x10) 
	Mlun_MS_Initialize,//SPCA755 NOT SUPPORT 
	#endif 
	#if((K_CARD_TYPE &0x20)== 0x20) 
	Mlun_XD_Initialize,//SPCA755 NOT SUPPORT 
	#endif 
}; 
xdata U8 MlunSequence[K_CARD_TOTAL]; 
//=============================*Note End*================================== 
//------------------------------------------------- 
void USER_FillSettingInfo(void); 
U16 USER_GetMusicTotalTime(void); 
void USER_GetSettingInfo(void); 
void USER_Remove_USB(void); 
void SD_InsertState_Detect(void); 
void X_Get_DefaultUserValue(void); 
void UI_PreProcessor_scan_key(void); 
void UI_Battery_Detect(); 
extern U8 UserSendDataToDSP(U8 tc_FileType,U8 tc_DspCommand); 
//============================================================================================ 
//--------- 
//Variable 
//--------- 
bit           gb_ShowNowSongNumberFG;//show the filename flag 
bit           gb_DisplayEvent_Happened;//ui_event flag 
bit           gb_ADCKey_Pressed; 
data  BIT     gb_FastFFFR=0; 
data  BIT     gb_Openfile=FALSE;         // For Open file Flag behind the UI-State transition 
data  BIT     gb_UIPostError = FALSE;    // The Error flag of UI post-processor for Audio Engine, such as Open file fail, initial fail etc. 
                                         // here can't initialize,move to main.c to initialize.xyq021228 
data  BIT     gb_RecordPauseAndStop;	 // chamber@030121 Close file when Stop after Pause!! 
 
 
xdata U8   gc_SKeyState;//[2]; 
xdata U8   gc_SPressingKey;//multi with gcl_ADCOldKey 
xdata U8   gc_SKeyHoldCnt;//[2]; 
xdata U8   REC_name[12]; 
xdata U8   gc_fileend; 
 
U8 gc_LongKey_Speed; 
U8 ForBackWord_SecondCount; 
 
bit                 gb_FFFRHoldToPlay; 
bit                 gb_LowBattery_StopRecord; 
U8 xdata gc_Play_Pause_Stop_State; 
U8 xdata gc_Menu_State; 
unsigned int  code  USER_SetIdleTime[]={0,180,300,600,1800}; 
U8 code  UserBackLightArray[]={5,10,15,30,0xff,0}; 
U8 code  USER_Set_Play_DPC_Value[]={12,8,3,17,22}; 
//U8 xdata gc_the_CurrentDSP_Volume; 
//============================================================================================ 
 
 xdata	U32	gdw_TxtFileStartCluster;//lyh add 
 xdata	U32	gdw_TxtFileCurrentCluster; 
 xdata	U32	gdw_TxtFileSize; 
 xdata	U8	gc_TxtDisplayBuf[41]; 
 xdata	U8	gc_TxtCurrentLen; 
 xdata 	U8  gc_TheSameTXT; 
 xdata 	U8  gc_DownorUp; 
 xdata 	U8  gc_OffsetByte; 
//============================================================================================ 
xdata U8 gc_USR_PowerOffCount; 
U8 xdata X_G_LRC_HaveGetFirstLyrics;//lyh add 
bit             _G_RecordNextFile;//lyh add 
xdata U8 gc_USR_HaveID3OrNot; 
data  U8     gc_sts ;//lyh add 
U8 data  gc_Battery_Detect_Timer;//lyh add 
xdata U8 ADCOldKey1; 
//============================================================================================ 
xdata U16 gw_TotalSecond; 
//============================================================================================ 
 #define MAXLEN 6 
 xdata U8  gc_UI_CurrSecond;//gc_UI_BSecond; 
 xdata U32   gdw_UI_ADataPoint; 
 xdata U32   gdw_UI_BDataPoint; 
 xdata U32   gdw_UI_AFrameCnt; 
 xdata U8 gc_UI_ABStateMode; 
 idata U8  gc_DOS_ErrorStatus;//lzp add for test 
//============================================================================================ 
//------------------------------------------------------------------------------- 
U16 USER_GetMusicTotalTime(void) 
{ 
	U16 tw_FileTotalSecond; 
	 
	if ((gs_File_FCB[gc_UIMode].c_FileType == AUDIO_FILE_TYPE_WAV)&&(gc_UIMode == 1)) 
	{ 
		tw_FileTotalSecond = ((gs_File_FCB[gc_UIMode].dw_File_TotalSize-60)*252/256)/4000;	 
	} 
	else 
	{ 
		tw_FileTotalSecond =((gs_File_FCB[gc_UIMode].dw_File_TotalSize/gs_System_State.w_BitRate)/125); 
	 
	} 
 
 
	return tw_FileTotalSecond; 
} 
//========================================================================================== 
void USER_Remove_USB(void) 
{ 
	//must initialize after remove USB 
	#if (K_CARD_TYPE == 0x03) 
	SMC_STORAGE_Initialize(); 
	if (gc_DOS_ErrorStatus = SD_STORAGE_Initialize())//try to initialize SD card 
	#endif 
	{//if SD card is not exist 
		gc_DOS_ErrorStatus = SMC_STORAGE_Initialize();//try to initialize SMC 
	} 
	//* 
	gw_FileIndex[0]=0; 
	gw_FileIndex[1]=0; 
	gw_FileIndex[2]=0; 
	 
	gw_FileTotalNumber[0]=0; 
	gw_FileTotalNumber[1]=0; 
	//*/ 
	if (gc_DOS_ErrorStatus == 0) 
	{		 
		USER_FindDir(0,gdw_DOS_RootDirClus);//detect DVR dir 
	} 
	 
	if (gdw_USER_DirClus[0])	 
	{//if DVR is exist 
		gs_File_FCB[1].dw_FDB_StartCluster = gdw_USER_DirClus[0];	 //040830 lzp add  
		gbt_FindFlag = 0;//当要第一次查找或改变查找文件类型时,都需要将该值清0	 
		DOS_Search_File(0x10,1,0x10);      //在单目录下统计录音文件总数 040907 LIZHN 
	} 
 
	gs_File_FCB[0].dw_FDB_StartCluster = gdw_DOS_RootDirClus; 
	gbt_FindFlag = 0;//当要第一次查找或改变查找文件类型时,都需要将该值清0 
	DOS_Search_File(0,0,0x10);//全盘检索音乐文件 
	 
	gbt_FindFlag = 0;//当要第一次查找或改变查找文件类型时,都需要将该值清0 
	if (gc_UIMode) 
	{ 
		 
		if (gdw_USER_DirClus[0] != 0) 
		{ 
			DOS_Search_File(0x12,gc_UIMode,0x10); 
		}	 
	} 
	else 
	{	 
		DOS_Search_File(0x01,0,0x10);//向下检索一个音乐文件	 
	} 
	if(gw_FileTotalNumber[gc_UIMode]) 
	{ 
 
		gw_FileIndex[gc_UIMode] = 1; 
	} 
	else 
	{ 
		gw_FileIndex[gc_UIMode] = 0;//clear index 
	 
//		gs_File_FCB[gc_UIMode].c_FileType = gc_UIMode + 4; 
	} 
	gb_Storage_Full=0; 
	gc_Menu_State=0; 
	gc_Busy_Timer = 0; 
/* 
	 if(!USER_Get_SYSInformation(0))   
	 { 
	 	 gb_Storage_Full=1; 
	 } 
	 else 
	 { 
	 	gb_Storage_Full = 0; 
	 } 
*/    
    UI_idle_Display();//lyh add 
    gc_SystemStateMode=SYSTEM_STATE0_IDLE; 
    USER_MCUClock_Select(K_MCU_LOWSPEED);//return back MCU Clock 
} 
 
//====================================================================================== 
#if (K_CARD_TYPE == 0x03) 
void SD_InsertState_Detect(void) 
{ 
	U8 tc_CardInsert; 
	U8 tc_DoInitialize = 0; 
	//printf("Time=%bx\n",gc_ReadWriteTimeOut); 
	if (gc_ReadWriteTimeOut) 
	{//if data read write timeout occur 
	    //printf("Read Write TimeOut\n"); 
		System_Stop(); 
		gc_ReadWriteTimeOut = 0; 
		gc_SystemStateMode = SYSTEM_STATE0_IDLE; 
	} 
	 
	if (gc_SystemStateMode == SYSTEM_STATE0_IDLE) 
	{//if in IDLE STATE 
		 
		STORAGE_Detect(&tc_CardInsert); 
//printf("tc_CardInsert=%bu\n",tc_CardInsert); 
		if (tc_CardInsert)//首先要判断是否有卡插入 
		{//if SD or MMC is not insert last time 
			if (!(gc_CurrentExistMedia & 0x40))//如果有,而且是bit6为0,说明上一次检测时,是没有卡插入的。因为如果上一次有卡插入的话,其值一定为1。 
			{ 
				if (!SD_SetInterface(CURRENT_MEDIA_SD)) 
				{ 
					gc_CurrentCard = CURRENT_MEDIA_SD; 
					gc_CurrentExistMedia |= 0x40; 
					gc_DOS_ErrorStatus = SD_STORAGE_Initialize(); 
//printf("gc_DOS_ErrorStatus=%bu\n",gc_DOS_ErrorStatus); 
		 			tc_DoInitialize = 1;	 
				} 
				else if (!SD_SetInterface(CURRENT_MEDIA_MMC)) 
				{ 
					gc_CurrentCard = CURRENT_MEDIA_MMC; 
					gc_CurrentExistMedia |= 0x40; 
					gc_DOS_ErrorStatus = SD_STORAGE_Initialize(); 
					tc_DoInitialize = 1;	 
				} 
				else if (gc_CurrentExistMedia & 0x80) 
				{ 
					FlashExchang(CURRENT_MEDIA_NAND,CURRENT_MEDIA_MMC,1); 
				} 
		 
			} 
		} 
		else 
		{ 
			if ((gc_CurrentExistMedia & 0x40) == 0x40) 
			{//if SD or MMC is insert last time 
				gc_CurrentExistMedia &= 0xbf; 
				if (gc_CurrentExistMedia & 0x80) 
				{			 
					gc_DOS_ErrorStatus = SMC_STORAGE_Initialize(); 
					tc_DoInitialize = 1; 
				}  
			} 
		} 
		 
		if (tc_DoInitialize) 
		{ 
			 
			if (gc_DOS_ErrorStatus == 0) 
			{		 
				USER_FindDir(0,gdw_DOS_RootDirClus);//detect DVR dir 
			} 
 
			if (gdw_USER_DirClus[0] != 0) 
			{ 
				gs_File_FCB[1].dw_FDB_StartCluster = gdw_USER_DirClus[0]; 
				gbt_FindFlag = 0;//当要第一次查找或改变查找文件类型时,都需要将该值清0	 
				DOS_Search_File(0x10,1,0x10); 
				DOS_Search_File(0x12,1,0x10);	 
			} 
		 
			gs_File_FCB[0].dw_FDB_StartCluster = gdw_DOS_RootDirClus; 
			gbt_FindFlag = 0;//当要第一次查找或改变查找文件类型时,都需要将该值清0 
			DOS_Search_File(0,0,0x10);//全盘检索音乐文件 
			DOS_Search_File(0x01,0,0x10);//向下检索一个音乐文件 
			if(gw_FileTotalNumber[gc_UIMode]) 
			{ 
				gw_FileIndex[gc_UIMode] = 1; 
			 
			} 
			else 
			{ 
		 
			} 
	 
			UI_SetDispTimeToDispBuf(0);//clear time 
			 
			 
		} 
	}     
} 
#endif 
//========================================================================================== 
 
//========================================================================================== 
void UI_Connect_USB() 
{ 
   if(gb_USB_Setup_Ack==1) 
   LCD501_Disp_PCConnect(); 
} 
 
//========================================================================================== 
void UI_Battery_Detect_ND_Display() 
{ 
 
	if(!gc_Battery_Detect_Timer) 
	{ 
         //printf("gc_Battery_Detect_Timer=%bu\n",gc_Battery_Detect_Timer); 
		//printf("backlight=%bx\n",gc_BacklightCount); 
		if(gc_BacklightCount<0xf0)//if not permanence back light 
		{ 
			//printf("gc_BacklightCount = %bx\n",gc_BacklightCount); 
			if(gc_BacklightCount) gc_BacklightCount--; 
			if(!gc_BacklightCount) 
			{ 
//				BackLightOff;//turn off backlight 
			} 
		} 
		if(!gc_Busy_Timer) 
		{ 
			UI_Battery_Detect(); 
//			if(gc_USB_Connect)gc_Battery_Level=10;//lyh add 
          //printf("gc_USB_Connect=%bu\n",gc_USB_Connect); 
          //printf("gc_Battery_Level=%bu\n",gc_Battery_Level); 
			{ 
				LCD501_Disp_Battery();				 
			} 
		} 
		gc_Battery_Detect_Timer=16;//2s=0.125*16 
	} 
} 
//=========================================================================================== 
void UI_Battery_Detect() 
{ 
	U8 ADC_Value; 
	U8 i; 
	U8 code ADC_Table[]= 
	{0x3e,0x46,0x4e,0x55,0x5f,0x67,0x6d,0x75,0x7c,0x85,0x8d,0x95,0x9c,0xa3,0xad}; 
	//0.7v0.8v 0.9v 1.0v 1.1v 1.2v 1.3v 1.4v 1.5v 1.6v 1.7v 1.8v 1.9v 2.0v  
	//ADC_Value=0xD0; 
	ADC_Value=gc_BatteryValue;//L2_Read_SARADC(2); 
	i=0; 
	while(ADC_Value>=ADC_Table[i]) 
	{ 
		i++; 
		if(i>=15) break; 
	} 
	gc_Battery_Level=i; 
	HSTPrint("ADC_Value=%bx\n",ADC_Value); 
	return; 
} 
//=========================================================================================== 
 
//===========================================UI=================================================== 
//============================================================================================== 
void UI_PreProcessor_scan_key(void)// lyh add 
{ 
	gc_EVENT=gc_KeyValue;//gc_SPressingKey;//put the value to gc_EVENT,then,gc_SPressingKey=0.if shield the function--UI_GetShortOrLongKeyCode,gc_SPressingKey will always be 0; 
  
	if (gc_KeyValue) 
	{	 
		gc_KeyValue = 0; 
	} 
	if ((gc_LongKeyDelay < (MAX_REPEATKEYDELAY - 3)) && (gc_EVENT == LONG_KEY_PLAY_EVENT)) 
	{//当按键不需要有长按键连发功能,必须在此将连发事件清除 
		gc_EVENT = 0; 
	} 
//	printf("gc_EVENT=%bu\n",gc_EVENT); 
 
//	if(LockPin_Locked)//is the lock event is happened or not? 
	if(0)//is the lock event is happened or not? lss 060612 
	{ 
		if(!gc_Menu_State && gc_KeyLockState==0) 
		{ 
			LCD501_Disp_Icon_Lock(1); 
		} 
		gc_KeyLockState=1;//lock 
	} 
	else 
	{ 
		if(!gc_Menu_State && gc_KeyLockState==1) 
		{ 
			LCD501_Disp_Icon_Lock(0); 
			gc_Busy_Timer=0; 
		} 
		gc_KeyLockState=0;//unlock			 
	} 
 
	if(gc_EVENT) 
	{ 
		if(gc_UserBacklightLevel<5) 
		{ 
			gc_BacklightCount = UserBackLightArray[gc_UserBacklightLevel]; 
//			BackLightOn;//GPIO1 
		} 
		gw_PowerOffTimer=USER_SetIdleTime[gc_USR_PowerOffCount]; 
		gb_DisplayEvent_Happened=1; 
	} 
#if 1 
	if(gc_KeyLockState)//if lock key,then any key is pressing at gc_Menu_State,so show Icon. 
	{ 
		if(gc_EVENT && !gc_Menu_State) 
		{ 
			SPLC501_Disp_PowerOnLock(); 
			gb_ShowNowSongNumberFG=true; 
			gc_Busy_Timer = 16; 
		} 
		gc_EVENT=0; 
	}	 
#endif 
	gc_SPressingKey=0x00; 
	if(gb_ShowNowSongNumberFG && !gc_Busy_Timer)//return to filename and time display 
	{ 
		//printf("disp idle event\n"); 
		gb_DisplayEvent_Happened=1; 
		gc_Menu_State=0; 
	} 
} 
//================================================================================================ 
void UI_VolumeUpDown(bit tbt_UpDown) 
{ 
 
	if(tbt_UpDown) 
	{ 
		if(gc_DSP_Volume<=K_DSP_VolumeMax-3) gc_DSP_Volume+=3; 
	}else{ 
		gc_DSP_Volume-=3; 
		if(gc_DSP_Volume>=K_DSP_VolumeMax)gc_DSP_Volume=K_DSP_VolumeMax; 
	} 
//	gc_the_CurrentDSP_Volume=gc_DSP_Volume; 
 
	if(gc_SystemStateMode==SYSTEM_STATE1_PLAYING)//dsLONG_KEY_PLAY_EVENT 
	{ 
		System_SetVolume(gc_DSP_Volume); 
	} 
	LCD501_Disp_VOL_LEVEL(gc_DSP_Volume); 
	//gc_Busy_Timer = 16;             //two seconds 
	//gb_ShowNowSongNumberFG=true; 
	gb_UI_UserSeeting_Changed=1; 
	gc_LongKey_Speed=4; 
 
} 
//================================================================================================ 
//at here delete a function to count the bitrate of mp3.UI_ASK_AudioCODEC_AboutMP3_Bitrate() 
//================================================================================================ 
void UI_FastForBackward()//will get bitrate,seconds,then stop; get the new sector,new cluster;set the play 
{  
   // U16 tw_TotalSecond;//,liyonghua;	//lizhn modify the varible to be globe 
	if(!gb_FastFFFR) 
	{     
		gb_FastFFFR=TRUE; 
        gc_SystemStateMode=STATE_FF;//lyh add 
		System_FastForBackward(); 
		gw_TotalSecond = USER_GetMusicTotalTime();//get the totalsec.	 
		//	printf("Currt=%x\n",G_Currtotalsecond);	 
		//		printf("Total=%x\n",gw_TotalSecond); 
		G_Currtotalsecond = UI_GetDispTimeFromDispBuf();//at here ,return the value of currentsec 
		ForBackWord_SecondCount=0;//add by xyq    set the counter 0 
	} 
	//=================================== 
	//Fast forward&backward time's count 
	//=================================== 
	if(gc_EVENT) 
	{ 
		ForBackWord_SecondCount++;//add by xyq 
		if(!(ForBackWord_SecondCount%6)) 
		{ 
			if(gc_LongKey_Speed<12) gc_LongKey_Speed++;//the speed increase if 6,12... 
		} 
	} 
 
	if(gc_EVENT==LONG_KEY_FF_EVENT) 
	{ 
		G_Currtotalsecond += 1; 
		//printf("Currt=%x\n",G_Currtotalsecond);	 
		//printf("Total=%x\n",gw_TotalSecond); 
		UI_SetDispTimeToDispBuf(G_Currtotalsecond); 
		if(G_Currtotalsecond>gw_TotalSecond || ((gc_PlaySequenceMode == 0x04) && (G_DISPLAY_TotalSec>10))) 
		{ 
 
			gc_SystemStateMode=SYSTEM_STATE0_IDLE;//goto play_state 
			gb_FastFFFR=FALSE; 
			gb_FFFRHoldToPlay=1; 
			return; 
		} 
	} 
	else if(gc_EVENT==LONG_KEY_FR_EVENT) 
	{ 
		G_Currtotalsecond -= 1; 
		UI_SetDispTimeToDispBuf(G_Currtotalsecond); 
		if(G_Currtotalsecond<=0) 
		{ 
			gc_SystemStateMode=SYSTEM_STATE0_IDLE; 
			gb_FastFFFR=FALSE; 
			gb_FFFRHoldToPlay=1; 
			return; 
		} 
	} 
	//========================== 
	//Count the current Min&Sec 
	//========================== 
	G_DISPLAY_TotalSec = G_Currtotalsecond;//so the two variables ,in fastward,G_Currtotalsecond increasing fast!DSP should stop! 
	//==================================== 
	//test release point and restart play 
	//==================================== 
	if((gc_EVENT == LONG_KEY_FF_RELEASE_EVENT) || (gc_EVENT == LONG_KEY_FR_RELEASE_EVENT)) //if the key released 
	{ 
        if(gb_FastFFFR) 
        { 
        gb_FastFFFR=0; 
    	System_FileFixPoint(G_Currtotalsecond); 
//liyonghua= 
        UI_GetDispTimeFromDispBuf(); 
 
        } 
		gc_SystemStateMode=SYSTEM_STATE1_PLAYING;//change state ff to play 
		gb_FastFFFR=FALSE; 
		gc_LongKey_Speed=9;//add by xyq,reset speed 
	}  
} 
//================================================================================================ 
void LED_Blink(void) 
{ 
	if((!gc_BlinkTimer) || (!G_USBReadWriteCount))//turn on LED 
	{ 
		G_USBReadWriteCount=2; 
		gc_BlinkTimer=9;//LED OFF 3*125mS//by lixt 
//		if(G_Powerstate==0x02) 
		{ 
			//G_LED_Blink_On_Timer=5;//LED OFF 3*125mS 
			SPLC501_Disp_MusicLogo(_G_USBReadOrWrite_ForUI); 
		} 
	} 
 
} 
//================================================================================================ 
unsigned int xdata G_APointSeconds;//if G_APointSecond will cause multi error.so --s. 
void Rep_AB() USING_0//in void Audio_CoDec(void) USING_0 to judge is at b point 
{	 
   	switch(gc_AB_Cnt) 
   	{   		 
		case 0:  //repeat A playing   get the lrctime and the resdiual sectornum of a G_ASectorNUM = L2_DSP_Read_DMem16(DSP_ResBuffer);  
			#ifdef Support_LRCFile 
			if((gc_LrcFileName_Exist)) 
			{ 
				G_APointLRCStartSecond = gw_LrcRecentTime;//lyh delX_G_LRC_RecentLRCTime;//show  the lrc time 
			} 
			#endif//#ifdef Support_LRCFile 
//			G_DelayFrameCounter = 0; 
			LCD501_Disp_Apoint(ON); 
			System_SetRepeatAB(gc_AB_Cnt); 
            gc_AB_Cnt=1;//lyh add 
			break; 
		case 1:  //repeat B playing,but at b point will get the all sector 
			if(System_SetRepeatAB(gc_AB_Cnt) == gc_AB_Cnt)//for wma very short AB repeat BUG 
			{//if set B point is fail, return to A point 
				gc_AB_Cnt=1; 
				break; 
			} 
//			G_AsearchCluster = USR_File_Seek(G_ASectorNUM); // Keep the Current searchCluster 
//			Rep_AB_Goto_Apoint_To_Play(0);//go to a point to play,0 need stop or not 
//          System_SetRepeatAB(3); 
			LCD501_Disp_Bpoint(ON);///show point b icon 
            gc_AB_Cnt=2;//lyh add 
			break; 
		case 2:  //Clear A-B Play 
            LCD501_Disp_Apoint(OFF);LCD501_Disp_Bpoint(OFF); 
			//LCD501_Disp_ABPoint(0); 
			System_SetRepeatAB(gc_AB_Cnt); 
            gc_AB_Cnt=0;//lyh add 
			gc_fileend = 0; 
			break; 
        default: 
    		break; 
   	} 
} 
//================================================================================================ 
void UI_Close_File()//when SYSTEM_STATE0_IDLE,file_close(NULL, K_DOS_ReadFile, 0) 
{ 
	if(gc_SystemStateMode!=SYSTEM_STATE0_IDLE) 
	{ 
		System_Stop();//some question for don't know the detail of the function. 
   		if(_WMA) 
		{ 
			_WMA=0;                //@@chchang_012803 
		} 
	} 
} 
//================================================================================================ 
void Playing_To_Stop()//set some paramter ,SYSTEM_STATE0_IDLE,included gc_Play_Pause_Stop_State=2;SYSTEM_STATE0_IDLE;gc_USR_PowerOffCount=USER_SetIdleTime[gc_USR_PowerOffCount]; 
{ 
	UI_Close_File(); 
 
	gc_Play_Pause_Stop_State=2;//this variable just in the user.c 
	gc_SystemStateMode=SYSTEM_STATE0_IDLE; 
	gw_PowerOffTimer=USER_SetIdleTime[gc_USR_PowerOffCount];//if in the SYSTEM_STATE0_IDLE,after the time to poweroff 
    gb_USB_PowerPlug_Interrupt=0; 
} 
//================================================================================================ 
void UI_Exe_Format()//show format... 
{ 
	LCD501_Disp_IconMenu(S_Del_Disk_FORMATProg);//"FORMAT ...  " 
 
    DOS_Format();//not make sure this function is realized all the functions. 
	gc_DOS_ErrorStatus = 0;//must clear dos error status for SearchFreeCluster(040904 add) 
 
	#if (K_CARD_TYPE == 0x03) 
	if (gc_DOS_ErrorStatus = SD_STORAGE_Initialize())//try to initialize SD card 
	#endif 
	{//if SD card is not exist		 
		gc_DOS_ErrorStatus = SMC_STORAGE_Initialize();//try to initialize SMC 
	} 
	//while(1); 
    gw_FileTotalNumber[0]=0; 
    gw_FileTotalNumber[1]=0; 
    gw_FileTotalNumber[2]=0; 
	gw_FileIndex[0]=0;//clear file index after format(040830 lzp add) 
	gw_FileIndex[1]=0; 
	gb_Storage_Full = 0; 
	UI_SetDispTimeToDispBuf(0);//clear time 
	gdw_USER_DirClus[0] = 0; 
	USER_Create_Dir(0,gdw_DOS_RootDirClus);//create DVR	 
	gc_KeyValue = 0;//clear key 
    LCD501_Clear_ALL(); 
} 
//================================================================================================ 
void UI_Disp_Page0()//the volume,the lock,abpoint,eq,playeq,battery 
{ 
//	SPLC501_Erase_OnePage(0); 
	LCD501_Disp_VOL_LEVEL(gc_DSP_Volume); 
	LCD501_Disp_Icon_Lock(gc_KeyLockState); 
	LCD501_Disp_ABPoint(gc_AB_Cnt); 
	LCD501_Disp_REP1ALL(gc_PlaySequenceMode); 
	LCD501_Disp_DSPEQ(gc_PlayEQMode); 
	LCD501_Disp_Battery(); 
} 
//================================================================================================ 
U8 UI_StorageIsError()//show the icon storageerror if gc_DOS_ErrorStatus=1,return 1 
{ 
	if(gc_DOS_ErrorStatus) 
	{ 
		gw_FileTotalNumber[gc_UIMode]=0;//there are no mp3 and dvr's files existed 
		gw_FileIndex[gc_UIMode]=0;//hxd030711 add 
		LCD501_Disp_StorageError(gc_DOS_ErrorStatus); 
		gb_DisplayEvent_Happened=0; 
		return 1; 
	}else{ 
			return 0; 
	} 
} 
//================================================================================================ 
void UI_GetMusicInfo()//lyh add 
{ 
     U8 tc_returnvalue;//,i; 
//printf("gc_UIMode=%bu\n",gc_UIMode); 
     if(gc_UIMode==0) 
     { 
//	  	U8 i; 
	   
         gc_USR_HaveID3OrNot=UI_GET_ID3INFO(gc_FileLongName); 
//printf("gc_USR_HaveID3OrNot=%bu\n",gc_USR_HaveID3OrNot); 
		 if(gc_USR_HaveID3OrNot)//UI_GET_ID3INFO ,how to set the parameter of it? //lyh add 
         { 
		     Dos_GetFileLongName(0,0,gc_FileLongName);  
		 } 
         X_Unicode2ISN(gc_FileLongName,1); 
		 UI_GetFileNameLength(); 
      } 
	  else 
   // if(gc_UIMode==1)//lyh add 
     { 
         tc_returnvalue=Dos_GetFileLongName(gc_UIMode,NULL,gc_FileLongName);  
		 /* 
		 { 
		 	U8 i; 
			for(i=0;i<8;i++) 
			{ 
				printf("%bx\n",gc_FileLongName[5+i]); 
			} 
		  
		 } 
		 */ 
		 
         UI_GetFileNameLength(); 
	//	 printf("test display\n"); 
     } 
//    LCD501_Disp_FileName(&gc_FileLongName[gw_DispFileName_ByteOffset+5],gc_SongNameNDSingerName_Length-gw_DispFileName_ByteOffset,1); 
//2005-2-3     
} 
//================================================================================================ 
void UI_idle_Display()//in the idle_state ,show the filename,and set some parameters,,UI_Refresh_DispAll(1) 
{ 
	if(!UI_StorageIsError()) 
	{ 
	//printf("State=%bx\n",gc_Menu_State); 
		if(gc_Menu_State==0) 
		{ 
           UI_GetMusicInfo(); 
        } 
	 
		gc_AB_Cnt=0; 
		gc_Play_Pause_Stop_State=2; 
		if(gc_Menu_State==0) 
		{ 
			UI_Refresh_DispAll(1);//show the name 
		} 
	} 
	gw_PowerOffTimer=USER_SetIdleTime[gc_USR_PowerOffCount]; 
 
	//gb_DisplayEvent_Happened=0; 
	gb_ShowNowSongNumberFG=0; 
	gc_LongKey_Speed=9;//add by xyq 
	gc_FileNameRollTimer=1;//set the interval time to roll the filename 
} 
//================================================================================================ 
void UI_Refresh_DispAll(bit DispFileName)//display all the icon in the initial state 
{ 
//printf("Timer=%bx\n",gc_Busy_Timer); 
	if(!gc_Busy_Timer)    //if the refresh time is coming on 
	{  
 		LCD501_Clear_ALL(); 
		//SPLC501_Erase_OnePage(3); 
		UI_Disp_Page0(); 
		LCD501_Disp_CurrentFileMode(DSP_MenuMODE[gc_UIMode]);//DSP_MenuMODE[] ={KDSP_MP3_MODE,	KDSP_DVRD_MODE,	KDSP_DVRE_MODE} 
		LCD501_Disp_Bitrate(0);//space//at somewhere to show the bitrate. 
		if(gc_PlayMode==PLAY_ALL) 
		{ 
			LCD501_Disp_FileIndex_InDIR(gw_FileIndex[gc_UIMode],gw_FileTotalNumber[gc_UIMode]);//show the fileindex in the dir 
		}else{ 
//lyh del			LCD501_Disp_FileIndex_InDIR(G_PlayListIndex,G_PlayListLen); 
		} 
		 
		LCD501_Disp_HHMMSS(0);//show time 
		 
		LCD501_Playing_Pause_Stop_Record(gc_Play_Pause_Stop_State);//show the state 
		{	 
			if(DispFileName)//0 or 1 
			{ 
			 
//				if(gw_FileIndex[gc_UIMode]) 
				if(gw_FileTotalNumber[gc_UIMode]) 
				{ 
					//printf("display file\n"); 
				       X_G_OverStep_DispArea=LCD501_Disp_FileName(&gc_FileLongName[gw_DispFileName_ByteOffset+5],gc_SongNameNDSingerName_Length-gw_DispFileName_ByteOffset,1); 
//printf("X_G_OverStep_DispArea=%bu\n",X_G_OverStep_DispArea); 
               	}else{ 
					LCD501_Disp_NoFile(gc_UIMode); 
				} 
			} 
		} 
		gb_DisplayEvent_Happened=0; 
		gb_ShowNowSongNumberFG=0; 
	} 
} 
//================================================================================================ 
void UI_RollFileName()//if the filename beyond the lcd ,so rolling ,the same with lrc 
{ 
    if((!gc_FileNameRollTimer)&&(!gc_Busy_Timer)&&(gw_FileTotalNumber[gc_UIMode])&&(!gc_Menu_State)&&(X_G_OverStep_DispArea)) 
	{ 
		#ifdef Support_LRCFile//gc_FileNameRollTimer indicated the interval to show the filename 
		if((gc_LrcFileName_Exist) && (gc_SystemStateMode==SYSTEM_STATE1_PLAYING || gc_SystemStateMode==STATE_PLAY_PAUSE) )//&& X_G_LRC_HaveGetFirstLyrics) 
		{  
			LCD501_Disp_FileName(&gc_LrcDisplayBuf[gw_DispFileName_ByteOffset],gc_LrcCurrentLen-gw_DispFileName_ByteOffset,1); 
		}else 
		#endif//#ifdef Support_LRCFile 
		{  
            if(gc_SystemStateMode==STATE_FR||gc_SystemStateMode==STATE_FF)goto end; 
			LCD501_Disp_FileName(&gc_FileLongName[gw_DispFileName_ByteOffset+5],gc_SongNameNDSingerName_Length-gw_DispFileName_ByteOffset,1); 
		} 
end: 
		gc_FileNameRollTimer=1;//check the time,if beyond ,rolling 
	} 
 
} 
//================================================================================================ 
void UI_GetFileNameLength() 
{ 
//   U8 tw_Lenth; 
     gc_SongNameNDSingerName_Length=gc_FileLongName[4]; 
//	 tw_Lenth =(U16)((gc_FileLongName[0]<<8)|(gc_FileLongName[1])); 
//   gc_SongNameNDSingerName_Length=(U8)tw_Lenth; 
     
} 
//================================================================================================ 
void Main_Get_FreeMemory()//will update the library! 
{ 
    U32 tdw_TotalFreeClusNumber;//lyh add 
    LCD501_Disp_CheckDisk();   
	tdw_TotalFreeClusNumber=USER_Get_SYSInformation(0);//call this function need to update the library. 
	gdw_Dos_FreeMemorySizeMB=((U32)tdw_TotalFreeClusNumber*512)*10/1024/1024; 
//   printf("gdw_Dos_FreeMemorySizeMB=%lx\n",gdw_Dos_FreeMemorySizeMB); 
} 
//================================================================================================ 
bit Func10_CheckLRC() 
{ 
	if(gc_SystemStateMode == SYSTEM_STATE1_PLAYING&&gc_LrcFileName_Exist) 
	{ 
		X_Get_LRC_TimeStamp(); 
		if(gb_LrcGetTimeOrNot) 
		{gb_LrcGetTimeOrNot=0;			 
			X_Get_LRC_Lyrics();//read the sector to store in a buffer,so if offset more than the maxnumber,stop;if than a sector,get another sector;if the end of the file ,restart.			 
			X_G_OverStep_DispArea=LCD501_Disp_FileName(gc_LrcDisplayBuf,gc_LrcCurrentLen,1); 
 
//			LCD501_Disp_FileName(&gc_LrcDisplayBuf[gw_DispFileName_ByteOffset],gc_LrcCurrentLen-gw_DispFileName_ByteOffset,1); 
			gw_DispFileName_ByteOffset=0; 
		} 
	} 
	return 0; 
} 
//================================================================================================ 
void UI_FFFR(bit XFFFR)//go the next or ahead file,File_Close(NULL, K_DOS_ReadFile, 0); 
{                            //->Search_File(GS_SearchMode,gc_UIMode,0); 
                            //if state_waitidle,after search file ,then show the related informations 
	switch(gc_SystemStateMode) 
	{ 
		case SYSTEM_STATE0_IDLE: 
			if(gw_FileIndex[gc_UIMode]==0) 
				return;//if no this line,error will happen 
			break; 
		case SYSTEM_STATE1_PLAYING: 
			gb_Openfile = TRUE; // Make Openfile post-processor activity 
			break; 
		case STATE_PLAY_PAUSE: 
			gc_SystemStateMode = SYSTEM_STATE0_IDLE; //return to IDLE State 
			break; 
	} 
    System_NextOrPrev(XFFFR, 1, gc_UIMode); 
	if(gc_SystemStateMode==STATE_WaitDEL)//which the different between Systemstate and UIstate? 
	{ 
		UI_GetMusicInfo();				 
		LCD501_Disp_FileIndex_InDIR(gw_FileIndex[gc_UIMode],gw_FileTotalNumber[gc_UIMode]); 
		LCD501_Disp_REP1ALL(gc_PlaySequenceMode); 
	} 
//if(gc_SystemStateMode==SYSTEM_STATE1_PLAYING)gb_ShowNowSongNumberFG=1; 
	gc_Busy_Timer=0; 
    gb_DisplayEvent_Happened=1;//lyh add 
    gw_DispFileName_ByteOffset=0;//lyh add 
	X_G_OverStep_DispArea=1;//lyh add 
//gc_TheSameLRC=0;//lyh add 
} 
//================================================================================================ 
void UI_Trigger_AutonDisplay()//set gb_ShowNowSongNumberFG=true;gb_DisplayEvent_Happened = false;gc_Busy_Timer = 64; 
{ 
	gb_ShowNowSongNumberFG=true; 
	gb_DisplayEvent_Happened = false; 
	gc_Busy_Timer = 64;             //eight seconds 
} 
//================================================================================================ 
//===============================THE UI_MENU_OPERATE FUNCTION================================================================= 
//================================================================================================ 
 
void UI_Menu_Operate(U8 TempEvent)//gb_ShowNowSongNumberFG = false;gb_DisplayEvent_Happened = false; 
{                                           //get the previous menu_state,tempevent,get the new state, 
	U8 TempState;                //then show related icon,change dsp,set some variables 
 
	U8 code StateChangeTable[][6]={ 
	//event FF           FR                   PLAY                Vol+                  Vol-                MODE         gc_Menu_State 
	S_Null,              S_Null,              S_Null,             S_Null,               S_Null,             S_Mode_Mu,//0 
	S_PMode,             S_Info,              S_Mode_Mu,          S_Null,               S_Null,             S_Null,//1  -->menu mode 
	S_Eq,                S_MMode,             S_PMode_NOREP,      S_Null,               S_Null,             S_Null,//2  -->menu play mode 
	S_Del,               S_PMode,             S_EQ_Norm,          S_Null,               S_Null,             S_Null,//3  -->menu EQ 
	S_Set,               S_Eq,                S_Del_One,          S_Null,               S_Null,             S_Null,//4  -->menu delete 
	S_Info,              S_Del,               S_Set_Backlit,      S_Null,               S_Null,             S_Null,//5  -->menu seetings 
	S_MMode,             S_Set,               S_Info_TotalMemory, S_Null,               S_Null,             S_Null,//6  -->menu Info	 
 
	S_Mode_Vo,           S_Mode_FM,			  S_Null,             S_PlayList_All,       S_Info_TotalMemory, S_Null,//7  -->mode music 
	S_Mode_FM,           S_Mode_Mu,           S_Null,             S_PlayList_All,       S_Info_TotalMemory, S_Null,//8  -->mode voice 
 
	S_PMode_REP1,        S_PMode_Intro,       S_Null,             S_EQ_Norm,            S_PlayList_All,          S_Null,//9  -->playmode no rep 
	S_PMode_REPA,        S_PMode_NOREP,       S_Null,             S_EQ_Norm,            S_PlayList_All,          S_Null,//10  -->playmode rep 1 
	S_PMode_Random,      S_PMode_REP1,        S_Null,             S_EQ_Norm,            S_PlayList_All,          S_Null,//11 -->playmode rep all 
	S_PMode_Intro,       S_PMode_REPA,        S_Null,             S_EQ_Norm,            S_PlayList_All,          S_Null,//12 -->playmode Random 
	S_PMode_NOREP,       S_PMode_Random,      S_Null,             S_EQ_Norm,            S_PlayList_All,          S_Null,//13 -->playmode Intro	 
 
 
//	S_PMode_REP1,        S_PMode_Intro,       S_Null,             S_EQ_Norm,            S_DSP_UNSURROUND,        S_Null,//9  -->playmode no rep 
//	S_PMode_REPA,        S_PMode_NOREP,       S_Null,             S_EQ_Norm,            S_DSP_UNSURROUND,        S_Null,//10  -->playmode rep 1 
//	S_PMode_Random,      S_PMode_REP1,        S_Null,             S_EQ_Norm,            S_DSP_UNSURROUND,        S_Null,//11 -->playmode rep all 
//	S_PMode_Intro,       S_PMode_REPA,        S_Null,             S_EQ_Norm,            S_DSP_UNSURROUND,        S_Null,//12 -->playmode Random 
//	S_PMode_NOREP,       S_PMode_Random,      S_Null,             S_EQ_Norm,            S_DSP_UNSURROUND,        S_Null,//13 -->playmode Intro	 
 
 
 
	S_EQ_DBB,            S_EQ_SURROUND,       S_Null,             S_VSP_Norm,           S_PMode_NOREP,      S_Null,//14  -->EQ normal 
	S_EQ_Jazz,           S_EQ_Norm,           S_Null,             S_VSP_Norm,           S_PMode_NOREP,      S_Null,//15  -->EQ dbb 
	S_EQ_Disc,           S_EQ_DBB,            S_Null,             S_VSP_Norm,           S_PMode_NOREP,      S_Null,//16  -->EQ jazz 
	S_EQ_POP,            S_EQ_Jazz,           S_Null,             S_VSP_Norm,           S_PMode_NOREP,      S_Null,//17  -->EQ disc 
	S_EQ_Clas,           S_EQ_Disc,           S_Null,             S_VSP_Norm,           S_PMode_NOREP,      S_Null,//18  -->EQ pop 
	S_EQ_SURROUND,       S_EQ_POP,            S_Null,             S_VSP_Norm,           S_PMode_NOREP,      S_Null,//19  -->EQ clas 
	S_EQ_Norm,           S_EQ_Clas,            S_Null,            S_VSP_Norm,           S_PMode_NOREP,      S_Null,//20  -->EQ SRS 
 
	S_VSP_Slow1,         S_VSP_Speed2,        S_Null,             S_Del_One,            S_EQ_Norm,          S_Null,//21  -->S_VSP_Norm 
	S_VSP_Slow2,         S_VSP_Norm,          S_Null,             S_Del_One,            S_EQ_Norm,          S_Null,//22  -->S_VSP_Slow1 
	S_VSP_Speed1,        S_VSP_Slow1,         S_Null,             S_Del_One,            S_EQ_Norm,          S_Null,//23  -->S_VSP_Slow2 
	S_VSP_Speed2,        S_VSP_Slow2,         S_Null,             S_Del_One,            S_EQ_Norm,          S_Null,//24  -->S_VSP_Speed1 
	S_VSP_Norm,          S_VSP_Speed1,        S_Null,             S_Del_One,            S_EQ_Norm,          S_Null,//25  -->S_VSP_Speed2 
 
	S_Set_Contrast,      S_Set_Default,       S_Set_Backlit,      S_Info_TotalMemory,   S_Del_One,          S_Null,//26  -->setting backlight 
	S_Set_Idletime,      S_Set_Backlit,       S_Set_Contrast,     S_Info_TotalMemory,   S_Del_One,          S_Null,//27  -->setting contrast 
	S_Set_Language,      S_Set_Contrast,      S_Set_Idletime,     S_Info_TotalMemory,   S_Del_One,          S_Null,//28  -->setting idle time 
	S_Set_Default,       S_Set_Idletime,      S_Set_Language,     S_Info_TotalMemory,   S_Del_One,          S_Null,//29  -->setting Current HZK 
	S_Set_Backlit,       S_Set_Language,      S_Null,             S_Info_TotalMemory,   S_Del_One,          S_Null,//30  -->setting default setting 
 
    S_Set_Backlit_20,    S_Set_Backlit_Off,   S_Null,             S_Set_Contrast_0,     S_Set_Language_ENG, S_Set_Backlit,//31 -->backlight 10 
	S_Set_Backlit_30,    S_Set_Backlit_10,    S_Null,             S_Set_Contrast_0,     S_Set_Language_ENG, S_Set_Backlit,//32 -->backlight 20 
	S_Set_Backlit_60,    S_Set_Backlit_20,    S_Null,             S_Set_Contrast_0,     S_Set_Language_ENG, S_Set_Backlit,//33 -->backlight 30 
	S_Set_Backlit_Prem,  S_Set_Backlit_30,    S_Null,             S_Set_Contrast_0,     S_Set_Language_ENG, S_Set_Backlit,//34 -->backlight 60 
	S_Set_Backlit_Off,   S_Set_Backlit_60,    S_Null,             S_Set_Contrast_0,     S_Set_Language_ENG, S_Set_Backlit,//35 -->backlight Prem 
	S_Set_Backlit_10,    S_Set_Backlit_Prem,  S_Null,             S_Set_Contrast_0,     S_Set_Language_ENG, S_Set_Backlit,//36 -->backlight Off 
 
	S_Set_Contrast_1,    S_Set_Contrast_9,    S_Null,             S_Set_Idletime_Off,   S_Set_Backlit_10,   S_Set_Contrast,//37 -->contrast 0 
	S_Set_Contrast_2,    S_Set_Contrast_0,    S_Null,             S_Set_Idletime_Off,   S_Set_Backlit_10,   S_Set_Contrast,//38 -->contrast 1 
	S_Set_Contrast_3,    S_Set_Contrast_1,    S_Null,             S_Set_Idletime_Off,   S_Set_Backlit_10,   S_Set_Contrast,//39 -->contrast 2 
	S_Set_Contrast_4,    S_Set_Contrast_2,    S_Null,             S_Set_Idletime_Off,   S_Set_Backlit_10,   S_Set_Contrast,//40 -->contrast 3 
	S_Set_Contrast_5,    S_Set_Contrast_3,    S_Null,             S_Set_Idletime_Off,   S_Set_Backlit_10,   S_Set_Contrast,//41 -->contrast 4 
	S_Set_Contrast_6,    S_Set_Contrast_4,    S_Null,             S_Set_Idletime_Off,   S_Set_Backlit_10,   S_Set_Contrast,//42 -->contrast 5 
	S_Set_Contrast_7,    S_Set_Contrast_5,    S_Null,             S_Set_Idletime_Off,   S_Set_Backlit_10,   S_Set_Contrast,//43 -->contrast 6 
	S_Set_Contrast_8,    S_Set_Contrast_6,    S_Null,             S_Set_Idletime_Off,   S_Set_Backlit_10,   S_Set_Contrast,//44 -->contrast 7 
	S_Set_Contrast_9,    S_Set_Contrast_7,    S_Null,             S_Set_Idletime_Off,   S_Set_Backlit_10,   S_Set_Contrast,//45 -->contrast 8 
	S_Set_Contrast_0,    S_Set_Contrast_8,    S_Null,             S_Set_Idletime_Off,   S_Set_Backlit_10,   S_Set_Contrast,//46 -->contrast 9 
 
	S_Set_Idletime_10,   S_Set_Idletime_Prem, S_Null,             S_Set_Language_ENG,   S_Set_Contrast_0,   S_Set_Idletime,//47 -->idle off 
	S_Set_Idletime_30,   S_Set_Idletime_Off,  S_Null,             S_Set_Language_ENG,   S_Set_Contrast_0,   S_Set_Idletime,//48 -->idle 3 
	S_Set_Idletime_60,   S_Set_Idletime_10,   S_Null,             S_Set_Language_ENG,   S_Set_Contrast_0,   S_Set_Idletime,//49 -->idle 5 
	S_Set_Idletime_Prem, S_Set_Idletime_30,   S_Null,             S_Set_Language_ENG,   S_Set_Contrast_0,   S_Set_Idletime,//50 -->idle 10 
	S_Set_Idletime_Off,  S_Set_Idletime_60,   S_Null,             S_Set_Language_ENG,   S_Set_Contrast_0,   S_Set_Idletime,//51 -->idle 30 
 
	S_Del_All,           S_Del_All,           S_Null,             S_Set_Backlit,        S_VSP_Norm,         S_Null,//52  -->del 1 
	S_Del_One,           S_Del_One,           S_Disk_FMTConfirm,  S_Set_Backlit,        S_VSP_Norm,         S_Null,//53  -->del all 
 
	S_Set_Language_CHN,  S_Set_Language_Ger,  S_Null,             S_Set_Backlit_10,     S_Set_Idletime_Off, S_Set_Language,//54 -->English HZK 
	S_Set_Language_BIG,  S_Set_Language_ENG,  S_Null,             S_Set_Backlit_10,     S_Set_Idletime_Off, S_Set_Language,//55 -->chinese HZK 
	S_Set_Language_JAP,  S_Set_Language_CHN,  S_Null,             S_Set_Backlit_10,     S_Set_Idletime_Off, S_Set_Language,//56 -->BIG HZK 
	S_Set_Language_Ger,  S_Set_Language_BIG,  S_Null,             S_Set_Backlit_10,     S_Set_Idletime_Off, S_Set_Language,//57 -->JAP HZK 
	S_Set_Language_ENG,  S_Set_Language_JAP,  S_Null,             S_Set_Backlit_10,     S_Set_Idletime_Off, S_Set_Language,//58 -->GER HZK 
 
	S_Info_FreeMemory,   S_Info_FWVersion,    S_Disp_TotalMemory, S_Mode_Mu,            S_Set_Backlit,      S_Null,//59--->Info total memory 
	S_Info_FWVersion,    S_Info_TotalMemory,  S_Disp_FreeMemory,  S_Mode_Mu,            S_Set_Backlit,      S_Null,//60--->Info free memory 
	S_Info_TotalMemory,  S_Info_FreeMemory,   S_Disp_FWVersion,   S_Mode_Mu,            S_Set_Backlit,      S_Null,//61--->Info f/w version 
 
	S_Disk_FMTCancel,    S_Disk_FMTCancel,    S_Null,             S_Disk_FMTConfirm,    S_Disk_FMTConfirm,  S_Del_All,//62--->format confirm 
	S_Disk_FMTConfirm,   S_Disk_FMTConfirm,   S_Null,             S_Disk_FMTCancel,     S_Disk_FMTCancel,   S_Del_All,//63--->format cancel 
 
	S_Mode_Mu,           S_Mode_FM,           S_Mode_Record,      S_PMode_NOREP,        S_Info_TotalMemory, S_Null,//64  -->mode record 
	S_Select_RecWave,    S_Select_RecWave,    S_Null,             S_Select_RecASF,      S_Select_RecASF,    S_Mode_Record,//65-->record WAV 
	S_Select_RecASF,     S_Select_RecASF,     S_Null,             S_Select_RecWave,     S_Select_RecWave,   S_Mode_Record,//66-->record ASF 
 
	S_Null,   	         S_Null,              S_Null,             S_Null,               S_Null,             S_Info_TotalMemory,//67--->DispInfo total memory 
	S_Null,  	         S_Null,              S_Null,             S_Null,               S_Null,             S_Info_FreeMemory,//68--->DispInfo free memory 
	S_Null,  	         S_Null,              S_Null,             S_Null,               S_Null,             S_Info_FWVersion,//69--->DispInfo f/w version 
	 
	S_PlayList_Favorite, S_PlayList_Favorite, S_Null,             S_PMode_NOREP,        S_Mode_Mu,          S_Null,  //70--->Playlist all. 
	S_PlayList_All,      S_PlayList_All,      S_Null,             S_PMode_NOREP,        S_Mode_Mu,          S_Null,  //71--->Playlist favorite. 
 
//	S_PlayList_Favorite, S_PlayList_Favorite, S_Null,             S_DSP_UNSURROUND,        S_Mode_Mu,          S_Null,  //70--->Playlist all. 
//	S_PlayList_All,      S_PlayList_All,      S_Null,             S_DSP_UNSURROUND,        S_Mode_Mu,          S_Null,  //71--->Playlist favorite. 
 
 
	S_Mode_Mu,       	 S_Mode_Vo,           S_FM_BackMode,      S_PMode_NOREP,        S_Info_TotalMemory, S_Null,//72-->mode FM. 
 
	S_FM_AutoSearch,     S_FM_Sensitivity,    S_Mode_FM,          S_FM_BackMode,        S_FM_BackMode,      S_Null,//73-->S_FM_BackMode 
	S_FM_ManualSearch,   S_FM_BackMode,       S_Null,             S_FM_AutoSearch,      S_FM_AutoSearch,    S_Null,//74-->S_FM_AutoSearch 
	S_FM_PresetSearch,   S_FM_AutoSearch,     S_Null,             S_FM_ManualSearch,    S_FM_ManualSearch,  S_Null,//75-->S_FM_ManualSearch 
	S_FM_Channel,        S_FM_ManualSearch,   S_Null,             S_FM_PresetSearch,    S_FM_PresetSearch,  S_Null,//76-->S_FM_PresetSearch 
	S_FM_Sensitivity,    S_FM_PresetSearch,   S_FM_Stereo,        S_FM_Channel,         S_FM_Channel,       S_Null,//77-->S_FM_Channel 
	S_FM_Mono,           S_FM_Mono,           S_Null,             S_FM_Stereo,          S_FM_Stereo,        S_FM_Channel,//78-->S_FM_Stereo 
	S_FM_Stereo,         S_FM_Stereo,         S_Null,             S_FM_Mono,            S_FM_Mono,          S_FM_Channel,//79-->S_FM_Mono 
	S_FM_BackMode,       S_FM_Channel,        S_FM_Sensitivity_Hi,S_FM_Sensitivity,     S_FM_Sensitivity,   S_Null,//80-->S_FM_Sensitivity 
	S_FM_Sensitivity_Low,S_FM_Sensitivity_Low,S_Null,             S_FM_Sensitivity_Hi,  S_FM_Sensitivity_Hi,S_FM_Sensitivity,//81-->S_FM_Sensitivity_Hi 
	S_FM_Sensitivity_Hi, S_FM_Sensitivity_Hi, S_Null,             S_FM_Sensitivity_Low, S_FM_Sensitivity_Low,S_FM_Sensitivity,//82-->S_FM_Sensitivity_Low 
 
//	S_DSP_UNSURROUND,    S_DSP_UNSURROUND,    S_Null,             S_PMode_NOREP,        S_PlayList_All,     S_Null,//83-->mode FM. 
//	S_DSP_SURROUND,      S_DSP_SURROUND,      S_Null,             S_PMode_NOREP,        S_PlayList_All,     S_Null,//84-->mode FM. 
     
 
	}; 
 
    //this is a statue change form,the right is the statue of the menu,when  
	{ 
		gw_DispFileName_ByteOffset=0;//lyh add 
		if(TempEvent>5) return; 
		if(TempEvent==2)//play key<=>mode key//in the multimenu.... 
		{ 
			TempEvent=5; 
		}else{ 
			if(TempEvent==5) 
				TempEvent=2; 
		} 
		TempState = gc_Menu_State;//0->mu,mu->vo 
		if(TempState==0) 
		{ 
			gc_Menu_State=S_Mode_Mu+gc_UIMode;//differ the statue is mode--music7 or voice8 
		}else{		 
			gc_Menu_State = StateChangeTable[TempState][TempEvent]; 
		} 
         
	} 
 
	switch(TempEvent) 
	{ 
	case 2://SETTING 
		if(TempState==S_Del) 
		{ 
			Playing_To_Stop(); 
		}else if(TempState==S_Info_TotalMemory) 
		{ 
			 
			//USER_Get_SYSInformation(1); 
			LCD501_Disp_TotalMemory();//get the memory,will call USER_Get_SYSInformation(1); 
//			gc_SystemStateMode=STATE_MemoryInfo; 
//			gc_Busy_Timer = 0; 
			UI_Trigger_AutonDisplay(); 
			return; 
		}else if(TempState==S_Info_FreeMemory)//will stop to play,then show the freememory 
		{ 
			if(!gc_DOS_ErrorStatus && (gdw_Dos_FreeMemorySizeMB==0xffffffff))//xyq 040614 add 
			{ 
				if(gc_SystemStateMode==SYSTEM_STATE1_PLAYING) 
				{ 
					Playing_To_Stop(); 
				} 
//				Main_Get_FreeMemory();//how to get the memory 
 
			} 
            Main_Get_FreeMemory(); 
//printf("gc_DOS_ErrorStatus=%bu\n",gc_DOS_ErrorStatus); 
//printf("get the freememory!\n"); 
/////////////need to know how to get the size of free memory????????????????????????????? 
			LCD501_Disp_FreeMemory();//total memory info 
//			gc_SystemStateMode=STATE_MemoryInfo; 
//			gc_Busy_Timer = 0; 
			UI_Trigger_AutonDisplay(); 
			return; 
		}else if(TempState==S_Info_FWVersion) 
		{ 
			LCD501_Disp_FWVersion();//total memory info 
//			gc_SystemStateMode=STATE_MemoryInfo; 
//			gc_Busy_Timer = 0; 
			UI_Trigger_AutonDisplay(); 
			return; 
		}else if(TempState==S_Mode_Mu || TempState==S_Mode_Vo)//if different,stop ,then idle_state;else,then search the file 
		{ 
			if(TempState==S_Mode_Mu) 
			{ 
				if(gc_SystemStateMode==SYSTEM_STATE1_PLAYING||gc_SystemStateMode==SYSTEM_STATE0_IDLE) 
				{ 
					if(gc_UIMode)//when playing DVR,stop it 
					{ 
						Playing_To_Stop(); 
					}else{ 
						goto DispFileName; 
					} 
				} 
			} 
			if(TempState==S_Mode_Vo) 
			{ 
				if(gc_SystemStateMode==SYSTEM_STATE1_PLAYING||gc_SystemStateMode==SYSTEM_STATE0_IDLE) 
				{ 
					if(!gc_UIMode)//when playing MP3,stop it 
					{ 
						Playing_To_Stop(); 
					}else{ 
						goto DispFileName; 
					} 
				} 
			} 
              //matched     
			gc_UIMode=TempState-S_Mode_Mu; 
 
//			if(gc_UIMode==0x00)//can reduce code size(xyq040213) 
//			{//--->MP3 
//			 
//			}else{//--->DVRD 
//				gc_PlayMode=0;		 
//			} 
			gw_FileIndex[gc_UIMode] = 0; 
			gbt_FindFlag = 0;	 
			if(gc_UIMode == 1)//DSP DVR decode mode 
			{	 
								 
				DOS_Search_File(0x12,1,0x10);//FF 
			}else{ 
				DOS_Search_File(0x01,0,0x10);//FF 
			} 				 
            //System_NextOrPrev(0, 1, gc_UIMode);//lyh add 
			gc_Busy_Timer = 0; 
			UI_idle_Display();//xyq031120 
		//	printf("flash1\n"); 
			return; 
		}else if(TempState>=S_PMode_NOREP && TempState<=S_PMode_Intro) 
		{ 
			gc_PlaySequenceMode=TempState-S_PMode_NOREP;//0:(no repeat); 1:(repeat 1); 2:(repeat All);3:(random);4:(intro 10) 
			LCD501_Disp_REP1ALL(gc_PlaySequenceMode); 
			gb_UI_UserSeeting_Changed=1;//changed 
			goto DispFileName; 
		}else if(TempState>=S_EQ_Norm && TempState<=S_EQ_SURROUND) 
		{//11:EQ normal 12://EQ dbb 13://EQ jazz 14://EQ disc 15://EQ pop 16://EQ clas 
			 
			gc_PlayEQMode=TempState-S_EQ_Norm; 
			//printf("mode=%bx\n",gc_PlayEQMode); 
			if(gc_SystemStateMode==SYSTEM_STATE1_PLAYING) 
				System_SetEQ(gc_PlayEQMode);//set dsp first 
			LCD501_Disp_DSPEQ(gc_PlayEQMode);//show the bmp in the lcd 
 
			gb_UI_UserSeeting_Changed=1; 
			goto DispFileName; 
		}else if(TempState>=S_Set_Backlit_10 && TempState<=S_Set_Backlit_Off) 
		{//backlight 
			gc_UserBacklightLevel=TempState-S_Set_Backlit_10; 
		 
			if(gc_UserBacklightLevel<5) 
			{ 
				gc_BacklightCount = UserBackLightArray[gc_UserBacklightLevel];//the value 
//				BackLightOn;//turn on back light 
			}else{ 
//				BackLightOff;//turn off back light 
			} 
			gb_UI_UserSeeting_Changed=1; 
			goto DispFileName; 
		}else if(TempState>=S_Set_Contrast_0 && TempState<=S_Set_Contrast_9) 
		{ 
			goto DispFileName; 
		}else if(TempState>=S_Set_Idletime_Off && TempState<=S_Set_Idletime_Prem) 
		{//idle time 
			gc_USR_PowerOffCount=TempState-S_Set_Idletime_Off; 
			gw_PowerOffTimer = USER_SetIdleTime[gc_USR_PowerOffCount];//get the value 
			gb_UI_UserSeeting_Changed=1; 
			goto DispFileName; 
		}else if(TempState==S_Set_Default) 
		{ 
			X_Get_DefaultUserValue();//set the dsp volume and some application's variable(global) 
			LCD501_Adjust_Contrast(2); 
			gc_DSP_Volume = 21+3; 
//			G_DSP_RECVolume=39+3; 
            System_SetVolume(gc_DSP_Volume); 
/*			if(gc_SystemStateMode=S_PlayList_All && TempState<=S_PlayList_Favorite) 
		{			 
/*			if(gc_PlayMode!=(TempState-S_PlayList_All)) 
			{				 
				if((gc_SystemStateMode==SYSTEM_STATE1_PLAYING) || (gc_SystemStateMode==STATE_RECORD)) 
				{					 
					Playing_To_Stop();										 
				} 
				if(gc_UIMode!=0) 
				{ 
					gc_UIMode=0; 
//					GS_SearchMode=0; 
//					G_DSPPrimeMODE = KDSP_MP3_MODE; 
										 
				} 
/*				DOS_ReadSector(gs_File_FCB[gc_UIMode].dw_FDB_LogAdd);//store the fdb's logadd,find the sector 
				if(USR_IsMp3Ext(&G_ucStorData[gs_File_FCB[gc_UIMode].FDB_Offset])) 
				{ 
					GS_FileType=0; 
				} 
				else 
				{ 
					GS_FileType=1; 
				} 
*///what the meaning of these codes 
/*				gs_File_FCB[gc_UIMode].dw_FDB_LogAdd=0;//GS_PlayFile_SectorLogAdd=0;//hxd030620 add... 
				if (GS_SearchMode==1) 
				{ 
					DOS_Search_File(0x10,gc_UIMode,2); 
				} 
				if (gw_FileTotalNumber[gc_UIMode]) 
				{ 
					DOS_Search_File(0x10,gc_UIMode,0); 
				}else{ 
					gw_FileIndex[gc_UIMode]=0;					 
				}																 
			}												 
			gc_PlayMode=TempState-S_PlayList_All; 
/*			if((gc_PlayMode==PLAY_FAVORITE) && (gc_SystemStateMode!=SYSTEM_STATE1_PLAYING)) 
			{				 
				UI_GetPlayListInfo(); 
			} 
*///haven't playlist module,so delete related codes! 
/*			gc_Busy_Timer = 0; 
			if(gc_SystemStateMode!=SYSTEM_STATE1_PLAYING) 
			{ 
				UI_idle_Display();			 
			} 
			gb_UI_UserSeeting_Changed=1; 
*/		//	return; 
			break; 
			//goto DispFileName; 
		}else if( TempState>=S_Set_Language_ENG && TempState<=S_Set_Language_Ger) 
		{ 
			G_CurrentHZK=TempState - S_Set_Language_ENG; 
			gc_MenuHZK = gc_CurrentHZKMapMenuHZK[G_CurrentHZK];//the language of the menu 
			UI_Close_File(); 
			if(gc_SystemStateMode==SYSTEM_STATE1_PLAYING) 
			{ 
				gc_SystemStateMode=SYSTEM_STATE1_PLAYING;//will stop the playing song ,and start it again 
				gb_Openfile = TRUE; // Make Openfile post-processor activity 
			} 
			UI_GET_ID3INFO(gc_FileLongName); 
			gb_UI_UserSeeting_Changed=1; 
			goto DispFileName; 
		} 
		//=========end EQ=====================================*/ 
		//=========language=================================== 
		if(gc_Menu_State==S_Set_Language) 
		{ 
			gc_Menu_State=S_Set_Language_ENG+G_CurrentHZK; 
		}else 
		//=========end language=============================== 
		//=========backlight================================== 
		if(gc_Menu_State==S_Set_Backlit) 
		{ 
		 
			gc_Menu_State=S_Set_Backlit_10+gc_UserBacklightLevel; 
			//gc_Menu_State = S_Set_Backlit_10; 
			//printf("gc_Menu_State=%bx\n",gc_Menu_State); 
		}else 
		//=========end backlight=============================== 
		//=========idletime================================== 
		if(gc_Menu_State==S_Set_Idletime) 
		{ 
			gc_Menu_State=S_Set_Idletime_Off+gc_USR_PowerOffCount; 
		}else 
		//=========end idletime=============================== 
	    //=========contrast==================================== 
		if(gc_Menu_State==S_Set_Contrast) 
		{ 
			gc_Menu_State=S_Set_Contrast_0+G_Current_Contrast; 
		}else 
		//==========mode record================================ 
		if(gc_Menu_State==S_Mode_Record) 
		{ 
			if(!gc_DVRE_Mode_Selected)//xyq040207 
			{ 
				gc_Menu_State=S_Select_RecASF; 
			}else{ 
				gc_Menu_State=S_Select_RecWave; 
			} 
		}else 
		//==========Record WAV or ASF file===================== 
		if(TempState==S_Select_RecASF || TempState==S_Select_RecWave)//xyq040207 
		{ 
			if(TempState==S_Select_RecASF) 
			{ 
				gc_DVRE_Mode_Selected=0; 
				//G_DSPMinorMODE=KDVR_ADPCM_4bit; 
				_G723=FALSE; 
			}else{ 
				gc_DVRE_Mode_Selected=1; 
				//G_DSPMinorMODE=KDVR_G723_5K; 
				_G723=TRUE; 
			} 
			goto DispFileName; 
		} 
		break; 
	case 3://Volume + 
	case 4://Volume - 
 
		if(_WMA)//WMA no digital speed control 
		{ 
			if(TempState>=S_EQ_Norm && TempState<=S_EQ_Clas && TempEvent==3) 
			{ 
				gc_Menu_State=S_Del_One; 
			} 
			if((TempState==S_Del_One || TempState==S_Del_All) &&TempEvent==4) 
			{ 
				gc_Menu_State=S_EQ_Norm; 
			} 
		} 
		if(gc_UIMode)//when DVR mode,No EQ menu 
		{ 
			if(TempState>=S_PMode_NOREP && TempState<=S_PMode_Intro && TempEvent==3) 
			{ 
				gc_Menu_State=S_VSP_Norm; 
			} 
			if((TempState>=S_VSP_Norm && TempState<=S_VSP_Speed2) &&TempEvent==4) 
			{ 
				gc_Menu_State=S_PMode_NOREP; 
			} 
		} 
		//=========op mode==================================== 
		if(gc_Menu_State==S_Mode_Mu) 
		{ 
			gc_Menu_State=S_Mode_Mu+gc_UIMode; 
		} 
		//=========play mode================================== 
		if(gc_Menu_State==S_PMode_NOREP) 
		{ 
			gc_Menu_State=S_PMode_NOREP+gc_PlaySequenceMode; 
		}else 
		//=========end play mode============================== 
		//=========EQ========================================= 
		if(gc_Menu_State==S_EQ_Norm) 
		{ 
			gc_Menu_State=S_EQ_Norm+gc_PlayEQMode; 
		}else 
		//=========end EQ=====================================*/ 
		//=========language=================================== 
		if(gc_Menu_State==S_Set_Language_ENG) 
		{ 
			gc_Menu_State=S_Set_Language_ENG+G_CurrentHZK; 
		}else 
		//=========end language=============================== 
		//=========backlight================================== 
		if(gc_Menu_State==S_Set_Backlit_10) 
		{ 
			gc_Menu_State=S_Set_Backlit_10+gc_UserBacklightLevel; 
		}else 
		//=========end backlight=============================== 
		//=========idletime================================== 
		if(gc_Menu_State==S_Set_Idletime_Off) 
		{ 
			gc_Menu_State=S_Set_Idletime_Off+gc_USR_PowerOffCount; 
		}else 
		//=========end idletime=============================== 
	    	//=========contrast==================================== 
		if(gc_Menu_State==S_Set_Contrast_0) 
		{ 
			gc_Menu_State=S_Set_Contrast_0+G_Current_Contrast; 
		}else 
		//=========end contrast==================================== 
		//=========playlist================================== 
		if(gc_Menu_State==S_PlayList_All) 
		{ 
			gc_Menu_State=S_PlayList_All+gc_PlayMode; 
		} 
		//=========end playlist=============================== 
		break; 
//	case 5: 
//		if(TempState==S_Info_Memory) 
//		{ 
//			UI_Disp_Page0(); 
//		} 
//		break; 
	}//end switch();&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
 
	//=========Start DVR Encode mode select================= 
	if(TempState==S_Select_RecASF || TempState==S_Select_RecWave)//xyq040207 
	{ 
		if(TempState==S_Select_RecASF) 
		{ 
			gc_DVRE_Mode_Selected=0; 
		}else{ 
			gc_DVRE_Mode_Selected=1; 
		} 
	} 
	//=========End DVR Encode mode select==================== 
 
	//=========Start contrast================================= 
	if(TempState>=S_Set_Contrast_0 && TempState<=S_Set_Contrast_9) 
	{ 
		if(TempEvent<2) 
		{ 
			G_Current_Contrast=gc_Menu_State-S_Set_Contrast_0; 
			gb_UI_UserSeeting_Changed=1; 
		} 
		LCD501_Adjust_Contrast(G_Current_Contrast); 
	} 
	//=========end contrast================================= 
 
	//=========Start EQ================================= 
	if((gc_SystemStateMode==SYSTEM_STATE1_PLAYING) && (!gc_UIMode))//will change the dsp mode 
	{ 
		if(gc_Menu_State>=S_EQ_Norm && gc_Menu_State<=S_EQ_SURROUND) 
		{ 
			//printf("menu=%bx\n",gc_Menu_State); 
			System_SetEQ(gc_Menu_State-S_EQ_Norm); 
		}else{ 
			System_SetEQ(gc_PlayEQMode); 
		} 
	} 
	//=========End EQ================================= 
   
	if(_WMA==0) 
	if(gc_Menu_State>=S_VSP_Norm && gc_Menu_State<=S_VSP_Speed2) 
	{ 
		gc_PLAY_DPC=USER_Set_Play_DPC_Value[gc_Menu_State-S_VSP_Norm];//get the value 
 
        
		if(gc_SystemStateMode==SYSTEM_STATE1_PLAYING) 
		{ 
			System_SetPlayDPC(gc_PLAY_DPC);//will change the dsp value 
		} 
	} 
 
	if(gc_Menu_State==S_Null) goto DispFileName; 
	//if(gc_Menu_State!=S_Info_Memory) 
	{ 
		//printf("disp icon menu\n"); 
 
		LCD501_Disp_IconMenu(gc_Menu_State); 
	} 
//printf("refresh!\n"); 
	UI_Trigger_AutonDisplay(); 
	return; 
DispFileName: 
 
//printf("DispFileName\n"); 
	if(gc_SystemStateModegc_fileend 
                gb_PlayPause = FALSE; 
				gc_AB_Cnt=0;		 
 
			}//if(gw_FileTotalNumber[gc_UIMode]) 
			else 
			{ 
				gc_SystemStateMode=SYSTEM_STATE0_IDLE; 
				return; 
			} 
//printf("gc_Play_Pause_Stop_State=%bu\n",gc_Play_Pause_Stop_State); 
			gc_Play_Pause_Stop_State=0; 
            X_G_OverStep_DispArea=1;//2005-2-3 
            gw_DispFileName_ByteOffset=0;//2005-2-3 
			LCD501_Playing_Pause_Stop_Record(0); 
	  }//if(gc_SystemStateMode==SYSTEM_STATE1_PLAYING) 
 
		// initial UI's indication in LCD and LED 
		G_W_OldTime=0;   
		G_DISPLAY_TotalSec=0; 
		G_Currtotalsecond=0;      
		gb_FastFFFR=FALSE; 
		LCD501_Disp_ABPoint(0); 
		LCD501_Disp_HHMMSS(0); 
//printf("gc_SystemStateMode=%bu\n",gc_SystemStateMode); 
//		gc_FileNameRollTimer=8;//2005-2-3 
		gc_Busy_Timer = 0; 
//for(k=0;k<=100;k++) 
        USER_DelayDTms(10);				// Delay 10mS for de-bounce 
 
	}//end if(gb_Openfile) 
} 
//================================================================================================ 
//===========================================AudioCodec=========================================== 
//================================================================================================ 
void Audio_CoDec(void)//lyh add 
{ 
	U8 i;//U16 liyonghua; 
	if(gb_UIPostError)  // UI post-processor error happen !! 
	{ 
		i=gb_UIPostError; 
		//printf("now,it gb_UIPostError=%bu\n",i); 
		//System_Stop();//lyh add 
		// reset the state to IDLE state -- 
		gb_UIPostError = FALSE;     // reset the error flag 
		if(gc_SystemStateMode==SYSTEM_STATE1_PLAYING) 
		{ 
			if(gc_PlaySequenceMode == 0x01) 
			{//repeat one 
				//==initialize parameters==// 
				gc_SystemStateMode=SYSTEM_STATE0_IDLE; 
			}else{ //hxd~~//repeat all and no repeat 
					if (gw_FileIndex[gc_UIMode]==gw_FileTotalNumber[gc_UIMode])   //hxd030620 modify 
					   { 
                        gc_PeriphStep = PERIPH_IDLE;  
                        gbt_FindFlag = 0;//lyh add 
						gc_SystemStateMode=SYSTEM_STATE0_IDLE;//error happern,goto idle state 
						DOS_Search_File(0x01,gc_UIMode,0x10);  //hxd030620 add 
					   } 
                   else{ 
                        gbt_FindFlag = 0;//lyh add 
						gb_Openfile = TRUE; // Make Openfile post-processor activity 
						DOS_Search_File(0x01,gc_UIMode,0x10);  //hxd030620 add 
					   } 
			     } 
		} 
		else if(gc_SystemStateMode==STATE_RECORD) 
		{ 
			gc_UIMode=0x01; //return DVRD mode 
            //gbt_FindFlag = 0;//lyh add 
 
            //gs_File_FCB[1].dw_FDB_StartCluster = gdw_USER_DirClus[0]; 
			//if (gw_FileTotalNumber[gc_UIMode]) 
		//	{ 
           //    gbt_FindFlag = 0;//lyh add 
		//		DOS_Search_File(0x12,gc_UIMode,0x11);//go ahead to search record file. 
			//} 
			if(gb_Storage_Full) 
			{ 
                //gc_PeriphStep = PERIPH_IDLE; 
				LCD501_Disp_Full(); 
				gc_SystemStateMode=STATE_FLASHFULL_OR_LOWBATT; 
			}else{ 
				gc_SystemStateMode=SYSTEM_STATE0_IDLE; 
			} 
		}//end recordstate 
		return; 
	}//end if(gb_UIPostError) 
	//printf("mode=%bx\n",gc_SystemStateMode); 
	if(gc_SystemStateMode==SYSTEM_STATE1_PLAYING) 
	{//1 in the normal state 
//		U8 /*sts*/isnext=0; 
		//printf("end=%bx\n",gc_fileend); 
		if(!gc_fileend) 
		{//A             
/*			if((gc_AB_Cnt==2)) //&& (G_sectorNUM >= G_BSectorNUM))lyh del 
			{ 
                System_SetRepeatAB(3); 
			} 
*/ 
//printf("gc_fileend1=%bu\n",gc_fileend); 
		    if(gb_PlayPause) 
			{ 
				gc_SystemStateMode=STATE_PLAY_PAUSE; 
			}//lyh add,there is someting question ,not sure the state is changed in the function or here! 
            else 
			{ 
				gc_fileend = CODEC_MCU_TO_DSP(); 
	   		} 
            if(gc_PlaySequenceMode == 0x04) 
			{//浏览播放 
				if(UI_GetDispTimeFromDispBuf()>4) 
				{ 
					System_Stop(); 
					gc_fileend=1; 
				} 
			}		 
 
		} //A end if(!gc_fileend) 
		else 
		{//End of File for play		 
			{//wait DSP decode end 
				if(gc_PlayMode==PLAY_FAVORITE) 
				{//play list 
				} 
				else 
				{ 
					if(gc_PlaySequenceMode == 0x01) //repeat one, 
					{ 
						gb_Openfile = TRUE; // Make Openfile post-processor activity 
					}else if(gc_PlaySequenceMode == 0x03)//random 
					{ 
						X_RandomGetFileIndex(); 
						gb_Openfile = TRUE; // Make Openfile post-processor activity 
					}else{//q 
					       if (gw_FileIndex[gc_UIMode]==gw_FileTotalNumber[gc_UIMode])   //hxd030620 modify 
					    	{ 
	//printf("the last song!\n"); 
							   if(gc_PlaySequenceMode == 0x02) //repeat all, 
							    { 
	//printf("repeat all file\n"); 
								  gb_Openfile = TRUE; // Make Openfile post-processor activity 
	 
	                              System_NextOrPrev(0, 1, gc_UIMode); 
							    } 
							 	else    // Mode=0 , Single play,  stop play right now! 
							    { 
								  //G_Power_Off_Timer=USER_SetIdleTime[G_USR_PowerOffCount]; 
								  gb_DisplayEvent_Happened=1; 
								  gc_Play_Pause_Stop_State = 2; 
								  gc_SystemStateMode=SYSTEM_STATE0_IDLE; 
								  System_Stop();//must call system_stop() here 
							    } 
						    } 
					    else{ 
	//printf("to find the next song!\n"); 
						        gb_Openfile = TRUE; // Make Openfile post-processor activity 
	                            System_NextOrPrev(0, 1, gc_UIMode); 
						    } 
	//printf( 
					     }//q 
				   }//not PLAY_FAVORITE 
	           if(gc_UIMode==0) 
	           { 
		       i=Dos_GetFileLongName(0,NULL,gc_FileLongName); 
		       gc_LrcFileName_Exist=LRCName_IsExist();     //检查同步歌词是否存在 
			   UI_GetMusicInfo(); 
	           for(i=0;i=5999)//no hour display, so when record to 99 minute,record next file 
			{ 
				_G_RecordNextFile=1; 
				gc_fileend = TRUE; 
			}else{ 
				_G_RecordNextFile=0; 
			} 
 
		}//2B 
		else 
		{//2B 
//stoprecord: 
            gc_PeriphStep = PERIPH_IDLE;  
            System_Stop();//stop to record! lyh add 
			gc_EVENT=0; 
			gc_UIMode=0x01; //return DVRD mode 
			if(gb_Storage_Full) 
			{ 
				///printf("storage full\n"); 
				LCD501_Disp_Full(); 
				gc_SystemStateMode=STATE_FLASHFULL_OR_LOWBATT; 
			}else{ 
				if(_G_RecordNextFile==1) 
				{ 
//lyh del now					gc_UIMode=0x02;//??????????????why 0x02????????????????????????????? 
					gb_Openfile = TRUE; // Make Openfile post-processor activity 
				}else{ 
					gb_DisplayEvent_Happened=1; 
					if(gb_LowBattery_StopRecord) 
					{ 
						LCD501_Disp_LowBattery(); 
						gc_SystemStateMode=STATE_FLASHFULL_OR_LOWBATT;// 
					}else{ 
						gc_SystemStateMode=SYSTEM_STATE0_IDLE; 
					} 
				} 
			} 
		}//2B 
	}//2 
} 
//================================================================================================ 
 
void X_RandomGetFileIndex(void) 
{ 
	data unsigned int Num; 
	 
	Num=TH0; 
	Num<<=4; 
	Num=Num+TL0; 
	Num=(Num%gw_FileTotalNumber[gc_UIMode])+1;//G_USR_DirList[gc_UIMode].totalFile)+1; 
	 
	if(gw_FileIndex[gc_UIMode]==Num) 
	{ 
		System_NextOrPrev(0,1,gc_UIMode);	 
	} 
	else 
	{ 
		if (gw_FileIndex[gc_UIMode] > Num) 
		{ 
			System_NextOrPrev(1,(gw_FileIndex[gc_UIMode] - Num),gc_UIMode); 
		} 
		else 
		{ 
			System_NextOrPrev(0,(Num - gw_FileIndex[gc_UIMode]),gc_UIMode); 
		} 
	} 
} 
 
 
//****************************注意:以下函数必须保留,用户不能删除以下函数**************************************** 
//**************************************DEL BY LYH******************************************************** 
//------------------------------------------------------------------------------- 
 
 
 
 
//****************************注意:以下函数必须保留,用户不能删除以下函数********************** 
//********************************************************************************************** 
//------------------------------------------------------------------------------- 
void USER_FillSettingInfo(void) 
{ 
	gc_PlayRecordDataBuf[0] = gc_DSP_Volume; 
	gc_PlayRecordDataBuf[1] = gc_PlayEQMode; 
	gc_PlayRecordDataBuf[2] = G_CurrentHZK; 
 
	gc_PlayRecordDataBuf[3] = gc_UI_ABStateMode; 
	gc_PlayRecordDataBuf[4] = gc_UI_CurrSecond; 
 
	 
	gc_PlayRecordDataBuf[5] = ((U8 *)(&gdw_UI_ADataPoint))[0]; 
	gc_PlayRecordDataBuf[6] = ((U8 *)(&gdw_UI_ADataPoint))[1]; 
	gc_PlayRecordDataBuf[7] = ((U8 *)(&gdw_UI_ADataPoint))[2]; 
	gc_PlayRecordDataBuf[8] = ((U8 *)(&gdw_UI_ADataPoint))[3]; 
	gc_PlayRecordDataBuf[9] = ((U8 *)(&gdw_UI_BDataPoint))[0]; 
	gc_PlayRecordDataBuf[10] = ((U8 *)(&gdw_UI_BDataPoint))[1]; 
	gc_PlayRecordDataBuf[11] = ((U8 *)(&gdw_UI_BDataPoint))[2]; 
	gc_PlayRecordDataBuf[12] = ((U8 *)(&gdw_UI_BDataPoint))[3]; 
 
	gc_PlayRecordDataBuf[13] = ((U8 *)(&gdw_UI_AFrameCnt))[0]; 
	gc_PlayRecordDataBuf[14] = ((U8 *)(&gdw_UI_AFrameCnt))[1]; 
	gc_PlayRecordDataBuf[15] = ((U8 *)(&gdw_UI_AFrameCnt))[2]; 
	gc_PlayRecordDataBuf[16] = ((U8 *)(&gdw_UI_AFrameCnt))[3]; 
	gc_PlayRecordDataBuf[17] = gc_UserBacklightLevel;//lixt 
} 
//------------------------------------------------------------------------------- 
//------------------------------------------------------------------------------- 
void USER_GetSettingInfo(void) 
{ 
	gc_DSP_Volume = ((gc_PlayRecordDataBuf[0]%64)/3)*3; 
	gc_PlayEQMode = gc_PlayRecordDataBuf[1]%6; 
	G_CurrentHZK = gc_PlayRecordDataBuf[2]%5; 
 
	gc_UI_ABStateMode = gc_PlayRecordDataBuf[3]; 
	gc_UI_CurrSecond= gc_PlayRecordDataBuf[4]; 
 
	((U8 *)(&gdw_UI_ADataPoint))[0]= gc_PlayRecordDataBuf[5]; 
	((U8 *)(&gdw_UI_ADataPoint))[1]= gc_PlayRecordDataBuf[6]; 
	((U8 *)(&gdw_UI_ADataPoint))[2]= gc_PlayRecordDataBuf[7]; 
	((U8 *)(&gdw_UI_ADataPoint))[3]= gc_PlayRecordDataBuf[8]; 
	((U8 *)(&gdw_UI_BDataPoint))[0]= gc_PlayRecordDataBuf[9]; 
	((U8 *)(&gdw_UI_BDataPoint))[1]= gc_PlayRecordDataBuf[10]; 
	((U8 *)(&gdw_UI_BDataPoint))[2]= gc_PlayRecordDataBuf[11]; 
	((U8 *)(&gdw_UI_BDataPoint))[3]= gc_PlayRecordDataBuf[12]; 
	 
	((U8 *)(&gdw_UI_AFrameCnt))[0]= gc_PlayRecordDataBuf[13]; 
	((U8 *)(&gdw_UI_AFrameCnt))[1]= gc_PlayRecordDataBuf[14]; 
	((U8 *)(&gdw_UI_AFrameCnt))[2]= gc_PlayRecordDataBuf[15]; 
	((U8 *)(&gdw_UI_AFrameCnt))[3]= gc_PlayRecordDataBuf[16]; 
	gc_UserBacklightLevel = gc_PlayRecordDataBuf[17];//lixt 
 
 
} 
 
//------------------------------------------------------------------------------ 
//------------------------------------------------------------------------------- 
//==================================================================================================================== 
void X_Get_DefaultUserValue(void) 
{ 
	//get default value 
	gc_DSP_Volume = 21; 
 
	gc_PlayEQMode = 0;//normal 
	G_CurrentHZK = Language_GB2312;//Gb2312 
	gc_PlaySequenceMode = 0;//no repeat 
	G_Current_Contrast = 2; 
	gc_PLAY_DPC = 12; 
	gc_UserBacklightLevel = 4; 
//	gc_SevenBackLight = 0; 
//	G_DSP_RECVolume=39; 
 
} 
 
#if 0 
#if (K_CARD_TYPE == 0x01) 
//------------------------------------------------------------------------------- 
U8 SD_Read_LogicSector(U32 tdw_LogicSectorAddr,U32 tdw_ReadSectorNumber) 
{ 
	tdw_LogicSectorAddr = 0; 
	tdw_ReadSectorNumber = 0; 
	return 0;	 
} 
 
//------------------------------------------------------------------------------- 
U8 SD_Write_LogicSector(U32 tdw_LogicSectorAddr,U32 tdw_WriteSectorNumber) 
{	 
	tdw_LogicSectorAddr = 0; 
	tdw_WriteSectorNumber = 0; 
	return 0; 
} 
 
 
//------------------------------------------------------------------------------- 
U8 CF_Read_LogicSector(tdw_LogicSectorAddr,tdw_ReadSectorNumber) 
{ 
	tdw_LogicSectorAddr = 0; 
	tdw_ReadSectorNumber = 0; 
	return 0; 
} 
 
//------------------------------------------------------------------------------- 
U8 CF_Write_LogicSector(tdw_LogicSectorAddr,tdw_WriteSectorNumber) 
{ 
	tdw_LogicSectorAddr = 0; 
	tdw_WriteSectorNumber = 0; 
	return 0; 
} 
#endif 
 
#endif 
 
 
 
#if ((K_CARD_TYPE &0x01) == 0x01) 
void Mlun_NAND_Initialize() 
{ 
	gc_CurrentCard=CURRENT_MEDIA_NAND; 
//	FlashExchang(CURRENT_MEDIA_NAND,gc_CurrentCard,1);//	 
	SMC_Initializes(); 
//	return 0; 
} 
#endif 
 
#if ((K_CARD_TYPE &0x02) == 0x02) 
void Mlun_SD_Initialize() 
{ 
	SD_Initializes(gc_MlunCardType); 
	gc_CurrentCard=gc_MlunCardType; 
//	return 0; 
} 
#endif 
 
#if ((K_CARD_TYPE &0x04) == 0x04) 
void Mlun_SMC_Initialize() 
{ 
	FlashExchang(CURRENT_MEDIA_SMC,gc_CurrentCard,1);// 
	gc_CurrentCard=CURRENT_MEDIA_SMC; 
	SMC_Initializes(); 
//	return 0; 
} 
#endif 
 
#if ((K_CARD_TYPE &0x08) == 0x08) 
void Mlun_CF_Initialize() 
{ 
	CF_Initializes(CURRENT_MEDIA_CF); 
	gc_CurrentCard=CURRENT_MEDIA_CF; 
//	return 0; 
} 
#endif 
#if ((K_CARD_TYPE &0x10) == 0x10) 
void Mlun_MS_Initialize()//memory stick 
{ 
	MS_Initializes(CURRENT_MEDIA_MS); 
	gc_CurrentCard=CURRENT_MEDIA_MS; 
	//return 0; 
} 
#endif 
 
#if ((K_CARD_TYPE &0x20) == 0x20) 
void Mlun_MS_Initialize()//memory stick 
{ 
	MS_Initializes(CURRENT_MEDIA_MS); 
	gc_CurrentCard=CURRENT_MEDIA_MS; 
	//return 0; 
} 
#endif 
#if ((K_CARD_TYPE &0x02)== 0x02) 
void CardDetectInUsb(void)  
{	 
	U8 tc_Detect = 0; 
	U8 tc_CardType = 0xff; 
	{ 
		if(gb_Card_Event)		// Polling Card in FMGPIO.5 per 128mSec 
		{ 
			 
		 	gb_Card_Event=0;   // 
			STORAGE_Detect(&tc_Detect); 
	       	if (!tc_Detect)   //Card is plug-out 	 
	        {	 
				gb_USBCardST1 = 0; 
				gc_CurrentExistMedia &= 0xBF; 
				gc_MlunCardType = CURRENT_MEDIA_SD;//default is SD Card 
	        } 
			else			//Card is plug-in  
			{	 
				gb_USBCardST1 = 1; 
				gc_ucStorageType = 1; 
			}	 
			if(gb_USBCardST1!=gb_USBCardST0)	// Card is exchanged? 
			{ 
				gb_USBCardST0=~gb_USBCardST0;	// Card Status is exchange  
				G_USBMSDC_ubRefreshNeeded = 1; 
				if(gb_USBCardST1) 
				{ 
					// initial Card 
					if (!SD_SetInterface(CURRENT_MEDIA_SD)) 
					{ 
						tc_CardType = CURRENT_MEDIA_SD; 
						gc_CurrentExistMedia |= 0x40; 
					} 
					else if (!SD_SetInterface(CURRENT_MEDIA_MMC)) 
					{ 
						tc_CardType = CURRENT_MEDIA_MMC; 
						gc_CurrentExistMedia |= 0x40; 
					} 
					if(gc_CurrentExistMedia&0x40) 
					{ 
						SD_STORAGE_Initialize(); 
						gdw_MlunSdCardSize = USER_Get_SYSInformation(2);//xyq 050108 
						gc_MlunCardType = tc_CardType; 
						if (tc_CardType == CURRENT_MEDIA_SD) 
						{ 
						//	gc_SdCardLock = SD_WriteProtect(); 
						} 
			   		} 
					 
				} 
				else	// Card is not existed!! 
				{//--- If the Card is plug-out, then the Card is defined as No-Media in USB protocol. 
						gc_ucStorageType = 0; 
						if(USB_GetState() == USB_STAND_BY) 
						{ 
							if (gc_CurrentExistMedia & 0x80) 
							{ 
								SMC_STORAGE_Initialize(); 
							} 
						} 
				} 
				 
			} 
			 
								 
		}	 
	} 
} 
#endif 
#ifndef SUPPORT_MLUN 
void MultiLunCheckCard(void) 
{ 
	 
} 
#endif