/*
******************************************************************************************************
 @Module        	
 @Filename     	Setup_Scenario.c
 @Project        	SEM-3000
-----------------------------------------------------------------------------------------------------
 @Controller     	Si1010

 @Compiler      	Keil 8.12

 @ Frequency   	Using Internal clock 24.5MHz

 @Codegenerator 	0.1

 @Description   

------------------------------------------------------------------------------------------------------
 @Date          		2013-07-05 11:00:00

******************************************************************************************************
*/
#define _SETUP_SCENARIO_C_
/*
********************************************************************************************************
									 @Project Includes
********************************************************************************************************
*/

#include "PROJECT_INCLUDES.H"

/*
*********************************************************************************************************
 									@Macros
*********************************************************************************************************
*/

 
/*
*********************************************************************************************************
									 @TYPE DEFINE 
*********************************************************************************************************
*/

 U8 Sec_SetUp_Time;
 U8 Sec_Pairing_Time;
 
 U8 TempCnt;

U8 Sec_Pairing_SetTime;
U8 Sec_Pairing_Failed_SetTime;

extern U8 Key_Set_operation;  // cmlee

typedef enum {
	
	SET_YEAR=0,

	SET_MOON,

	SET_DAY,
	
	SET_HOUR,
	
	SET_MINUTE,
	
	//SET_WEEK,

		
	SET_MAX
	
}TIME_SET_OPERATION;

typedef enum {
	
	SET_BASIC_FARE=0,

	SET_TIER,

	SET_THRESHOLD,
	
	SET_CNT_MAX
	
}BILLING_SET_OPERATION;

typedef enum {
	SET_PEAK_MIN=0,
	
	SET_TIME_PEAK,

	//SET_AMPM,

	SET_PEAKRATE      // max value 

}PEAKTIME_SET_OPERATION;

#ifdef SET_ONOFFTIMER
typedef enum {
	SET_ONOFFTIMER_CHANNEL=0,
	SET_ONOFFTIMER_HOUR,
	SET_ONOFFTIMER_MINUTE,
	SET_ONOFFTIMER_ONOFF
}ONOFFTIME_SET_OPERATION;
#endif
/*
*********************************************************************************************************
									@INSIDE  FUNCTION 
*********************************************************************************************************
*/
static SET_OPERATION	Select_Set_Operation(void);
void Lcd_Dsp_Year_Setup(bit Attribute);
void Lcd_Dsp_Moonth_Day_Setup(U8 Sel, bit Attribute);
extern void  LCD_Dsplay_which_AMPM(U8 count);  // cmlee
extern void LCD_Dsplay_which_peak(U8 count);     // cmlee
#ifdef SET_ONOFFTIMER
extern void LCD_Dsplay_OnOffTimer_AMPM(U8 count, U8 onoff);
extern void LCD_Dsplay_OnOff_Timer(U8 count);
#endif
void Set_Operation_Initialization(void)
{
	Day_Display_Count=TINME_DSP;
}

U16 final_code; 

void  Normal_Display_Time_Day(U8 Display_Count)
{
   U8 hour_temp;
	switch(Display_Count){

		case TINME_DSP:
					LCD_MOON_OFF;
					LCD_DAY_OFF;
					LCD_YEAR_OFF;
					LCD_TIME_2DOT_ON;
					LCD_Blink_Attribute(LCD_INVERSE_DISPLAY_bit);
					LCD_Dsplay_AM_PM();
					#if 1
					hour_temp = event1.hours;
					if (event1.hours >12 && event1.hours < 24) hour_temp-=12;
					else if(event1.hours==24) hour_temp=0;
					LCD_Dsplay_Time_Hour_Minute(hour_temp,event1.minutes  );
					#else 
  					LCD_Dsplay_Time_Hour_Minute(event1.hours,event1.minutes  );
					#endif
					break;	
					
					
		case YEAR_DSP:	Lcd_Dsp_Year_Setup(LCD_NORMAL_DISPLAY_bit);   break;	
		case MOONTH_DAY_DSP: 	Lcd_Dsp_Moonth_Day_Setup(SET_MOON, LCD_NORMAL_DISPLAY_bit); break;	

		case DISPLAY_EXIT:
			
								break;
		default :		break;
		}
	LCD_Dsplay_Week();    
	
}

void Lcd_Dsp_Year_Setup(bit Attribute)
{	
		LCD_MOON_OFF;
		LCD_DAY_OFF;
		LCD_Week_ALL_OFF;
		
		LCD_TIME_AM_OFF;
		LCD_TIME_PM_OFF ; 	

		LCD_TIME_2DOT_OFF;
		
		LCD_YEAR_ON;
		
		LCD_Dsplay_Time_Hour_Minute( (U8)( event1.years/100 ), (U8)(event1.years% 100 ) );
		
		Set_Lcd_Char_Attribute(SETING_TIME_Minute_Digit1, Attribute );
		Set_Lcd_Char_Attribute(SETING_TIME_Hour_Digit1,    Attribute );
}



void Lcd_Dsp_Moonth_Day_Setup(U8 Sel, bit Attribute)
{	
		LCD_YEAR_OFF;
		LCD_Week_ALL_OFF;

		LCD_TIME_AM_OFF;
		LCD_TIME_PM_OFF ; 	

		LCD_TIME_2DOT_OFF;
		
		LCD_MOON_ON;
		LCD_DAY_ON;

	 	Compute_365_Total_Day( event1.years, event1.output_month, event1.output_days, &event1.days );  // 년월일을  365일로 환산 한다 
		
		Compute_Month(&event1.output_month, &event1.output_days,    event1.days, event1.years);  // 월, 일 로 환산 한다 
		
		LCD_Dsplay_Time_Hour_Minute(event1.output_month, event1.output_days );      // 월, 일 을 LCD에  표시 한다 

		if(Sel==SET_MOON)		Set_Lcd_Char_Attribute(SETING_TIME_Hour_Digit1, Attribute);
		else  if(Sel==SET_DAY)	Set_Lcd_Char_Attribute(SETING_TIME_Minute_Digit1, Attribute);	
		else {
				Set_Lcd_Char_Attribute(SETING_TIME_Hour_Digit1, Attribute);
				Set_Lcd_Char_Attribute(SETING_TIME_Minute_Digit1, Attribute);	
		}
		
}


void Lcd_Dsp_All_Off_Time_SetUp(void)
{
	//U8 i;
	Set_Lcd_Char_Attribute(SETING_TIME_Minute_Digit1, 	LCD_NORMAL_DISPLAY_bit);	
	Set_Lcd_Char_Attribute(SETING_TIME_Hour_Digit1, 	LCD_NORMAL_DISPLAY_bit);	
	Set_Lcd_Char_Attribute(Week_Set, 				LCD_NORMAL_DISPLAY_bit);	

	LCD_YEAR_OFF;
	LCD_MOON_OFF;
	LCD_DAY_OFF;

	LCD_TIME_AM_OFF;
	LCD_TIME_PM_OFF ; 

	TEMP_THRESHOLD_OFF;
	TIME_Billing_OFF;
	LCDMap.LCD_BitCtrl.SEG42_SETING_TIME_TIER=0;  // TIER 아이콘 ON
	//LCDMap.LCD_ByteCtrl[TIMER_SLOT_Digit1]=0; 
	//Attribute.LCD_ByteCtrl[TIMER_SLOT_Digit1]=LCD_NORMAL_DISPLAY;
	#if 0
	for(i=2;i<7;i++)
		{
		LCDMap.LCD_ByteCtrl[i]=0; 
		Attribute.LCD_ByteCtrl[i]=LCD_NORMAL_DISPLAY;
		}
	#endif 
}
#if 1 // cmlee
void Lcd_Dsp_All_Off_PeakTime_SetUp(void)
{
	Set_Lcd_Char_Attribute(SETING_TIME_Minute_Digit1, 	LCD_NORMAL_DISPLAY_bit);	
	Set_Lcd_Char_Attribute(SETING_TIME_Hour_Digit1, 	LCD_NORMAL_DISPLAY_bit);	
	Set_Lcd_Char_Attribute(Week_Set, 				LCD_NORMAL_DISPLAY_bit);	

	LCD_YEAR_OFF;
	LCD_MOON_OFF;
	LCD_DAY_OFF;

	LCD_TIME_AM_OFF;
	LCD_TIME_PM_OFF ; 	
	PEAKTIME_START_OFF;

//LCDMap.LCD_BitCtrl.SEG40_SETING_TIME_Rate =1 ; //  Rate  in Time Section
//	LCDMap.LCD_BitCtrl.SEG40_SETING_TIME_OFF =0; 
//	LCDMap.LCD_BitCtrl.SEG40_SETING_TIME_MID =0; 
//	LCDMap.LCD_BitCtrl.SEG38_SETING_TIME_ON =0; 
	
}
#endif
 // display Basic Fare 
//void Lcd_Dsp_BASIC_Setup(U8 no_count_fare, LCD_INVERSE_DISPLAY_bit)	
void Lcd_Dsp_PeakTime_Setup(U8 No_Step_Peaktime)	
{	U8 hour_temp;
	//Key_Set_operation=1;
	NOW_COST_UNIT_POUND_OFF;
	NOW_COST_UNIT_JAPAN_OFF;
	NOW_COST_UNIT_EURO_OFF;
	NOW_COST_UNIT_DOLLAR_OFF;

	NOW_COST_IMP_KWH_OFF;
	NOW_COST_K_OFF;
	NOW_COST_Won_OFF;

	NOW_COST_DOT1_OFF;
	NOW_COST_DOT2_OFF;

	LCD_DAY_OFF;
	LCD_MOON_OFF;
	//NOW_COST_UNIT_JAPAN_ON;
	//NOW_COST_Won_ON;                     // 화페 단위 표시 ( 한 화 )
	//LCDMap.LCD_BitCtrl.SEG42_SETING_TIME_TIER=1;  // TIER 아이콘 ON
	PEAKTIME_START_ON ; 
	LCD_TIME_2DOT_ON;

	
	
	//  LCD_Blink_Attribute(LCD_INVERSE_DISPLAY_bit);
#if 1
	hour_temp = Peak.hour[No_Step_Peaktime];
	if (Peak.hour[No_Step_Peaktime] >12 && Peak.hour[No_Step_Peaktime] < 24) hour_temp-=12;
	else if(Peak.hour[No_Step_Peaktime]==24) hour_temp=0;
	LCD_Dsplay_Time_Hour_Minute(hour_temp,Peak.minute[No_Step_Peaktime]   );
	LCD_Dsplay_which_AMPM(No_Step_Peaktime);
#else 
  	LCD_Dsplay_Time_Hour_Minute(Peak.hour[No_Step_Peaktime],Peak.minute[No_Step_Peaktime] );	
#endif	
	
	LCD_Dsplay_which_peak(No_Step_Peaktime);
	
	
}
	
void Lcd_Dsp_All_Off_Billing_SetUp(void)
{
	//Set_Lcd_Char_Attribute(SETING_TIME_Minute_Digit1, 	LCD_NORMAL_DISPLAY_bit);	
	//Set_Lcd_Char_Attribute(SETING_TIME_Hour_Digit1, 	LCD_NORMAL_DISPLAY_bit);	
	//Set_Lcd_Char_Attribute(Week_Set, 				LCD_NORMAL_DISPLAY_bit);	

	LCD_YEAR_OFF;
	LCD_MOON_OFF;
	LCD_DAY_OFF;

	LCD_TIME_AM_OFF;
	LCD_TIME_PM_OFF ; 	
}
extern U8 No_Step_Fare_System;

void Lcd_Dsp_All_Off_Bill_System_SetUp(void)   // 가정용 고압 산업용 구분 
{
	//Set_Lcd_Char_Attribute(SETING_TIME_Minute_Digit1, 	LCD_NORMAL_DISPLAY_bit);	
	//Set_Lcd_Char_Attribute(SETING_TIME_Hour_Digit1, 	LCD_NORMAL_DISPLAY_bit);	
	//Set_Lcd_Char_Attribute(Week_Set, 				LCD_NORMAL_DISPLAY_bit);	

	LCD_YEAR_OFF;
	LCD_MOON_OFF;
	LCD_DAY_OFF;

	LCD_TIME_AM_OFF;
	LCD_TIME_PM_OFF ; 	
	LcdPut_Digit_1(Cost_Unit_Digit,   No_Step_Fare_System); 
	
}
extern U8 No_Step_temp_change;

void Lcd_Dsp_temp_C_F_SetUp(void)   // 가정용 고압 산업용 구분 
{
	//Set_Lcd_Char_Attribute(SETING_TIME_Minute_Digit1, 	LCD_NORMAL_DISPLAY_bit);	
	//Set_Lcd_Char_Attribute(SETING_TIME_Hour_Digit1, 	LCD_NORMAL_DISPLAY_bit);	
	//Set_Lcd_Char_Attribute(Week_Set, 				LCD_NORMAL_DISPLAY_bit);	

	LCD_YEAR_OFF;
	LCD_MOON_OFF;
	LCD_DAY_OFF;

	LCD_TIME_AM_OFF;
	LCD_TIME_PM_OFF ; 	
	LcdPut_Digit_1(Cost_Unit_Digit,   No_Step_temp_change); 
	
}
void Lcd_Dsp_Flat_Setup(void)	
{
	volatile U32 Dsp_Money;
	float Dsp_Money1; 
 		
	NOW_COST_UNIT_POUND_OFF;
	NOW_COST_UNIT_JAPAN_OFF;
	NOW_COST_UNIT_EURO_OFF;
	NOW_COST_UNIT_DOLLAR_OFF;

	NOW_COST_IMP_KWH_OFF;
	NOW_COST_K_OFF;
	NOW_COST_Won_OFF;

	NOW_COST_DOT1_OFF;
	NOW_COST_DOT2_OFF;
	
	//NOW_COST_UNIT_JAPAN_ON;
	NOW_COST_Won_ON;                     // 화페 단위 표시 ( 한 화 )
	//LCDMap.LCD_BitCtrl.SEG42_SETING_TIME_TIER=1;  // TIER 아이콘 ON
	
	//Dsp_Money=Lcd_Dsp_Money_Proc( NEW_POWER,   Power );
	Dsp_Money1 = event1.Average_Cost;
	Dsp_Money = Dsp_Money1 * 100; 
	NOW_COST_DOT2_ON;
///	printf("\n Basic_Money = %ld , %f\n", Dsp_Money, Dsp_Money1); 
	//LcdPut_Digit_1(TIMER_SLOT_Digit1,    count+1);   // Display Tier NO
	Lcd_Put_Number1(Now_COST_Digit1, Dsp_Money,5);
}
void Lcd_Dsp_Code_Setup(void)	
{
	//volatile U32 Dsp_Money;
	U16 Dsp_Money1; 
 		
	NOW_COST_UNIT_POUND_OFF;
	NOW_COST_UNIT_JAPAN_OFF;
	NOW_COST_UNIT_EURO_OFF;
	NOW_COST_UNIT_DOLLAR_OFF;

	NOW_COST_IMP_KWH_OFF;
	NOW_COST_K_OFF;
	NOW_COST_Won_OFF;

	NOW_COST_DOT1_OFF;
	NOW_COST_DOT2_OFF;
	
	//NOW_COST_UNIT_JAPAN_ON;
	NOW_COST_Won_OFF;                     // 화페 단위 표시 ( 한 화 )
	//LCDMap.LCD_BitCtrl.SEG42_SETING_TIME_TIER=1;  // TIER 아이콘 ON
	
	//Dsp_Money=Lcd_Dsp_Money_Proc( NEW_POWER,   Power );
	Dsp_Money1 = final_code;
	//Dsp_Money = Dsp_Money1 * 10; 
	NOW_COST_DOT1_OFF;
///	printf("\n Basic_Money = %ld , %f\n", Dsp_Money, Dsp_Money1); 
	//LcdPut_Digit_1(TIMER_SLOT_Digit1,    count+1);   // Display Tier NO
	Lcd_Put_Number(Now_COST_Digit1, Dsp_Money1,5);
}
void Lcd_Dsp_Moment_Power_Max_Setup(void)	
{
	volatile U32 Dsp_Money;
	//U16 Dsp_Money1; 
 		
	NOW_COST_UNIT_POUND_OFF;
	NOW_COST_UNIT_JAPAN_OFF;
	NOW_COST_UNIT_EURO_OFF;
	NOW_COST_UNIT_DOLLAR_OFF;

	NOW_COST_IMP_KWH_OFF;
	NOW_COST_K_OFF;
	NOW_COST_Won_OFF;

	NOW_COST_DOT1_OFF;
	NOW_COST_DOT2_OFF;
	
	//NOW_COST_UNIT_JAPAN_ON;
	NOW_COST_Won_OFF;                     // 화페 단위 표시 ( 한 화 )
	//LCDMap.LCD_BitCtrl.SEG42_SETING_TIME_TIER=1;  // TIER 아이콘 ON
	
	//Dsp_Money=Lcd_Dsp_Money_Proc( NEW_POWER,   Power );
	Dsp_Money = event1.alarm_moment_peak;
	//Dsp_Money = Dsp_Money1 * 10; 
	NOW_COST_DOT1_OFF;
      if(Dsp_Money>65535) Dsp_Money=65535;
	Lcd_Put_Number1(Now_COST_Digit1, (U16)Dsp_Money,5);
}
void Lcd_Dsp_Month_Target_Power(void)	
{
	volatile U32 Dsp_Money;
	//U16 Dsp_Money1; 
 		
	NOW_COST_UNIT_POUND_OFF;
	NOW_COST_UNIT_JAPAN_OFF;
	NOW_COST_UNIT_EURO_OFF;
	NOW_COST_UNIT_DOLLAR_OFF;
	NOW_COST_IMP_KWH_OFF;
	
	NOW_COST_K_ON;
	NOW_COST_Won_OFF;

	NOW_COST_DOT1_OFF;
	NOW_COST_DOT2_OFF;
	
	//NOW_COST_UNIT_JAPAN_ON;
	NOW_COST_Won_OFF;                     // 화페 단위 표시 ( 한 화 )
	//LCDMap.LCD_BitCtrl.SEG42_SETING_TIME_TIER=1;  // TIER 아이콘 ON
	
	//Dsp_Money=Lcd_Dsp_Money_Proc( NEW_POWER,   Power );
	Dsp_Money = event1.alarm_month_target;
	//Dsp_Money = Dsp_Money1 * 10; 
	NOW_COST_DOT1_OFF;
      if(Dsp_Money>65535) Dsp_Money=65535;
	Lcd_Put_Number1(Now_COST_Digit1, (U16)Dsp_Money,5);
}
  // display Basic Fare 
//void Lcd_Dsp_BASIC_Setup(U8 no_count_fare, LCD_INVERSE_DISPLAY_bit)	
void Lcd_Dsp_BASIC_Setup(U8 Billing_type, U8 count)	
{
	volatile U32 Dsp_Money;
	float Dsp_Money1; 
 		
	NOW_COST_UNIT_POUND_OFF;
	NOW_COST_UNIT_JAPAN_OFF;
	NOW_COST_UNIT_EURO_OFF;
	NOW_COST_UNIT_DOLLAR_OFF;

	NOW_COST_IMP_KWH_OFF;
	NOW_COST_K_OFF;
	NOW_COST_Won_OFF;

	NOW_COST_DOT1_OFF;
	NOW_COST_DOT2_OFF;
	
	//NOW_COST_UNIT_JAPAN_ON;
	NOW_COST_Won_ON;                     // 화페 단위 표시 ( 한 화 )
	LCDMap.LCD_BitCtrl.SEG42_SETING_TIME_TIER=1;  // TIER 아이콘 ON
	
	//Dsp_Money=Lcd_Dsp_Money_Proc( NEW_POWER,   Power );
	switch(Billing_type){
		case SET_BASIC_FARE : Dsp_Money=Cost.Base_Cost[count];  TEMP_THRESHOLD_OFF;  TIME_Billing_ON; TIME_RATE_OFF; break;    // Basic
		case SET_TIER		: Dsp_Money=Cost.Treshold[count];  TIME_Billing_OFF ; TEMP_THRESHOLD_ON ; TIME_RATE_OFF;  break;     // Threshold
		case SET_THRESHOLD 	: Dsp_Money1=Cost.Billing_Rate[count];           // Rate
								TEMP_THRESHOLD_OFF ;  TIME_Billing_OFF ; TIME_RATE_ON;
								Dsp_Money = Dsp_Money1 * 10;   
							break;
		default				: break;
		}
///	printf("\n Basic_Money = %ld , %f\n", Dsp_Money, Dsp_Money1); 
	LcdPut_Digit_1(TIMER_SLOT_Digit1,    count+1);   // Display Tier NO
	if(Dsp_Money>=10000009L)  // 천 만 이상 
	{
		Dsp_Money /=1000;
		NOW_COST_K_ON;
	}
	if(1000000L< Dsp_Money&&Dsp_Money< 9999999L)  // 백만 이상   ~ 9999999L
	{
		Dsp_Money /=100;
		NOW_COST_K_ON;
		NOW_COST_DOT1_ON;
	}
	else if(99999L< Dsp_Money&&Dsp_Money< 1000000L) // 99999L ~ 백만 미만 
	{
		Dsp_Money /=10;
		NOW_COST_K_ON;
		NOW_COST_DOT2_ON;
	}
	if(Billing_type==SET_THRESHOLD) NOW_COST_DOT1_ON;
			Lcd_Put_Number1(Now_COST_Digit1, Dsp_Money,5);
}
//#endif 
void Lcd_Dsp_BASIC1_Setup(U8 count)	//    UAE    Display   
{
	volatile U32 Dsp_Money;
	float Dsp_Money1; 
 		
	NOW_COST_UNIT_POUND_OFF;
	NOW_COST_UNIT_JAPAN_OFF;
	NOW_COST_UNIT_EURO_OFF;
	NOW_COST_UNIT_DOLLAR_OFF;

	NOW_COST_IMP_KWH_OFF;
	NOW_COST_K_OFF;
	NOW_COST_Won_OFF;

	NOW_COST_DOT1_OFF;
	NOW_COST_DOT2_OFF;
	
	LCDMap.LCD_BitCtrl.SEG42_SETING_TIME_TIER=1;  // TIER 아이콘 ON       Basic 표시ㅣ가 없어서 Tier로 표시
	
	LcdPut_Digit_1(TIMER_SLOT_Digit1,    count+1);   // Display Tier NO
	LcdPut_Digit_1(Cost_Unit_Digit,   count+1); 
	 NOW_COST_DOT2_ON;

	 Dsp_Money1 = Cost.Billing_Rate[count];		
	 Dsp_Money = Dsp_Money1 * 100; 	// display 2 floating point  									
	Lcd_Put_Number(Now_COST_Digit1, Dsp_Money,5);
}
static SET_OPERATION SetUp_Time_Set(void)
{

	U8 Key;
	U8 hour_temp;
	Key_Set_operation =1;     // cmlee  to rotate
	Key = Key_Get();

	switch(Key)
	{						
		   
		case MENU_KEY_SHORT:	break;    //cmlee
		case SET_KEY_SHORT:  
						Beep_Oneshort();
						
						if(Key==SET_KEY_SHORT){  
												if(Time_SetUp_Sqc )Time_SetUp_Sqc--;
												else Time_SetUp_Sqc=SET_MINUTE; 	
						}						
						else 				    {  if( ++Time_SetUp_Sqc==SET_MAX )Time_SetUp_Sqc=SET_YEAR;   }

						Lcd_Dsp_All_Off_Time_SetUp(); 	
						
						switch(Time_SetUp_Sqc){
							
						case SET_YEAR:        	Lcd_Dsp_Year_Setup(LCD_INVERSE_DISPLAY_bit); 					break;											
						case SET_MOON:        	Lcd_Dsp_Moonth_Day_Setup(SET_MOON, LCD_INVERSE_DISPLAY_bit); 	break;											
						case SET_DAY:         	Lcd_Dsp_Moonth_Day_Setup(SET_DAY   , LCD_INVERSE_DISPLAY_bit);  	break;
						
						case SET_HOUR:  		
											Set_Lcd_Char_Attribute(SETING_TIME_Hour_Digit1, LCD_INVERSE_DISPLAY_bit);	break;
						case SET_MINUTE:  	Set_Lcd_Char_Attribute(SETING_TIME_Minute_Digit1, LCD_INVERSE_DISPLAY_bit); break;
						default:  			Time_SetUp_Sqc=SET_YEAR  ; break;    // cmlee 
						}
						break;


		case DOWN_KEY_LONG:	
								#if 1
								Beep_Two();
								System_Parameter_Init(SYSTEM_RESET_INITIALIZE);
								return  EXIT_SET_OPERATION;
								#endif
		case DOWN_KEY_SHORT:			
								Beep_Oneshort();
		
								switch(Time_SetUp_Sqc){

									case SET_YEAR:																
	  											 if(event1.years> 2000)event1.years--; 
												 else event1.years=2000;
												 
												 Lcd_Dsp_Year_Setup(LCD_INVERSE_DISPLAY_bit); 	
												 
												 break;
												 
									case SET_MOON:		
										
	  											 if(--event1.output_month==0)event1.output_month=12; 	
												 
												 Lcd_Dsp_Moonth_Day_Setup(SET_MOON, LCD_INVERSE_DISPLAY_bit);
												 
												 break;
												 
									case SET_DAY:		
										
	  											 if(--event1.output_days==0)event1.output_days=31; 	
												 
												 Lcd_Dsp_Moonth_Day_Setup(SET_DAY, LCD_INVERSE_DISPLAY_bit);
												 
												 break;
												 
									
									case SET_HOUR:	 
		  											 if(event1.hours)event1.hours--; 
													 else event1.hours=23;
													 break;
									case SET_MINUTE:  
		  											 if(event1.minutes)event1.minutes--; 
													 else event1.minutes=59;
													 break;
									default :    		 Time_SetUp_Sqc=SET_YEAR  ; break; // cmlee 
								}

								break;

		case UP_KEY_LONG:			
								#if 1
								Beep_Two();
								System_Parameter_Init(SYSTEM_RESET_INITIALIZE);
								return  EXIT_SET_OPERATION;
								#endif
		case UP_KEY_SHORT:			 
								Beep_Oneshort();	

								switch(Time_SetUp_Sqc){
									case SET_YEAR:																
	  											 event1.years++; 
												 Lcd_Dsp_Year_Setup(LCD_INVERSE_DISPLAY_bit); 	
												 break;
									case SET_MOON:																
	  											 if( ++event1.output_month>12)event1.output_month=1; 
												 Lcd_Dsp_Moonth_Day_Setup(SET_MOON, LCD_INVERSE_DISPLAY_bit);
												 break;
									case SET_DAY:																
	  											 if(++event1.output_days>31)event1.output_days=1; 
												 Lcd_Dsp_Moonth_Day_Setup(SET_DAY, LCD_INVERSE_DISPLAY_bit);  
												 break;
												 
									case SET_HOUR:     if( ++event1.hours==24)event1.hours=0;  			break;
									case SET_MINUTE:  if( ++event1.minutes==60)event1.minutes=0;   		break;
									default :    		 Time_SetUp_Sqc=SET_YEAR  ; break; // cmlee 
								}
								break;
					
		case CHANGE_KEY_SHORT:			
								Buzzer_Sound_Error();	
								
								MINUTE_INIT=event1.minutes;   
								HOUR_INIT=event1.hours;   
								Key_Set_operation = 0; // cmlee    to rotate time month day
								System_Parameter_Init(SYSTEM_SETING);
								Lcd_Dsp_All_Off_Time_SetUp(); 
								RTC_SetTimer(TIME_INIT);
								RTC_Timer_Run();		

							//	Lcd_Dsp_All_Off_Time_SetUp(); 
								//LCD_BufferClear(); // cmlee 
								LCD_TIME_2DOT_ON;																		
								LCD_Blink_Attribute(LCD_INVERSE_DISPLAY_bit);
                           				timer_mSecTimerDelete(mSec_SetUp_Time);
								LCD_Display_Home_Menu();  // cmlee
											
								return  EXIT_SET_OPERATION;
		default: 					break;   // cmlee
	
	}

       LCD_Dsplay_Week();  
	   
       if(Time_SetUp_Sqc > SET_DAY)
	{				
					LCD_TIME_2DOT_ON;
					LCD_Dsplay_AM_PM();
					#if 1
					hour_temp = event1.hours;
					if (event1.hours >12 && event1.hours < 24) hour_temp-=12;
					else if(event1.hours==24) hour_temp=0;
					LCD_Dsplay_Time_Hour_Minute(hour_temp,event1.minutes  );
					#else 
  					LCD_Dsplay_Time_Hour_Minute(event1.hours,event1.minutes  );
					#endif
       }
		
	return Set_Operation_Mode;
	
}
U8 No_Step;                 //cmlee
U8 Billing_SetUp_Sqc;	   // cmlee
U8 money_pos ;	         // cmlee

#if 1
static SET_OPERATION SetUp_Billing_Rate(void)    //============================
{

	 U8 Key, i;   //, temp_location;
	 U16 temp_basic, temp_threshold; 
	 float temp_rate;

	//TIME_Billing_ON;
	//printf("Entrance Billing Setup\n");
	Key_Set_operation =1;     // cmlee  to rotate
	//Lcd_Dsp_All_Off_Billing_SetUp(); 	
	Key = Key_Get();
	
	switch(Key)
	{						
		
		case MENU_KEY_SHORT:
							Beep_Oneshort();
							if(Billing_SetUp_Sqc==SET_BASIC_FARE || Billing_SetUp_Sqc==SET_TIER || Billing_SetUp_Sqc==SET_THRESHOLD )
								{
																
								if(money_pos < 0 || money_pos>=6)money_pos=0;
								money_pos++;
								switch(money_pos)
									{
									 case 1 : //  temp_location = Now_COST_Digit1; 
											Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_INVERSE_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
								 			break;
								 	case 2 : //   temp_location = Now_COST_Digit2; 
											Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_INVERSE_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
								 			break;
								 	case 3 : //    temp_location = Now_COST_Digit3; 
											Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_INVERSE_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
								 			break;
								  	case 4 : //  temp_location = Now_COST_Digit4; 
								 			Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_INVERSE_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
								 			break;
									 case 5 : //temp_location = Now_COST_Digit5; break;
											Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_INVERSE_DISPLAY_bit );
								 			break;
							
								default : 
											Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_INVERSE_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_INVERSE_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_INVERSE_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_INVERSE_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_INVERSE_DISPLAY_bit );
									break;
									}
								//	money_pos++;
								}
						break;
		case SET_KEY_SHORT:   
						Beep_Oneshort();
						
	#if 1   // cmlee 	
						
						Lcd_Dsp_All_Off_Billing_SetUp(); 	
						if(Key==SET_KEY_SHORT)Billing_SetUp_Sqc++;
						if(Billing_SetUp_Sqc>=SET_CNT_MAX) Billing_SetUp_Sqc=SET_BASIC_FARE; 
						switch(Billing_SetUp_Sqc){
							
						case SET_BASIC_FARE:      ///  	printf("SET_BASIC_FARE\n"); 
													//Lcd_Dsp_BASIC_Setup(LCD_INVERSE_DISPLAY_bit); 	
													Lcd_Dsp_BASIC_Setup(Billing_SetUp_Sqc,No_Step); 	
													break;											
						case SET_TIER:       /// 			printf("SET_TIER\n"); 
													//Lcd_Dsp_TIER_Setup(); 	
													Lcd_Dsp_BASIC_Setup(Billing_SetUp_Sqc,No_Step); 	
													break;											
						case SET_THRESHOLD:    ///     	printf("SET_THRESHOLD\n"); 
													//Lcd_Dsp_THRESHOLD_Setup();  	
													Lcd_Dsp_BASIC_Setup(Billing_SetUp_Sqc,No_Step); 
													break;
						
						#if 1 // cmlee
						default:  			Billing_SetUp_Sqc=SET_BASIC_FARE  ; 
											break;    // cmlee 
						#endif 
						}
						
						if(Key==MENU_KEY_SHORT) money_pos++;
						break;				

		case DOWN_KEY_LONG:	
			#if 1
								Beep_Two();
								System_Parameter_Init(SYSTEM_RESET_INITIALIZE);
								return  EXIT_SET_OPERATION;
								#endif
		case DOWN_KEY_SHORT:			
								Beep_Oneshort();
								if(money_pos >=6 || money_pos ==0 ) {
								if(No_Step>5)No_Step=5;
								Lcd_Dsp_BASIC_Setup(Billing_SetUp_Sqc,No_Step); 
								No_Step--; 
									}
	#if 1
								
								else if(Billing_SetUp_Sqc < 3 &&  money_pos <6 ){
								switch(Billing_SetUp_Sqc)
									{
									case SET_BASIC_FARE : 
													
											temp_basic =Cost.Base_Cost[No_Step];		
											switch(money_pos)
												{
												 case 1 : 
												 		temp_basic-=1;
														if(temp_basic < 0) temp_basic =Cost.Base_Cost[No_Step];	
														else Cost.Base_Cost[No_Step]=temp_basic;
														break;
												case 2 : 
														temp_basic-=10;
														if(temp_basic < 0) temp_basic =Cost.Base_Cost[No_Step];	
														else Cost.Base_Cost[No_Step]=temp_basic;
														break;
												case 3 : 
														temp_basic-=100;
														if(temp_basic < 0) temp_basic =Cost.Base_Cost[No_Step];	
														else Cost.Base_Cost[No_Step]=temp_basic;
														break;
												case 4 : 
														temp_basic-=1000;
														if(temp_basic < 0) temp_basic =Cost.Base_Cost[No_Step];	
														else Cost.Base_Cost[No_Step]=temp_basic;
														break;
												case 5 : 
														temp_basic-=10000;
														if(temp_basic < 0) temp_basic =Cost.Base_Cost[No_Step];	
														else Cost.Base_Cost[No_Step]=temp_basic;
														break;	
												default:  break; 
												
												}
										case SET_TIER : 
													///	printf("000000\n");
											temp_threshold = Cost.Treshold[No_Step];		
											switch(money_pos)
												{
												 case 1 : 
												 		temp_threshold-=1;
														if(temp_threshold < 0) temp_threshold =Cost.Treshold[No_Step];	
														else Cost.Treshold[No_Step]=temp_threshold;
														break;
												case 2 : 
														temp_threshold-=10;
														if(temp_threshold < 0) temp_threshold =Cost.Treshold[No_Step];	
														else Cost.Treshold[No_Step]=temp_threshold;
														break;
												case 3 : 
														temp_threshold-=100;
														if(temp_threshold < 0) temp_threshold =Cost.Treshold[No_Step];	
														else Cost.Treshold[No_Step]=temp_threshold;
														break;
												case 4 : 
														temp_threshold-=1000;
														if(temp_threshold < 0) temp_threshold =Cost.Treshold[No_Step];	
														else Cost.Treshold[No_Step]=temp_threshold;
														break;
												case 5 : 
														temp_threshold-=10000;
														if(temp_threshold < 0) temp_threshold =Cost.Treshold[No_Step];	
														else Cost.Treshold[No_Step]=temp_threshold;
														break;	
												default:  break; 
												}
									case SET_THRESHOLD :    // floating point 
													///	printf("000000\n");
											temp_rate = Cost.Billing_Rate[No_Step];		
											switch(money_pos)
												{
												 case 1 : 
												 		temp_rate-=0.1;
														if(temp_rate < 0) temp_rate =Cost.Billing_Rate[No_Step];	
														else Cost.Billing_Rate[No_Step]=temp_rate;
														break;
												case 2 : 
														temp_rate-=1;
														if(temp_rate < 0) temp_rate =Cost.Billing_Rate[No_Step];	
														else Cost.Billing_Rate[No_Step]=temp_rate;
														break;
												case 3 : 
														temp_rate-=10;
														if(temp_rate < 0) temp_rate =Cost.Billing_Rate[No_Step];	
														else Cost.Billing_Rate[No_Step]=temp_rate;
														break;
												case 4 : 
														temp_rate-=100;
														if(temp_rate < 0) temp_rate =Cost.Billing_Rate[No_Step];	
														else Cost.Billing_Rate[No_Step]=temp_rate;
														break;
												case 5 : 
														temp_rate-=1000;
														if(temp_rate < 0) temp_rate =Cost.Billing_Rate[No_Step];	
														else Cost.Billing_Rate[No_Step]=temp_rate;
														break;	
												default:  break; 
												}
										Lcd_Dsp_BASIC_Setup(Billing_SetUp_Sqc,No_Step); 	
										default : break;		
									}
									}
								//LCD_Dsplay_Time_Hour_Minute(Peak.hour[No_Step_Peaktime],Peak.minute[No_Step_Peaktime] );
								//LCD_Dsplay_which_AMPM(No_Step_Peaktime);
								//LCD_Dsplay_which_peak(No_Step_Peaktime);
								//LcdPut_Digit_1(TIMER_SLOT_Digit1,    No_Step_Peaktime+1);   // Display Peaktime slot NO
								break;


	#endif
								break;

		case UP_KEY_LONG:	
			#if 1
								Beep_Two();
								System_Parameter_Init(SYSTEM_RESET_INITIALIZE);
								return  EXIT_SET_OPERATION;
								#endif
		case UP_KEY_SHORT:			 
								Beep_Oneshort();	
								if(money_pos >=6 || money_pos ==0) {
								if(No_Step>4)No_Step=0;  // N0_Step는 unsigned 
								else No_Step++; 
								Lcd_Dsp_BASIC_Setup(Billing_SetUp_Sqc,No_Step); 
								
								}
								
	#if 1
								
								else if(Billing_SetUp_Sqc < 3 &&  money_pos <6 ){
								switch(Billing_SetUp_Sqc)
									{
									case SET_BASIC_FARE : 
													
											temp_basic =Cost.Base_Cost[No_Step];		
											switch(money_pos)
												{
												 case 1 : 
												 		temp_basic+=1;
														if(temp_basic < 0) temp_basic =Cost.Base_Cost[No_Step];	
														else Cost.Base_Cost[No_Step]=temp_basic;
														break;
												case 2 : 
														temp_basic+=10;
														if(temp_basic < 0) temp_basic =Cost.Base_Cost[No_Step];	
														else Cost.Base_Cost[No_Step]=temp_basic;
														break;
												case 3 : 
														temp_basic+=100;
														if(temp_basic < 0) temp_basic =Cost.Base_Cost[No_Step];	
														else Cost.Base_Cost[No_Step]=temp_basic;
														break;
												case 4 : 
														temp_basic+=1000;
														if(temp_basic < 0) temp_basic =Cost.Base_Cost[No_Step];	
														else Cost.Base_Cost[No_Step]=temp_basic;
														break;
												case 5 : 
														temp_basic+=10000;
														if(temp_basic < 0) temp_basic =Cost.Base_Cost[No_Step];	
														else Cost.Base_Cost[No_Step]=temp_basic;
														break;	
												default:  break; 
												
												}
										case SET_TIER : 
													///	printf("000000\n");
											temp_threshold = Cost.Treshold[No_Step];		
											switch(money_pos)
												{
												 case 1 : 
												 		temp_threshold+=1;
														if(temp_threshold < 0) temp_threshold =Cost.Treshold[No_Step];	
														else Cost.Treshold[No_Step]=temp_threshold;
														break;
												case 2 : 
														temp_threshold+=10;
														if(temp_threshold < 0) temp_threshold =Cost.Treshold[No_Step];	
														else Cost.Treshold[No_Step]=temp_threshold;
														break;
												case 3 : 
														temp_threshold+=100;
														if(temp_threshold < 0) temp_threshold =Cost.Treshold[No_Step];	
														else Cost.Treshold[No_Step]=temp_threshold;
														break;
												case 4 : 
														temp_threshold+=1000;
														if(temp_threshold < 0) temp_threshold =Cost.Treshold[No_Step];	
														else Cost.Treshold[No_Step]=temp_threshold;
														break;
												case 5 : 
														temp_threshold+=10000;
														if(temp_threshold < 0) temp_threshold =Cost.Treshold[No_Step];	
														else Cost.Treshold[No_Step]=temp_threshold;
														break;	
												default:  break; 
												}
									case SET_THRESHOLD :    // floating point 
													///	printf("000000\n");
											temp_rate = Cost.Billing_Rate[No_Step];		
											switch(money_pos)
												{
												 case 1 : 
												 		temp_rate+=0.1;
														if(temp_rate < 0) temp_rate =Cost.Billing_Rate[No_Step];	
														else Cost.Billing_Rate[No_Step]=temp_rate;
														break;
												case 2 : 
														temp_rate+=1;
														if(temp_rate < 0) temp_rate =Cost.Billing_Rate[No_Step];	
														else Cost.Billing_Rate[No_Step]=temp_rate;
														break;
												case 3 : 
														temp_rate+=10;
														if(temp_rate < 0) temp_rate =Cost.Billing_Rate[No_Step];	
														else Cost.Billing_Rate[No_Step]=temp_rate;
														break;
												case 4 : 
														temp_rate+=100;
														if(temp_rate < 0) temp_rate =Cost.Billing_Rate[No_Step];	
														else Cost.Billing_Rate[No_Step]=temp_rate;
														break;
												case 5 : 
														temp_rate+=1000;
														if(temp_rate < 0) temp_rate =Cost.Billing_Rate[No_Step];	
														else Cost.Billing_Rate[No_Step]=temp_rate;
														break;	
												default:  break; 
												}
										Lcd_Dsp_BASIC_Setup(Billing_SetUp_Sqc,No_Step); 	
										default : break;		
									}
									}
								//LCD_Dsplay_Time_Hour_Minute(Peak.hour[No_Step_Peaktime],Peak.minute[No_Step_Peaktime] );
								//LCD_Dsplay_which_AMPM(No_Step_Peaktime);
								//LCD_Dsplay_which_peak(No_Step_Peaktime);
								//LcdPut_Digit_1(TIMER_SLOT_Digit1,    No_Step_Peaktime+1);   // Display Peaktime slot NO
							


	#endif
								break;
												
		case CHANGE_KEY_SHORT:	 
		case CHANGE_KEY_LONG :         // save changed data 		
								Buzzer_Sound_Error();	
		///						printf("Change ...........\n");
								Key_Set_operation = 0; // cmlee    to rotate time month day

								for(i=0;i<6;i++) event1.Base_Cost[i]   =  Cost.Base_Cost[i];
								for(i=0;i<6;i++) event1.Treshold[i]  = Cost.Treshold[i];
								for(i=0;i<6;i++) event1.Billing_Rate[i]=   Cost.Billing_Rate[i] ;
																
								#if 1
								System_Parameter_Init(SYSTEM_SETING);
								Lcd_Dsp_All_Off_Time_SetUp(); 
								#if 1
								RTC_SetTimer(TIME_INIT);
								RTC_Timer_Run();		
								#endif
								LCD_Display_Home_Menu();
								
								//LCDMap.LCD_ByteCtrl[TIMER_SLOT_Digit1]=0; 
								//Attribute.LCD_ByteCtrl[TIMER_SLOT_Digit1]=LCD_NORMAL_DISPLAY;

								
								//LCD_BufferClear(); // cmlee 
								LCD_TIME_2DOT_ON;																		
								LCD_Blink_Attribute(LCD_INVERSE_DISPLAY_bit);
                           				timer_mSecTimerDelete(mSec_SetUp_Time);
								//LCD_Display_Home_Menu();  // cmlee		
								#endif 	
								return  EXIT_SET_OPERATION;
								
		default: 					break;   // cmlee
	
#endif  // cmlee first #if 	
	}
#if 0   // cmlee

       LCD_Dsplay_Week();  
	   
       if(Time_SetUp_Sqc > SET_DAY)
	{				
					LCD_TIME_2DOT_ON;
					LCD_Dsplay_AM_PM();
				 	LCD_Dsplay_Time_Hour_Minute(event1.hours,event1.minutes  );
       }
#endif		
	return Set_Operation_Mode;

}
#endif
//=========================================================================
U8 No_Step;                 //cmlee
//U8 Billing_SetUp_Sqc;	   // cmlee
U8 flat_money_pos ;	         // cmlee
static SET_OPERATION SetUp_flat_Rate(void)    //============================
{
	 U8 Key;   //, temp_location;
	 //U16 temp_basic, temp_threshold; 
	 float temp_rate;
	
	Key_Set_operation =1;     // cmlee  to rotate
	Key = Key_Get();
	switch(Key)
	{						
		case MENU_KEY_SHORT:
							Beep_Oneshort();
								if(flat_money_pos < 0 || flat_money_pos>=6)flat_money_pos=0;
								flat_money_pos++;
								switch(flat_money_pos)
									{
									 case 1 : //  temp_location = Now_COST_Digit1; 
											
									 		Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_INVERSE_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
								 			break;
								 	case 2 : //   temp_location = Now_COST_Digit2; 
								 	
											Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_INVERSE_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
								 			break;
								 	case 3 : //    temp_location = Now_COST_Digit3; 
								 			
											Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_INVERSE_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
								 			break;
								  	case 4 : //  temp_location = Now_COST_Digit4; 
								  	
											
								 			Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_INVERSE_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
								 			break;
									 case 5 : //temp_location = Now_COST_Digit5; break;
									 #if 0
									 		LCDMap.LCD_BitCtrl.SEG17_DIGIT1_11D=0;
											LCDMap.LCD_BitCtrl.SEG16_DIGIT2_10D=0;
											LCDMap.LCD_BitCtrl.SEG15_DIGIT3_9D=0;
											LCDMap.LCD_BitCtrl.SEG14_DIGIT4_8D=0;
											LCDMap.LCD_BitCtrl.SEG13_DIGIT5_7D=1;
											#endif
											Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_INVERSE_DISPLAY_bit );
								 			break;
							default : 
											Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
									break;
									}
								//	money_pos++;
								
						break;
		case SET_KEY_SHORT:   
						Beep_Oneshort();
						
	#if 1   // cmlee 	
						
						//Lcd_Dsp_All_Off_Billing_SetUp(); 	
						//Lcd_Dsp_BASIC_Setup(Billing_SetUp_Sqc,No_Step); 	
						Lcd_Dsp_Flat_Setup(); 
						break;				

		case DOWN_KEY_LONG:	
								#if 1
								Beep_Two();
								System_Parameter_Init(SYSTEM_RESET_INITIALIZE);
								return  EXIT_SET_OPERATION;
								#endif
		case DOWN_KEY_SHORT:			
								Beep_Oneshort();
								//if(flat_money_pos >=6) {
								
								//	}
	#if 1
							
											///	printf("000000\n");
											temp_rate = event1.Average_Cost;		
											switch(flat_money_pos)
												{
												 case 1 : 
												 		temp_rate-=0.01;
														if(temp_rate < 0 || temp_rate >1000) temp_rate =event1.Average_Cost;	
														else event1.Average_Cost=temp_rate;
														break;
												case 2 : 
														temp_rate-=0.1;
														if(temp_rate < 0|| temp_rate >1000) temp_rate =event1.Average_Cost;	
														else event1.Average_Cost=temp_rate;
														break;
												case 3 : 
														temp_rate-=1;
														if(temp_rate < 0|| temp_rate >1000) temp_rate =event1.Average_Cost;	
														else event1.Average_Cost=temp_rate;
														break;
												case 4 : 
														temp_rate-=10;
														if(temp_rate < 0|| temp_rate >1000) temp_rate =event1.Average_Cost;	
														else event1.Average_Cost=temp_rate;
														break;
												case 5 : 
														temp_rate-=100;
														if(temp_rate < 0|| temp_rate >1000) temp_rate =event1.Average_Cost;	
														else event1.Average_Cost=temp_rate;
														break;	
												default:  break; 
												}
										Lcd_Dsp_Flat_Setup(); 
										
									
									
								//LCD_Dsplay_Time_Hour_Minute(Peak.hour[No_Step_Peaktime],Peak.minute[No_Step_Peaktime] );
								//LCD_Dsplay_which_AMPM(No_Step_Peaktime);
								//LCD_Dsplay_which_peak(No_Step_Peaktime);
								//LcdPut_Digit_1(TIMER_SLOT_Digit1,    No_Step_Peaktime+1);   // Display Peaktime slot NO
								break;


	#endif
								break;

		case UP_KEY_LONG:			
								#if 1
								Beep_Two();
								System_Parameter_Init(SYSTEM_RESET_INITIALIZE);
								return  EXIT_SET_OPERATION;
								#endif
		case UP_KEY_SHORT:			 
								Beep_Oneshort();	
								//if(flat_money_pos >=6) {
								
								//Lcd_Dsp_Flat_Setup(); 
								
								//}
	   					///	printf("000000\n");
											temp_rate = event1.Average_Cost;		
											switch(flat_money_pos)
												{
												 case 1 : 
												 		temp_rate+=0.01;
														if(temp_rate < 0|| temp_rate >1000) temp_rate =event1.Average_Cost;	
														else event1.Average_Cost=temp_rate;
														break;
												case 2 : 
														temp_rate+=0.1;
														if(temp_rate < 0|| temp_rate >1000) temp_rate =event1.Average_Cost;	
														else event1.Average_Cost=temp_rate;
														break;
												case 3 : 
														temp_rate+=1;
														if(temp_rate < 0|| temp_rate >1000) temp_rate =event1.Average_Cost;	
														else event1.Average_Cost=temp_rate;
														break;
												case 4 : 
														temp_rate+=10;
														if(temp_rate < 0|| temp_rate >1000) temp_rate =event1.Average_Cost;	
														else event1.Average_Cost=temp_rate;
														break;
												case 5 : 
														temp_rate+=100;
														if(temp_rate < 0|| temp_rate >1000) temp_rate =event1.Average_Cost;	
														else event1.Average_Cost=temp_rate;
														break;	
												default:  break; 
												}
									Lcd_Dsp_Flat_Setup(); 
										
									
								//LCD_Dsplay_Time_Hour_Minute(Peak.hour[No_Step_Peaktime],Peak.minute[No_Step_Peaktime] );
								//LCD_Dsplay_which_AMPM(No_Step_Peaktime);
								//LCD_Dsplay_which_peak(No_Step_Peaktime);
								//LcdPut_Digit_1(TIMER_SLOT_Digit1,    No_Step_Peaktime+1);   // Display Peaktime slot NO

								break;
												
		case CHANGE_KEY_SHORT:	 
		case CHANGE_KEY_LONG :      // save changed data 		
								Buzzer_Sound_Error();	
		///						printf("Change ...........\n");
								Key_Set_operation = 0; // cmlee    to rotate time month day
													
								#if 1
								//event1.Average_Cost=temp_rate;
								System_Parameter_Init(SYSTEM_SETING);
								Lcd_Dsp_All_Off_Time_SetUp(); 
								#if 1
								RTC_SetTimer(TIME_INIT);
								RTC_Timer_Run();		
								#endif	

								Lcd_Dsp_All_Off_Time_SetUp(); 
								Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
								Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
								Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
								Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
								Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
								//LCD_BufferClear(); // cmlee 
								LCD_TIME_2DOT_ON;																		
								LCD_Blink_Attribute(LCD_INVERSE_DISPLAY_bit);
                           				timer_mSecTimerDelete(mSec_SetUp_Time);
								LCD_Display_Home_Menu();  // cmlee		
								#endif 	
								return  EXIT_SET_OPERATION;
		
		default: 					break;   // cmlee
	
#endif  // cmlee first #if 	
	}
#if 0   // cmlee

       LCD_Dsplay_Week();  
	   
       if(Time_SetUp_Sqc > SET_DAY)
	{				
					LCD_TIME_2DOT_ON;
					LCD_Dsplay_AM_PM();
				 	LCD_Dsplay_Time_Hour_Minute(event1.hours,event1.minutes  );
       }
#endif		
	return Set_Operation_Mode;

}


U8 No_Step_Fare_System;
//U8 Fare_Method;

static SET_OPERATION SetUp_Billing_System(void)    //============================
{

	U8 Key;

	//TIME_Billing_ON;
	//printf("Entrance Billing Setup\n");
	Key_Set_operation =1;     // cmlee  to rotate
	//Lcd_Dsp_All_Off_Bill_System_SetUp(); 
	Key = Key_Get();
	
	switch(Key)
	{						
		
		case MENU_KEY_SHORT:	break;
		case SET_KEY_SHORT:   
						Beep_Oneshort();
						
	#if 1   // cmlee 	
			///			printf("Bill System_SetUp_Sqc=%d\n"); //cmlee 
						
						Lcd_Dsp_All_Off_Bill_System_SetUp(); 	
						//Set_Lcd_Char_Attribute(Cost_Unit_Digit,LCD_INVERSE_DISPLAY_bit);
						break;				

		case DOWN_KEY_LONG:	
								#if 1
								Beep_Two();
								System_Parameter_Init(SYSTEM_RESET_INITIALIZE);
								return  EXIT_SET_OPERATION;
								#endif
		case DOWN_KEY_SHORT:			
								Beep_Oneshort();
								No_Step_Fare_System--;
								if(No_Step_Fare_System<0 || No_Step_Fare_System>2)No_Step_Fare_System=2;
								LcdPut_Digit_1(Cost_Unit_Digit,   No_Step_Fare_System);          // 요금  설정       요금종류 
								break;

		case UP_KEY_LONG:	
								#if 1
								Beep_Two();
								System_Parameter_Init(SYSTEM_RESET_INITIALIZE);
								return  EXIT_SET_OPERATION;
								#endif
		case UP_KEY_SHORT:			 
								Beep_Oneshort();	
								No_Step_Fare_System++;
								if(No_Step_Fare_System>2)No_Step_Fare_System=0;
								LcdPut_Digit_1(Cost_Unit_Digit,   No_Step_Fare_System);          // 요금  설정       요금종류 
								break;
												
		case CHANGE_KEY_SHORT:	 
		case CHANGE_KEY_LONG :         // save changed data 		
								Buzzer_Sound_Error();	
		///						printf("Change ...........\n");
								Key_Set_operation = 0; // cmlee    to rotate time month day
								event1.Fare_Method = No_Step_Fare_System;
								#if 1
								System_Parameter_Init(SYSTEM_SETING);
								Lcd_Dsp_All_Off_Time_SetUp(); 
								#if 1
								RTC_SetTimer(TIME_INIT);
								RTC_Timer_Run();		
								#endif	

								Lcd_Dsp_All_Off_Time_SetUp(); 
								//LCD_BufferClear(); // cmlee 
								LCD_TIME_2DOT_ON;																		
								LCD_Blink_Attribute(LCD_INVERSE_DISPLAY_bit);
                           				timer_mSecTimerDelete(mSec_SetUp_Time);
								LCD_Display_Home_Menu();  // cmlee
								#endif 						 	
								return  EXIT_SET_OPERATION;
								
		default: 					break;   // cmlee
	
#endif  // cmlee first #if 	
	}
#if 0   // cmlee

       LCD_Dsplay_Week();  
	   
       if(Time_SetUp_Sqc > SET_DAY)
	{				
					LCD_TIME_2DOT_ON;
					LCD_Dsplay_AM_PM();
				 	LCD_Dsplay_Time_Hour_Minute(event1.hours,event1.minutes  );
       }
#endif		
	return Set_Operation_Mode;

}
U8 No_Step_data_erase;
extern U8 content_buff[100];
extern xdata volatile CHEAD		ph;
static SET_OPERATION SetUp_Data_Erase(void)    //============================
{

	U8 Key;

	//TIME_Billing_ON;
	//printf("Entrance Billing Setup\n");
	Key_Set_operation =1;     // cmlee  to rotate
	//Lcd_Dsp_All_Off_Bill_System_SetUp(); 
	Key = Key_Get();
	
	switch(Key)
	{						
		
		case MENU_KEY_SHORT:	break;
		case SET_KEY_SHORT:   
						Beep_Oneshort();
						
	#if 1   // cmlee 	
			///			printf("Bill System_SetUp_Sqc=%d\n"); //cmlee 
						
						Lcd_Dsp_All_Off_Bill_System_SetUp(); 	
						//Set_Lcd_Char_Attribute(Cost_Unit_Digit,LCD_INVERSE_DISPLAY_bit);
						break;				

		case DOWN_KEY_LONG:			
		case DOWN_KEY_SHORT:			
								Beep_Oneshort();
								if(No_Step_data_erase==0)No_Step_data_erase=1 ;
								else No_Step_data_erase=0 ;
								if(No_Step_data_erase==1)
								LCD_Put_String(POWER_CONSOMPTION_Digit5,  "ERASE", 5);
								else
								LCD_Put_String(POWER_CONSOMPTION_Digit5,  " PASS", 5);
								LcdPut_Digit_1(Cost_Unit_Digit,   No_Step_data_erase);          // 요금  설정       요금종류 
								
								break;

		case UP_KEY_LONG:			
		case UP_KEY_SHORT:			 
								Beep_Oneshort();	
								if(No_Step_data_erase==0)No_Step_data_erase=1 ;
								else No_Step_data_erase=0 ;
								
								if(No_Step_data_erase==1)
								LCD_Put_String(POWER_CONSOMPTION_Digit5,  "ExASE", 5);     // the most proper char "R" is x 
								else
								LCD_Put_String(POWER_CONSOMPTION_Digit5,  " PASS", 5);
								
								LcdPut_Digit_1(Cost_Unit_Digit,   No_Step_data_erase);          // 요금  설정       요금종류 
								break;
												
		case CHANGE_KEY_SHORT:	 
		case CHANGE_KEY_LONG :         // save changed data 		
								Buzzer_Sound_Error();	
		///						printf("Change ...........\n");
								Key_Set_operation = 0; // cmlee    to rotate time month day
								#if 1
								if(No_Step_data_erase==1) 
									{
									sflash_fast_read(NETWORK_ADDRESS, content_buff, 57);
									sflash_bulk_erase();
									get_head_info();
									//Read_PowerInfomation();  // EEPROM 초기화 
									sflash_page_program(NETWORK_ADDRESS, content_buff, 57);
									
									//ph.cur.point = DATA_BASE_ADD;
									
									}
								//System_Parameter_Init(SYSTEM_SETING);
								Lcd_Dsp_All_Off_Time_SetUp(); 
								#if 1
								RTC_SetTimer(TIME_INIT);
								RTC_Timer_Run();		
								#endif	

								Lcd_Dsp_All_Off_Time_SetUp(); 
								//LCD_BufferClear(); // cmlee 
								LCD_TIME_2DOT_ON;																		
								LCD_Blink_Attribute(LCD_INVERSE_DISPLAY_bit);
                           				timer_mSecTimerDelete(mSec_SetUp_Time);
								LCD_Display_Home_Menu();  // cmlee
								#endif 						 	
								return  EXIT_SET_OPERATION;
								
		default: 					break;   // cmlee
	
#endif  // cmlee first #if 	
	}
#if 0   // cmlee

       LCD_Dsplay_Week();  
	   
       if(Time_SetUp_Sqc > SET_DAY)
	{				
					LCD_TIME_2DOT_ON;
					LCD_Dsplay_AM_PM();
				 	LCD_Dsplay_Time_Hour_Minute(event1.hours,event1.minutes  );
       }
#endif		
	return Set_Operation_Mode;

}
#if 0
//=========================================================================
//U8 No_Step;                 //cmlee
//U8 Billing_SetUp_Sqc;	   // cmlee
U8 code_pos ;	         // cmlee
 
 U8 select_now_rssi;
static SET_OPERATION DISPLAY_RSSI_CONTROL(void)    //============================
{
	 U8 Key;   //, temp_location;
	
	 U16 temp_code, test;
	
	Key_Set_operation =1;     // cmlee  to rotate
	LCD_Put_String(POWER_CONSOMPTION_Digit5,  " C0DE", 5);
	Key = Key_Get();
	switch(Key)
	{						
		case MENU_KEY_SHORT:
							Beep_Oneshort();
								if(code_pos < 0 || code_pos>=6)code_pos=0;
								code_pos++;
								switch(code_pos)
									{
									 case 1 : //  temp_location = Now_COST_Digit1; 
											Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_INVERSE_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
								 			break;
								 	case 2 : //   temp_location = Now_COST_Digit2; 
											Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_INVERSE_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
								 			break;
								 	case 3 : //    temp_location = Now_COST_Digit3; 
											Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_INVERSE_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
								 			break;
								  	case 4 : //  temp_location = Now_COST_Digit4; 
								 			Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_INVERSE_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
								 			break;
									 case 5 : //temp_location = Now_COST_Digit5; break;
											Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_INVERSE_DISPLAY_bit );
								 			break;
							default : 
											Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
									break;
									}
								//	money_pos++;
								
						break;
		case SET_KEY_SHORT:   
						Beep_Oneshort();
						Lcd_Dsp_Code_Setup(); 
						break;				

		case DOWN_KEY_LONG:			
		case DOWN_KEY_SHORT:			
								Beep_Oneshort();
													
											temp_code = final_code;		
											switch(code_pos)
												{
												 case 1 : 
												 		temp_code-=1;
														if(temp_code < 0) temp_code =final_code;	
														else final_code=temp_code;
														break;
												case 2 : 
														temp_code-=10;
														if(temp_code < 0) temp_code =final_code;	
														else final_code=temp_code;
														break;
												case 3 : 
														temp_code-=100;
														if(temp_code < 0) temp_code =final_code;	
														else final_code=temp_code;
														break;
												case 4 : 
														temp_code-=1000;
														if(temp_code < 0) temp_code =final_code;	
														else final_code=temp_code;
														break;
												case 5 : 
														temp_code-=10000;
														if(temp_code < 0) temp_code =final_code;	
														else final_code=temp_code;
														break;	
												default:  break; 
												}
										Lcd_Dsp_Code_Setup(); 
												
								break;

		case UP_KEY_LONG:			
		case UP_KEY_SHORT:			 
								Beep_Oneshort();	
								
											temp_code = final_code;		
											switch(code_pos)
												{
												 case 1 : 
												 		temp_code+=1;
														if(temp_code < 0) temp_code =final_code;	
														else  final_code=temp_code;
														break;
												case 2 : 
														temp_code+=10;
														if(temp_code < 0) temp_code =final_code;	
														else final_code=temp_code;
														break;
												case 3 : 
														temp_code+=100;
														if(temp_code < 0) temp_code =final_code;	
														else final_code=temp_code;
														break;
												case 4 : 
														temp_code+=1000;
														if(temp_code < 0) temp_code =final_code;	
														else final_code=temp_code;
														break;
												case 5 : 
														temp_code+=10000;
														if(temp_code < 0) temp_code =final_code;	
														else final_code=temp_code;
														break;	
												default:  break; 
												}
									Lcd_Dsp_Code_Setup(); 
	
								break;
												
		case CHANGE_KEY_SHORT:	 
		case CHANGE_KEY_LONG :         // save changed data 		
								Buzzer_Sound_Error();	
								test=event1.Pass_code;
								if (event1.Pass_code==final_code)
								          select_now_rssi = 0;  // if  select_now_rssi = 0; then rssi display else display now energy  
								 else select_now_rssi = 1;
								 
								Key_Set_operation = 0; // cmlee    to rotate time month day
													
								#if 1
								System_Parameter_Init(SYSTEM_SETING);
								Lcd_Dsp_All_Off_Time_SetUp(); 
								#if 1
								RTC_SetTimer(TIME_INIT);
								RTC_Timer_Run();		
								#endif	

								Lcd_Dsp_All_Off_Time_SetUp(); 
								Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
								Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
								Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
								Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
								Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
								//LCD_BufferClear(); // cmlee 
								LCD_TIME_2DOT_ON;																		
								LCD_Blink_Attribute(LCD_INVERSE_DISPLAY_bit);
                           				timer_mSecTimerDelete(mSec_SetUp_Time);
								LCD_Display_Home_Menu();  // cmlee		
								#endif 	
								return  EXIT_SET_OPERATION;
								
		default: 					break;   // cmlee
	

	}
#if 0   // cmlee

       LCD_Dsplay_Week();  
	   
       if(Time_SetUp_Sqc > SET_DAY)
	{				
					LCD_TIME_2DOT_ON;
					LCD_Dsplay_AM_PM();
				 	LCD_Dsplay_Time_Hour_Minute(event1.hours,event1.minutes  );
       }
#endif		
	return Set_Operation_Mode;

}
#endif
#if 1
U8 No_Step_temp_change;
//extern U8 content_buff[100];
//extern xdata volatile CHEAD		ph;
static SET_OPERATION DISPLAY_TEMPERATURE_CHANGE(void)    //============================
{

	U8 Key;

	//TIME_Billing_ON;
	//printf("Entrance Billing Setup\n");
	Key_Set_operation =1;     // cmlee  to rotate
	//Lcd_Dsp_All_Off_Bill_System_SetUp(); 
	Key = Key_Get();
	
	switch(Key)
	{						
		
		case MENU_KEY_SHORT:	break;
		case SET_KEY_SHORT:   
						Beep_Oneshort();
						
	#if 1   // cmlee 	
			///			printf("Bill System_SetUp_Sqc=%d\n"); //cmlee 
						
						Lcd_Dsp_temp_C_F_SetUp(); 	
						//Set_Lcd_Char_Attribute(Cost_Unit_Digit,LCD_INVERSE_DISPLAY_bit);
						break;				

		case DOWN_KEY_LONG:			
		case DOWN_KEY_SHORT:			
								Beep_Oneshort();
								if(No_Step_temp_change==0)No_Step_temp_change=1 ;
								else No_Step_temp_change=0 ;
								if(No_Step_temp_change==1)
								LCD_Put_String(POWER_CONSOMPTION_Digit5,  "FAHxE", 5);
								else
								LCD_Put_String(POWER_CONSOMPTION_Digit5,  "CELSi", 5);
								LcdPut_Digit_1(Cost_Unit_Digit,   No_Step_temp_change);          // 요금  설정       요금종류 
								
								break;

		case UP_KEY_LONG:			
		case UP_KEY_SHORT:			 
								Beep_Oneshort();	
								if(No_Step_temp_change==0)No_Step_temp_change=1 ;
								else No_Step_temp_change=0 ;
								
								if(No_Step_temp_change==1)
								LCD_Put_String(POWER_CONSOMPTION_Digit5,  "FAHxE", 5);     // the most proper char "R" is x 
								else
								LCD_Put_String(POWER_CONSOMPTION_Digit5,  "CELSi", 5);
								
								LcdPut_Digit_1(Cost_Unit_Digit,   No_Step_temp_change);          // 요금  설정       요금종류 
								break;
												
		case CHANGE_KEY_SHORT:	 
		case CHANGE_KEY_LONG :         // save changed data 		
								Buzzer_Sound_Error();	
		///						printf("Change ...........\n");
								Key_Set_operation = 0; // cmlee    to rotate time month day
								#if 1
								event1.Temperature_C_F=No_Step_temp_change;
								#if 1
								RTC_SetTimer(TIME_INIT);
								RTC_Timer_Run();		
								#endif	
								System_Parameter_Init(SYSTEM_SETING);
								Lcd_Dsp_All_Off_Time_SetUp(); 
								//LCD_BufferClear(); // cmlee 
								LCD_TIME_2DOT_ON;																		
								LCD_Blink_Attribute(LCD_INVERSE_DISPLAY_bit);
                           				timer_mSecTimerDelete(mSec_SetUp_Time);
								LCD_Display_Home_Menu();  // cmlee
								#endif 						 	
								return  EXIT_SET_OPERATION;
								
		default: 					break;   // cmlee
	
#endif  // cmlee first #if 	
	}
#if 0   // cmlee

       LCD_Dsplay_Week();  
	   
       if(Time_SetUp_Sqc > SET_DAY)
	{				
					LCD_TIME_2DOT_ON;
					LCD_Dsplay_AM_PM();
				 	LCD_Dsplay_Time_Hour_Minute(event1.hours,event1.minutes  );
       }
#endif		
	return Set_Operation_Mode;
}
#endif
#if 0
//======================================================================
U8 No_Step_Peaktime;                 //cmlee
U8 Peaktime_SetUp_Sqc;	   // cmlee
U8 peaktime_pos ;	         // cmlee
U8 count_peak1;
U8 count_peak2;
U8 count_peak3;

static SET_OPERATION SetUp_Peak_Time(void)    //============================
{
	U8 Key, hour_temp;
 //U8 hour_upper, hour_lower, minute_upper, minute_lower;
	
	Key_Set_operation =1;     // cmlee  to rotate
	//Lcd_Dsp_BASIC_Setup(SET_BASIC_FARE,money_pos); 
	//Lcd_Dsp_All_Off_PeakTime_SetUp();
	//LcdPut_Digit_1(TIMER_SLOT_Digit1,    No_Step_Peaktime);   // Display Tier NO
	Key = Key_Get();
	
	switch(Key)
	{						
		//case NONE_KEY: 					break;
		case MENU_KEY_SHORT:	
						Beep_Oneshort();
						#if 0
						if(Peaktime_SetUp_Sqc==SET_TIME_PEAK && peaktime_pos>=3) peaktime_pos=0;
						else if(Peaktime_SetUp_Sqc==SET_TIME_PEAK && peaktime_pos<3) peaktime_pos++;
						#endif 
						if(Peaktime_SetUp_Sqc==SET_TIME_PEAK && peaktime_pos==0) 
							 {
							    peaktime_pos=1;
								Set_Lcd_Char_Attribute(SETING_TIME_Minute_Digit1, LCD_INVERSE_DISPLAY_bit);
								Set_Lcd_Char_Attribute(SETING_TIME_Hour_Digit1, LCD_NORMAL_DISPLAY_bit);
						}
						else if(Peaktime_SetUp_Sqc==SET_TIME_PEAK && peaktime_pos==1)
							   {
							    peaktime_pos=0;
							    Set_Lcd_Char_Attribute(SETING_TIME_Hour_Digit1, LCD_INVERSE_DISPLAY_bit);
							    Set_Lcd_Char_Attribute(SETING_TIME_Minute_Digit1, LCD_NORMAL_DISPLAY_bit);	
							}
						 break;   // 메뉴 키는 변경할 위치를 찾는데 이용 (향후 SET 키와 메뉴 키를  change 하는  것이 좋을  듯 )
		case SET_KEY_SHORT:							// set key는  좀 더 넓은 범위의   선택 기능    0: 6개의 큰 범위 선택    1: 시작 시간   2: AM PM     3: OFF MID ON  
			
						Beep_Oneshort();
						
	#if 1   // cmlee 	
						//LCD_Dsplay_Time_Hour_Minute(Peak.hour[No_Step_Peaktime],Peak.minute[No_Step_Peaktime] );
						//LCD_Dsplay_which_AMPM(No_Step_Peaktime);
						//LCD_Dsplay_which_peak(No_Step_Peaktime);
		///				printf("PeakTime_SetUp_Sqc=%d\n",Peaktime_SetUp_Sqc); //cmlee 
						
						///Lcd_Dsp_All_Off_Billing_SetUp(); 	
						Peaktime_SetUp_Sqc++;
						if(Peaktime_SetUp_Sqc>SET_PEAKRATE) Peaktime_SetUp_Sqc=SET_PEAK_MIN; 
						
						switch(Peaktime_SetUp_Sqc){
						case SET_PEAK_MIN : 		///	printf("SET_PEAK_MIN\n"); 	
													LcdPut_Digit_1(TIMER_SLOT_Digit1,    No_Step_Peaktime+1);   // Display Peaktime slot NO
													Set_Lcd_Char_Attribute(TIMER_SLOT_Digit1, LCD_INVERSE_DISPLAY_bit);
													#if 1
													hour_temp = Peak.hour[No_Step_Peaktime];
													if (Peak.hour[No_Step_Peaktime] >12 && Peak.hour[No_Step_Peaktime] < 24) hour_temp-=12;
													else if(Peak.hour[No_Step_Peaktime]==24) hour_temp=0;
													LCD_Dsplay_Time_Hour_Minute(hour_temp,Peak.minute[No_Step_Peaktime]   );
													LCD_Dsplay_which_AMPM(No_Step_Peaktime);
													#else 
  													LCD_Dsplay_Time_Hour_Minute(Peak.hour[No_Step_Peaktime],Peak.minute[No_Step_Peaktime] );	
													#endif	
													
													LCD_Dsplay_which_peak(No_Step_Peaktime);
													Attribute.LCD_BitCtrl.SEG40_SETING_TIME_Rate=LCD_NORMAL_DISPLAY_bit;    // Rate Off
													
													
													break;
													
						case SET_TIME_PEAK:   ///     	printf("SET_Time_Peak\n"); 
													Set_Lcd_Char_Attribute(TIMER_SLOT_Digit1, LCD_NORMAL_DISPLAY_bit);      // when you push set key, previous state cllear
													Set_Lcd_Char_Attribute(SETING_TIME_Hour_Digit1, LCD_INVERSE_DISPLAY_bit);
													PEAKTIME_START_ON;
													#if 1
														hour_temp = Peak.hour[No_Step_Peaktime];
														if (Peak.hour[No_Step_Peaktime] >12 && Peak.hour[No_Step_Peaktime] < 24) hour_temp-=12;
														else if(Peak.hour[No_Step_Peaktime]==24) hour_temp=0;
														LCD_Dsplay_Time_Hour_Minute(hour_temp,Peak.minute[No_Step_Peaktime]   );
														LCD_Dsplay_which_AMPM(No_Step_Peaktime);
														#else 
  														LCD_Dsplay_Time_Hour_Minute(Peak.hour[No_Step_Peaktime],Peak.minute[No_Step_Peaktime] );	
														#endif	
													
													Attribute.LCD_BitCtrl.SEG40_SETING_TIME_Rate=LCD_NORMAL_DISPLAY_bit;    // Rate Off
													//Attribute.LCD_BitCtrl.SEG40_SETING_TIME_OFF =LCD_NORMAL_DISPLAY_bit; 
													//Attribute.LCD_BitCtrl.SEG40_SETING_TIME_MID =LCD_NORMAL_DISPLAY_bit; 
													//Attribute.LCD_BitCtrl.SEG38_SETING_TIME_ON =LCD_NORMAL_DISPLAY_bit;
													break;		
						#if 0  // for 12time * 2(AM/PM)   so AM/PM setting does exist , rotate
						case SET_AMPM:        	//		printf("SET_AMPM\n"); 
													//Lcd_Dsp_TIER_Setup(); 	
													Set_Lcd_Char_Attribute(TIMER_SLOT_Digit1, LCD_NORMAL_DISPLAY_bit);      // when you push set key, previous state cllear
													Set_Lcd_Char_Attribute(SETING_TIME_Hour_Digit1, LCD_NORMAL_DISPLAY_bit);
													 Set_Lcd_Char_Attribute(SETING_TIME_Minute_Digit1, LCD_NORMAL_DISPLAY_bit);	
													LCD_Dsplay_which_AMPM(No_Step_Peaktime);
													Attribute.LCD_BitCtrl.SEG40_SETING_TIME_Rate=LCD_NORMAL_DISPLAY_bit;    // Rate Off
													
													//Attribute.LCD_BitCtrl.SEG40_SETING_TIME_OFF =LCD_NORMAL_DISPLAY_bit; 
													//Attribute.LCD_BitCtrl.SEG40_SETING_TIME_MID =LCD_NORMAL_DISPLAY_bit; 
													//Attribute.LCD_BitCtrl.SEG38_SETING_TIME_ON =LCD_NORMAL_DISPLAY_bit;
													break;		
						#endif 
						case SET_PEAKRATE:     ///    	printf("SET_Peakrate\n"); 
													//Lcd_Dsp_THRESHOLD_Setup();  	
													Set_Lcd_Char_Attribute(TIMER_SLOT_Digit1, LCD_NORMAL_DISPLAY_bit);      // when you push set key, previous state cllear
													Set_Lcd_Char_Attribute(SETING_TIME_Hour_Digit1, LCD_NORMAL_DISPLAY_bit	);
													Set_Lcd_Char_Attribute(SETING_TIME_Minute_Digit1, 	LCD_NORMAL_DISPLAY_bit);	
													LCD_Dsplay_which_peak(No_Step_Peaktime);
													break;
						
						default:  					
													Peaktime_SetUp_Sqc=SET_TIME_PEAK  ; 
													break;    // cmlee 
							}
						
				break;				

		case DOWN_KEY_LONG:			
		case DOWN_KEY_SHORT:	
						///		printf("Peak Time == Down key\n");
								Beep_Oneshort();
								switch(Peaktime_SetUp_Sqc)
									{
									case SET_PEAK_MIN : 
													///	printf("000000\n");
														
														No_Step_Peaktime++;
														if(No_Step_Peaktime>=Max_peaktime) No_Step_Peaktime=0;
														LcdPut_Digit_1(TIMER_SLOT_Digit1,    No_Step_Peaktime+1);   // Display Peaktime slot NO
														#if 1
														hour_temp = Peak.hour[No_Step_Peaktime];
														if (Peak.hour[No_Step_Peaktime] >12 && Peak.hour[No_Step_Peaktime] < 24) hour_temp-=12;
														else if(Peak.hour[No_Step_Peaktime]==24) hour_temp=0;
														LCD_Dsplay_Time_Hour_Minute(hour_temp,Peak.minute[No_Step_Peaktime]   );
														LCD_Dsplay_which_AMPM(No_Step_Peaktime);
														#else 
  														LCD_Dsplay_Time_Hour_Minute(Peak.hour[No_Step_Peaktime],Peak.minute[No_Step_Peaktime] );	
														#endif	
														LCD_Dsplay_which_AMPM(No_Step_Peaktime);
														LCD_Dsplay_which_peak(No_Step_Peaktime);
														Attribute.LCD_BitCtrl.SEG40_SETING_TIME_Rate =LCD_NORMAL_DISPLAY_bit ; //  Rate  in Time Section
														Attribute.LCD_BitCtrl.SEG40_SETING_TIME_OFF =LCD_NORMAL_DISPLAY_bit; 
														Attribute.LCD_BitCtrl.SEG40_SETING_TIME_MID =LCD_NORMAL_DISPLAY_bit; 
														Attribute.LCD_BitCtrl.SEG38_SETING_TIME_ON =LCD_NORMAL_DISPLAY_bit; 
														break;
									case SET_TIME_PEAK : 
										
														switch(peaktime_pos)    		//해당 위치의 값 증가  0~9   해당 위치는 pos으로 정리    memu key
															{
															case 0 :  
																	Peak.hour[No_Step_Peaktime] -= 1;
																	if(Peak.hour[No_Step_Peaktime] < 0 ||Peak.hour[No_Step_Peaktime] > 24 ) {
																		 Peak.hour[No_Step_Peaktime] = 24;
																		}
															  		
															  	      break;
															case 1 : 
															  		Peak.minute[No_Step_Peaktime] -= 1;
																	if(Peak.minute[No_Step_Peaktime] < 0 ||Peak.minute[No_Step_Peaktime] > 59 ) {
																		       Peak.minute[No_Step_Peaktime] = 59;
																		}
																	break;	
															default : break;
															}

												#if 1
												hour_temp = Peak.hour[No_Step_Peaktime];
												if (Peak.hour[No_Step_Peaktime] >12 && Peak.hour[No_Step_Peaktime] < 24) hour_temp-=12;
												else if(Peak.hour[No_Step_Peaktime]==24) hour_temp=0;
												LCD_Dsplay_Time_Hour_Minute(hour_temp,Peak.minute[No_Step_Peaktime]   );
												LCD_Dsplay_which_AMPM(No_Step_Peaktime);
												#else 
  												LCD_Dsplay_Time_Hour_Minute(Peak.hour[No_Step_Peaktime],Peak.minute[No_Step_Peaktime] );	
												#endif	
													
												break;
											// 바로 display 할것인가 아니면 나중에 ?????			
									#if 0
									case SET_AMPM  :
													printf("22222=%x\n" ,count_peak2);
													 if(Peak.which_AMPM[No_Step_Peaktime]==AM) Peak.which_AMPM[No_Step_Peaktime]=PM;
													 else Peak.which_AMPM[No_Step_Peaktime]=AM;
																																
													 LCD_Dsplay_which_AMPM(No_Step_Peaktime);
												break;		
										// 바로 display 할것인가 아니면 나중에 ?????
									#endif 
									case SET_PEAKRATE  : 
						///							printf("33333=%x\n",count_peak3);
													count_peak3++;
													if(count_peak3>=3) count_peak3=0;
													
													switch(count_peak3){
															case 0 :  Peak.which_Peak[No_Step_Peaktime]=0; break;
															case 1 : Peak.which_Peak[No_Step_Peaktime]=1; break;
															case 2 : Peak.which_Peak[No_Step_Peaktime]=2; break;
															default: break;
														}
													LCD_Dsplay_which_peak(No_Step_Peaktime);
												break;
									default : break;
									}
								//LCD_Dsplay_Time_Hour_Minute(Peak.hour[No_Step_Peaktime],Peak.minute[No_Step_Peaktime] );
								//LCD_Dsplay_which_AMPM(No_Step_Peaktime);
								//LCD_Dsplay_which_peak(No_Step_Peaktime);
								//LcdPut_Digit_1(TIMER_SLOT_Digit1,    No_Step_Peaktime+1);   // Display Peaktime slot NO
								break;

		case UP_KEY_LONG:	
							#if 0
								if(time_mSecTimeExpired(mSec_SetUp_Time) == TIMER_EXPIRED ){ 
									
											timer_mSecTimerSet(mSec_SetUp_Time, Long_Key_Tick); 	// Set Time out priode
								}
								else return TIME_SET; 
							#endif
		case UP_KEY_SHORT:			 
					///			printf("Peak Time == Up key\n");
								Beep_Oneshort();
								switch(Peaktime_SetUp_Sqc)
									{
									case SET_PEAK_MIN : 
														No_Step_Peaktime--;
														if(No_Step_Peaktime<0 || No_Step_Peaktime > 6) No_Step_Peaktime=5;
														LcdPut_Digit_1(TIMER_SLOT_Digit1,    No_Step_Peaktime+1);   // Display Peaktime slot NO
														#if 1
														hour_temp = Peak.hour[No_Step_Peaktime];
														if (Peak.hour[No_Step_Peaktime] >12 && Peak.hour[No_Step_Peaktime] < 24) hour_temp-=12;
														else if(Peak.hour[No_Step_Peaktime]==24) hour_temp=0;
														LCD_Dsplay_Time_Hour_Minute(hour_temp,Peak.minute[No_Step_Peaktime]   );
														LCD_Dsplay_which_AMPM(No_Step_Peaktime);
														#else 
  														LCD_Dsplay_Time_Hour_Minute(Peak.hour[No_Step_Peaktime],Peak.minute[No_Step_Peaktime] );	
														#endif	
														
														LCD_Dsplay_which_peak(No_Step_Peaktime);
														break;
									case SET_TIME_PEAK : 
														switch(peaktime_pos)    		//해당 위치의 값 증가  0~9   해당 위치는 pos으로 정리    memu key
															{
															case 0 :  
																	Peak.hour[No_Step_Peaktime] += 1;
																	if(Peak.hour[No_Step_Peaktime] < 0 ||Peak.hour[No_Step_Peaktime] > 24 ) {
																		 Peak.hour[No_Step_Peaktime] = 0;
																		}
															  		
															  	      break;
															case 1 : 
															  		Peak.minute[No_Step_Peaktime] += 1;
																	if(Peak.minute[No_Step_Peaktime] < 0 ||Peak.minute[No_Step_Peaktime] > 59 ) {
																		       Peak.minute[No_Step_Peaktime] = 0;
																		}
																	break;	
															default : break;
															}
												#if 1
												hour_temp = Peak.hour[No_Step_Peaktime];
												if (Peak.hour[No_Step_Peaktime] >12 && Peak.hour[No_Step_Peaktime] < 24) hour_temp-=12;
												else if(Peak.hour[No_Step_Peaktime]==24) hour_temp=0;
												LCD_Dsplay_Time_Hour_Minute(hour_temp,Peak.minute[No_Step_Peaktime]   );
												LCD_Dsplay_which_AMPM(No_Step_Peaktime);
												#else 
  												LCD_Dsplay_Time_Hour_Minute(Peak.hour[No_Step_Peaktime],Peak.minute[No_Step_Peaktime] );	
												#endif	
												break;
											// 바로 display 할것인가 아니면 나중에 ?????	
									#if 0
									case SET_AMPM  :
													 if(Peak.which_AMPM[No_Step_Peaktime]==AM) Peak.which_AMPM[No_Step_Peaktime]=PM;
													 else Peak.which_AMPM[No_Step_Peaktime]=AM;
													 
													LCD_Dsplay_which_AMPM(No_Step_Peaktime); 
												break;		
										// 바로 display 할것인가 아니면 나중에 ?????
									#endif
									case SET_PEAKRATE  : 
													count_peak3--;
													if(count_peak3<0||count_peak3>2) count_peak3=2;
						///							printf("cccc=%d\n",count_peak3);
													switch(count_peak3){
															case 0 :  Peak.which_Peak[No_Step_Peaktime]=0; break;
															case 1 : Peak.which_Peak[No_Step_Peaktime]=1; break;
															case 2 : Peak.which_Peak[No_Step_Peaktime]=2; break;
															default: break;
														}
													LCD_Dsplay_which_peak(No_Step_Peaktime);
												break;
									default : break;
									}
								//LCD_Dsplay_Time_Hour_Minute(Peak.hour[No_Step_Peaktime],Peak.minute[No_Step_Peaktime] );
								//LCD_Dsplay_which_AMPM(No_Step_Peaktime);
								//LCD_Dsplay_which_peak(No_Step_Peaktime);
								//LcdPut_Digit_1(TIMER_SLOT_Digit1,    No_Step_Peaktime+1);   // Display Peaktime slot NO
								break;
												
		case CHANGE_KEY_SHORT:	 
		case CHANGE_KEY_LONG :         // save changed data 		
								Buzzer_Sound_Error();	
				///				printf("Change ...........\n");
								Key_Set_operation = 0; // cmlee    to rotate time month day
								#if 1
								Lcd_Dsp_All_Off_PeakTime_SetUp();
								Attribute.LCD_BitCtrl.SEG40_SETING_TIME_Rate =LCD_NORMAL_DISPLAY_bit ; //  Rate  in Time Section
								Attribute.LCD_BitCtrl.SEG40_SETING_TIME_OFF =LCD_NORMAL_DISPLAY_bit;   
								Attribute.LCD_BitCtrl.SEG40_SETING_TIME_MID =LCD_NORMAL_DISPLAY_bit; 
								Attribute.LCD_BitCtrl.SEG38_SETING_TIME_ON =LCD_NORMAL_DISPLAY_bit; 
								
								System_Parameter_Init(SYSTEM_SETING);
								Lcd_Dsp_All_Off_Time_SetUp(); 
								#if 1
								MINUTE_INIT=(U8)event1.minutes;   
								HOUR_INIT=(U8)event1.hours;   

								RTC_SetTimer(TIME_INIT);
								RTC_Timer_Run();		
								#endif	
								LCD_Display_Home_Menu();
								//LCD_BufferClear(); // cmlee 
								LCD_TIME_2DOT_ON;																		
								LCD_Blink_Attribute(LCD_INVERSE_DISPLAY_bit);
                           				timer_mSecTimerDelete(mSec_SetUp_Time);
								#endif 						 	
								return  EXIT_SET_OPERATION;
								
		default: 				
			break;   // cmlee
	
#endif  // cmlee first #if 	
	}
#if 0   // cmlee

       LCD_Dsplay_Week();  
	   
       if(Time_SetUp_Sqc > SET_DAY)
	{				
					LCD_TIME_2DOT_ON;
					LCD_Dsplay_AM_PM();
				 	LCD_Dsplay_Time_Hour_Minute(event1.hours,event1.minutes  );
       }
#endif		
	return Set_Operation_Mode;
	
}
#endif

#ifdef SET_ONOFFTIMER
void SetUp_Dsp_OnOffTime(void)
{
	U8 hour_temp;

	if(OnOffTimer.timer_onoff[Timer_Channel] == 1)
	{
		hour_temp = OnOffTimer.on_hour[Timer_Channel];
		if (OnOffTimer.on_hour[Timer_Channel] >12 && OnOffTimer.on_hour[Timer_Channel] < 24) hour_temp-=12;
		else if(OnOffTimer.on_hour[Timer_Channel]==24) hour_temp=0;
		LCD_Dsplay_Time_Hour_Minute(hour_temp,OnOffTimer.on_minute[Timer_Channel]   );
		LCD_Dsplay_OnOffTimer_AMPM(Timer_Channel, OnOffTimer.timer_onoff[Timer_Channel]);
	}
	else
	{
		hour_temp = OnOffTimer.off_hour[Timer_Channel];
		if (OnOffTimer.off_hour[Timer_Channel] >12 && OnOffTimer.off_hour[Timer_Channel] < 24) hour_temp-=12;
		else if(OnOffTimer.off_hour[Timer_Channel]==24) hour_temp=0;
		LCD_Dsplay_Time_Hour_Minute(hour_temp,OnOffTimer.off_minute[Timer_Channel]   );
		LCD_Dsplay_OnOffTimer_AMPM(Timer_Channel, OnOffTimer.timer_onoff[Timer_Channel]);
	}
}

void Lcd_Dsp_OnOffTimer_Setup(U8 DspTimer_Channel)	
{	U8 hour_temp;
	//Key_Set_operation=1;
	NOW_COST_UNIT_POUND_OFF;
	NOW_COST_UNIT_JAPAN_OFF;
	NOW_COST_UNIT_EURO_OFF;
	NOW_COST_UNIT_DOLLAR_OFF;

	NOW_COST_IMP_KWH_OFF;
	NOW_COST_K_OFF;
	NOW_COST_Won_OFF;

	NOW_COST_DOT1_OFF;
	NOW_COST_DOT2_OFF;

	LCD_DAY_OFF;
	LCD_MOON_OFF;
	PEAKTIME_START_ON ; 
	LCD_TIME_2DOT_ON;

	if(OnOffTimer.timer_onoff[Timer_Channel] == 1)
	{
		hour_temp = OnOffTimer.on_hour[DspTimer_Channel];
		if (OnOffTimer.on_hour[DspTimer_Channel] >12 && OnOffTimer.on_hour[DspTimer_Channel] < 24) hour_temp-=12;
		else if(OnOffTimer.on_hour[DspTimer_Channel]==24) hour_temp=0;
		LCD_Dsplay_Time_Hour_Minute(hour_temp,OnOffTimer.on_minute[DspTimer_Channel]   );
		LCD_Dsplay_OnOffTimer_AMPM(DspTimer_Channel, OnOffTimer.timer_onoff[Timer_Channel]);
	}
	else
	{
		hour_temp = OnOffTimer.off_hour[DspTimer_Channel];
		if (OnOffTimer.off_hour[DspTimer_Channel] >12 && OnOffTimer.off_hour[DspTimer_Channel] < 24) hour_temp-=12;
		else if(OnOffTimer.off_hour[DspTimer_Channel]==24) hour_temp=0;
		LCD_Dsplay_Time_Hour_Minute(hour_temp,OnOffTimer.off_minute[DspTimer_Channel]   );
		LCD_Dsplay_OnOffTimer_AMPM(DspTimer_Channel, OnOffTimer.timer_onoff[Timer_Channel]);
	}
	
	LCD_Dsplay_OnOff_Timer(DspTimer_Channel);
}

static SET_OPERATION SetUp_OnOffTimer(void)
{
	int i;
	U8 Key  ;   // hour_temp;
	//U8 hour_upper, hour_lower, minute_upper, minute_lower;
	
	Key_Set_operation =1;
	Key = Key_Get();
	
	switch(Key)
	{						
		case SET_KEY_SHORT:							// set key는  좀 더 넓은 범위의   선택 기능    0: 6개의 큰 범위 선택    1: 시작 시간   2: AM PM     3: OFF MID ON  
			///printf("\n SetUp_Peak_Time  set short key 33 ");

			Beep_Oneshort();

			OnOff_Timer_Sqc++;
			if(OnOff_Timer_Sqc>SET_ONOFFTIMER_ONOFF) OnOff_Timer_Sqc=SET_ONOFFTIMER_CHANNEL; 
			
			switch(OnOff_Timer_Sqc){
			case SET_ONOFFTIMER_CHANNEL : 		///	printf("SET_PEAK_MIN\n"); 	
			///printf("\n SetUp_Peak_Time  set short key peak min 44 ");
				#if 0
				LcdPut_Digit_1(TIMER_SLOT_Digit1,    Timer_Channel+1);   // Display Peaktime slot NO
				Set_Lcd_Char_Attribute(TIMER_SLOT_Digit1, LCD_INVERSE_DISPLAY_bit);
				#else
				Set_Lcd_Char_Attribute(TIMER_SLOT_Digit1, LCD_INVERSE_DISPLAY_bit);
				Lcd_Put_Number(RF_Channel, Timer_Channel,2);
				Set_Lcd_Char_Attribute(RF_Channel, LCD_INVERSE_DISPLAY_bit);
				#endif
				SetUp_Dsp_OnOffTime();
				Attribute.LCD_BitCtrl.SEG40_SETING_TIME_OFF=LCD_NORMAL_DISPLAY_bit;
				Attribute.LCD_BitCtrl.SEG38_SETING_TIME_ON=LCD_NORMAL_DISPLAY_bit;
				break;
										
			case SET_ONOFFTIMER_HOUR:   ///     	printf("SET_ONOFFTIMER_HOUR\n"); 
			///printf("\n SetUp_Peak_Time  set short key peak 55 ");
				Set_Lcd_Char_Attribute(TIMER_SLOT_Digit1, LCD_NORMAL_DISPLAY_bit);      // when you push set key, previous state cllear
				Set_Lcd_Char_Attribute(SETING_TIME_Hour_Digit1, LCD_INVERSE_DISPLAY_bit);
				Set_Lcd_Char_Attribute(SETING_TIME_Minute_Digit1, LCD_NORMAL_DISPLAY_bit);
				PEAKTIME_START_ON;
				SetUp_Dsp_OnOffTime();				
				break;		
			case SET_ONOFFTIMER_MINUTE:   ///     	printf("SET_ONOFFTIMER_HOUR\n"); 
			///printf("\n SetUp_Peak_Time  set short key peak 55 ");
				Set_Lcd_Char_Attribute(TIMER_SLOT_Digit1, LCD_NORMAL_DISPLAY_bit);      // when you push set key, previous state cllear
				Set_Lcd_Char_Attribute(SETING_TIME_Hour_Digit1, LCD_NORMAL_DISPLAY_bit);
				Set_Lcd_Char_Attribute(SETING_TIME_Minute_Digit1, LCD_INVERSE_DISPLAY_bit);
				PEAKTIME_START_ON;
				SetUp_Dsp_OnOffTime();				
				break;	
			case SET_ONOFFTIMER_ONOFF:     ///    	printf("SET_ONOFFTIMER_ONOFF\n"); 
										//Lcd_Dsp_THRESHOLD_Setup();  	
			///printf("\n SetUp_Peak_Time  set short key peak rate 66 ");
				Set_Lcd_Char_Attribute(TIMER_SLOT_Digit1, LCD_NORMAL_DISPLAY_bit);      // when you push set key, previous state cllear
				Set_Lcd_Char_Attribute(SETING_TIME_Hour_Digit1, LCD_NORMAL_DISPLAY_bit	);
				Set_Lcd_Char_Attribute(SETING_TIME_Minute_Digit1, 	LCD_NORMAL_DISPLAY_bit);	
				LCD_Dsplay_OnOff_Timer(Timer_Channel);
				break;
			
			default:  					
				OnOff_Timer_Sqc=SET_ONOFFTIMER_HOUR  ; 
				break;    // cmlee 
			}
						
		break;				

		case UP_KEY_SHORT:	
			///printf("\n Peak Time == Down key\n");
			Beep_Oneshort();
			switch(OnOff_Timer_Sqc)
			{
				case SET_ONOFFTIMER_CHANNEL : 
				///	printf("000000\n");
					
					Timer_Channel++;
					if(Timer_Channel>=Max_CHANNEL_ID) Timer_Channel=0;
					#if 0
					LcdPut_Digit_1(TIMER_SLOT_Digit1,    Timer_Channel+1);
					#else
					Lcd_Put_Number(RF_Channel, Timer_Channel + 1,2);
					#endif
					SetUp_Dsp_OnOffTime();					
					LCD_Dsplay_OnOff_Timer(Timer_Channel);
					Attribute.LCD_BitCtrl.SEG40_SETING_TIME_OFF =LCD_NORMAL_DISPLAY_bit; 
					Attribute.LCD_BitCtrl.SEG38_SETING_TIME_ON =LCD_NORMAL_DISPLAY_bit; 
					break;
				case SET_ONOFFTIMER_HOUR : 
					if(OnOffTimer.timer_onoff[Timer_Channel] == 1)
					{
						OnOffTimer.on_hour[Timer_Channel] += 1;
						if(OnOffTimer.on_hour[Timer_Channel] < 0 ||OnOffTimer.on_hour[Timer_Channel] > 24 ) {
							 OnOffTimer.on_hour[Timer_Channel] = 0;
							}
					}
					else
					{
						OnOffTimer.off_hour[Timer_Channel] += 1;
						if(OnOffTimer.off_hour[Timer_Channel] < 0 ||OnOffTimer.off_hour[Timer_Channel] > 24 ) {
							 OnOffTimer.off_hour[Timer_Channel] = 0;
							}
					}

					SetUp_Dsp_OnOffTime();						
					break;
				case SET_ONOFFTIMER_MINUTE : 
					if(OnOffTimer.timer_onoff[Timer_Channel] == 1)
					{
						OnOffTimer.on_minute[Timer_Channel] += 1;
						if(OnOffTimer.on_minute[Timer_Channel] < 0 ||OnOffTimer.on_minute[Timer_Channel] > 59 ) {
						       OnOffTimer.on_minute[Timer_Channel] = 0;
						}
					}
					else
					{
						OnOffTimer.off_minute[Timer_Channel] += 1;
						if(OnOffTimer.off_minute[Timer_Channel] < 0 ||OnOffTimer.off_minute[Timer_Channel] > 59 ) {
						       OnOffTimer.off_minute[Timer_Channel] = 0;
						}
					}

					SetUp_Dsp_OnOffTime();						
					break;
				case SET_ONOFFTIMER_ONOFF  : 

					if(Timer_Sel_onoff)
					{
						OnOffTimer.timer_onoff[Timer_Channel]=1;
						Timer_Sel_onoff=0;
						///printf(" \n 1 OnOffTimer.timer_onoff[Timer_Channel]=%d, Timer_Channel=%d ", (U16)OnOffTimer.timer_onoff[Timer_Channel], (U16)Timer_Channel);
					}
					else
					{
						OnOffTimer.timer_onoff[Timer_Channel]=0;
						Timer_Sel_onoff=1;
						///printf(" \n 2 OnOffTimer.timer_onoff[Timer_Channel]=%d, Timer_Channel=%d ", (U16)OnOffTimer.timer_onoff[Timer_Channel], (U16)Timer_Channel);
					}

					SetUp_Dsp_OnOffTime();
					LCD_Dsplay_OnOff_Timer(Timer_Channel);
					break;
				default : break;
				}
			break;

		case UP_KEY_LONG:	
				#if 1
								Beep_Two();
								System_Parameter_Init(SYSTEM_RESET_INITIALIZE);
								return  EXIT_SET_OPERATION;
								#endif
		case DOWN_KEY_LONG:
						#if 1
								Beep_Two();
								System_Parameter_Init(SYSTEM_RESET_INITIALIZE);
								return  EXIT_SET_OPERATION;
								#endif
		case DOWN_KEY_SHORT:			 
			///printf("\n Peak Time == Up key\n");
			Beep_Oneshort();
			switch(OnOff_Timer_Sqc)
			{
				case SET_ONOFFTIMER_CHANNEL : 
					Timer_Channel--;
					if(Timer_Channel<0 || Timer_Channel > Max_CHANNEL_ID) Timer_Channel=Max_CHANNEL_ID-1;
					#if 0
					LcdPut_Digit_1(TIMER_SLOT_Digit1,    Timer_Channel+1);
					#else
					Lcd_Put_Number(RF_Channel, Timer_Channel + 1,2);
					#endif
					SetUp_Dsp_OnOffTime();	
					LCD_Dsplay_OnOff_Timer(Timer_Channel);
					Attribute.LCD_BitCtrl.SEG40_SETING_TIME_OFF =LCD_NORMAL_DISPLAY_bit; 
					Attribute.LCD_BitCtrl.SEG38_SETING_TIME_ON =LCD_NORMAL_DISPLAY_bit; 					
					break;
				case SET_ONOFFTIMER_HOUR : 
					if(OnOffTimer.timer_onoff[Timer_Channel] == 1)
					{
						OnOffTimer.on_hour[Timer_Channel] -= 1;
						if(OnOffTimer.on_hour[Timer_Channel] < 0 ||OnOffTimer.on_hour[Timer_Channel] > 24 ) {
						 OnOffTimer.on_hour[Timer_Channel] = 24;
						}
					}
					else
					{
						OnOffTimer.off_hour[Timer_Channel] -= 1;
						if(OnOffTimer.off_hour[Timer_Channel] < 0 ||OnOffTimer.off_hour[Timer_Channel] > 24 ) {
						 OnOffTimer.off_hour[Timer_Channel] = 24;
						}
					}
					
					SetUp_Dsp_OnOffTime();					
					break;
				case SET_ONOFFTIMER_MINUTE : 
					if(OnOffTimer.timer_onoff[Timer_Channel] == 1)
					{
						OnOffTimer.on_minute[Timer_Channel] -= 1;
						if(OnOffTimer.on_minute[Timer_Channel] < 0 ||OnOffTimer.on_minute[Timer_Channel] > 59 ) {
						       OnOffTimer.on_minute[Timer_Channel] = 59;
						}
					}
					else
					{
						OnOffTimer.off_minute[Timer_Channel] -= 1;
						if(OnOffTimer.off_minute[Timer_Channel] < 0 ||OnOffTimer.off_minute[Timer_Channel] > 59 ) {
						       OnOffTimer.off_minute[Timer_Channel] = 59;
						}
					}
			  		
					SetUp_Dsp_OnOffTime();
					break;

				case SET_ONOFFTIMER_ONOFF  : 
					if(Timer_Sel_onoff)
					{
						OnOffTimer.timer_onoff[Timer_Channel]=1;
						Timer_Sel_onoff=0;
						///printf(" \n 3 OnOffTimer.timer_onoff[Timer_Channel]=%d, Timer_Channel=%d ", (U16)OnOffTimer.timer_onoff[Timer_Channel], (U16)Timer_Channel);
					}
					else
					{
						OnOffTimer.timer_onoff[Timer_Channel]=0;
						Timer_Sel_onoff=1;
						///printf(" \n 4 OnOffTimer.timer_onoff[Timer_Channel]=%d, Timer_Channel=%d ", (U16)OnOffTimer.timer_onoff[Timer_Channel], (U16)Timer_Channel);
					}
					SetUp_Dsp_OnOffTime();
					LCD_Dsplay_OnOff_Timer(Timer_Channel);
					break;
				default : break;
				}
			break;
												
		case CHANGE_KEY_SHORT:	 
		case CHANGE_KEY_LONG :         // save changed data 		
			Buzzer_Sound_Error();	
			///printf("\n Change ...........\n");
			Key_Set_operation = 0; // cmlee    to rotate time month day
			#if 1
			Lcd_Dsp_All_Off_PeakTime_SetUp();
			Attribute.LCD_BitCtrl.SEG40_SETING_TIME_OFF =LCD_NORMAL_DISPLAY_bit;   
			Attribute.LCD_BitCtrl.SEG38_SETING_TIME_ON =LCD_NORMAL_DISPLAY_bit; 
			
			for(i = 0; i < Max_CHANNEL_ID; i++)
			{
				event1.on_hour[i] = (U8)OnOffTimer.on_hour[i];
				event1.on_minute[i] = (U8)OnOffTimer.on_minute[i]; 
				event1.off_hour[i] = (U8)OnOffTimer.off_hour[i];
				event1.off_minute[i] = (U8)OnOffTimer.off_minute[i]; 
				event1.onoff_timer[i] = (U8)OnOffTimer.timer_onoff[i];
			}
			
			System_Parameter_Init(SYSTEM_SETING);
			Lcd_Dsp_All_Off_Time_SetUp(); 
			#if 1
			MINUTE_INIT=(U8)event1.minutes;   
			HOUR_INIT=(U8)event1.hours;   

			RTC_SetTimer(TIME_INIT);
			RTC_Timer_Run();		
			#endif	
			LCD_Display_Home_Menu();
			LCD_TIME_2DOT_ON;																		
			LCD_Blink_Attribute(LCD_INVERSE_DISPLAY_bit);
       		timer_mSecTimerDelete(mSec_SetUp_Time);
			
			#endif 						 	
			return  EXIT_SET_OPERATION;
								
		default: 				
			break;
	
	}

	return Set_Operation_Mode;
	
}
#endif

//=========================================================================
//U8 No_Step;                 //cmlee
//U8 Billing_SetUp_Sqc;	   // cmlee
U8 peak_power_value_pos ;	         // cmlee
static SET_OPERATION SetUp_Moment_Peak_Power(void)    //============================
{
	 U8 Key;   //, temp_location;
	 //U16 temp_basic, temp_threshold; 
	 U32 temp_peak_power;
	
	Key_Set_operation =1;     // cmlee  to rotate
	Key = Key_Get();
	switch(Key)
	{						
		case MENU_KEY_SHORT:
							Beep_Oneshort();
								if(peak_power_value_pos < 0 || peak_power_value_pos>=6)peak_power_value_pos=0;
								peak_power_value_pos++;
								switch(peak_power_value_pos)
									{
									 case 1 : //  temp_location = Now_COST_Digit1; 
											Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_INVERSE_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
								 			break;
								 	case 2 : //   temp_location = Now_COST_Digit2; 
											Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_INVERSE_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
								 			break;
								 	case 3 : //    temp_location = Now_COST_Digit3; 
											Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_INVERSE_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
								 			break;
								  	case 4 : //  temp_location = Now_COST_Digit4; 
								 			Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_INVERSE_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
								 			break;
									 case 5 : //temp_location = Now_COST_Digit5; break;
											Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_INVERSE_DISPLAY_bit );
								 			break;
							default : 
											Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
									break;
									}
								//	money_pos++;
								
						break;
		case SET_KEY_SHORT:   
						Beep_Oneshort();
						Lcd_Dsp_Moment_Power_Max_Setup(); 
						break;				

		case DOWN_KEY_LONG:	
			#if 1
								Beep_Two();
								System_Parameter_Init(SYSTEM_RESET_INITIALIZE);
								return  EXIT_SET_OPERATION;
								#endif
		case DOWN_KEY_SHORT:			
								Beep_Oneshort();
								
											temp_peak_power = event1.alarm_moment_peak;		
											switch(peak_power_value_pos)
												{
												
												case 1 : 
														temp_peak_power-=1;
														if(temp_peak_power < 0 || temp_peak_power > 65535 ) temp_peak_power =event1.alarm_moment_peak;	
														else event1.alarm_moment_peak=temp_peak_power;
														break;
												case 2 : 
														temp_peak_power-=10;
														if(temp_peak_power < 0 || temp_peak_power > 65535 ) temp_peak_power =event1.alarm_moment_peak;	
														else event1.alarm_moment_peak=temp_peak_power;
														break;
												case 3 : 
														temp_peak_power-=100;
														if(temp_peak_power < 0 || temp_peak_power > 65535 ) temp_peak_power =event1.alarm_moment_peak;	
														else event1.alarm_moment_peak=temp_peak_power;
														break;
												case 4 : 
														temp_peak_power-=1000;
														if(temp_peak_power < 0 || temp_peak_power > 65535 ) temp_peak_power =event1.alarm_moment_peak;	
														else event1.alarm_moment_peak=temp_peak_power;
														break;
												case 5 : 
														temp_peak_power-=10000;
														if(temp_peak_power < 0 || temp_peak_power > 65535 ) temp_peak_power =event1.alarm_moment_peak;	
														else event1.alarm_moment_peak=temp_peak_power;
														break;
												default:  break; 
												}
										Lcd_Dsp_Moment_Power_Max_Setup(); 
					break;

		case UP_KEY_LONG:		
			#if 1
								Beep_Two();
								System_Parameter_Init(SYSTEM_RESET_INITIALIZE);
								return  EXIT_SET_OPERATION;
								#endif
		case UP_KEY_SHORT:			 
								Beep_Oneshort();	
								//if(flat_money_pos >=6) {
								
								//Lcd_Dsp_Flat_Setup(); 
								
								//}
	   					///	printf("000000\n");
											temp_peak_power = event1.alarm_moment_peak;		
											switch(peak_power_value_pos)
												{
												
												case 1 : 
														temp_peak_power+=1;
														if(temp_peak_power < 0 || temp_peak_power > 65535 ) temp_peak_power =event1.alarm_moment_peak;	
														else event1.alarm_moment_peak=temp_peak_power;
														break;
												case 2 : 
														temp_peak_power+=10;
														if(temp_peak_power < 0 || temp_peak_power > 65535 ) temp_peak_power =event1.alarm_moment_peak;	
														else event1.alarm_moment_peak=temp_peak_power;
														break;
												case 3 : 
														temp_peak_power+=100;
														if(temp_peak_power < 0 || temp_peak_power > 65535 ) temp_peak_power =event1.alarm_moment_peak;	
														else event1.alarm_moment_peak=temp_peak_power;
														break;
												case 4 : 
														temp_peak_power+=1000;
														if(temp_peak_power < 0 || temp_peak_power > 65535 ) temp_peak_power =event1.alarm_moment_peak;	
														else event1.alarm_moment_peak=temp_peak_power;
														break;
												case 5 : 
														temp_peak_power+=10000;
														if(temp_peak_power < 0 || temp_peak_power > 65535 ) temp_peak_power =event1.alarm_moment_peak;	
														else event1.alarm_moment_peak=temp_peak_power;
														break;
												default:  break; 
												}
									Lcd_Dsp_Moment_Power_Max_Setup(); 
										
									
								//LCD_Dsplay_Time_Hour_Minute(Peak.hour[No_Step_Peaktime],Peak.minute[No_Step_Peaktime] );
								//LCD_Dsplay_which_AMPM(No_Step_Peaktime);
								//LCD_Dsplay_which_peak(No_Step_Peaktime);
								//LcdPut_Digit_1(TIMER_SLOT_Digit1,    No_Step_Peaktime+1);   // Display Peaktime slot NO

								break;
												
		case CHANGE_KEY_SHORT:	 
		case CHANGE_KEY_LONG :         // save changed data 		
								Buzzer_Sound_Error();	
		///						printf("Change ...........\n");
								Key_Set_operation = 0; // cmlee    to rotate time month day
								if(event1.alarm_moment_peak < 0 || event1.alarm_moment_peak > 65535 )event1.alarm_moment_peak=65535;
								
								#if 1
								System_Parameter_Init(SYSTEM_SETING);
								Lcd_Dsp_All_Off_Time_SetUp(); 
								#if 1
								RTC_SetTimer(TIME_INIT);
								RTC_Timer_Run();		
								#endif	

								Lcd_Dsp_All_Off_Time_SetUp(); 
								Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
								Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
								Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
								Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
								Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
								//LCD_BufferClear(); // cmlee 
								LCD_TIME_2DOT_ON;																		
								LCD_Blink_Attribute(LCD_INVERSE_DISPLAY_bit);
                           				timer_mSecTimerDelete(mSec_SetUp_Time);
								LCD_Display_Home_Menu();  // cmlee		
								#endif 	
								return  EXIT_SET_OPERATION;
								
		default: 					break;   // cmlee
	

	}
#if 0   // cmlee

       LCD_Dsplay_Week();  
	   
       if(Time_SetUp_Sqc > SET_DAY)
	{				
					LCD_TIME_2DOT_ON;
					LCD_Dsplay_AM_PM();
				 	LCD_Dsplay_Time_Hour_Minute(event1.hours,event1.minutes  );
       }
#endif		
	return Set_Operation_Mode;

}

#if 1
//=========================================================================
//U8 No_Step;                 //cmlee
//U8 Billing_SetUp_Sqc;	   // cmlee
U8 month_target_value_pos ;	         // cmlee
static SET_OPERATION SetUp_Month_Target_Power(void)    //============================
{
	 U8 Key;   //, temp_location;
	// U16 temp_basic, temp_threshold; 
	 U32 temp_month_target_power;   // K 단위   목표전력량  월간 이 므로 
	
	Key_Set_operation =1;     // cmlee  to rotate
	Key = Key_Get();
	switch(Key)
	{						
		case MENU_KEY_SHORT:
							Beep_Oneshort();
								if(month_target_value_pos < 0 || month_target_value_pos>=6)month_target_value_pos=0;
								month_target_value_pos++;
								switch(month_target_value_pos)
									{
									 case 1 : //  temp_location = Now_COST_Digit1; 
											Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_INVERSE_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
								 			break;
								 	case 2 : //   temp_location = Now_COST_Digit2; 
											Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_INVERSE_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
								 			break;
								 	case 3 : //    temp_location = Now_COST_Digit3; 
											Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_INVERSE_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
								 			break;
								  	case 4 : //  temp_location = Now_COST_Digit4; 
								 			Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_INVERSE_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
								 			break;
									 case 5 : //temp_location = Now_COST_Digit5; break;
											Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_INVERSE_DISPLAY_bit );
								 			break;
							default : 
											Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
											Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
									break;
									}
								//	money_pos++;
								
						break;
		case SET_KEY_SHORT:   
						Beep_Oneshort();
						Lcd_Dsp_Month_Target_Power(); 
						break;				

		case DOWN_KEY_LONG:	
			#if 1
								Beep_Two();
								System_Parameter_Init(SYSTEM_RESET_INITIALIZE);
								return  EXIT_SET_OPERATION;
								#endif
		case DOWN_KEY_SHORT:			
								Beep_Oneshort();
								
											temp_month_target_power = event1.alarm_month_target;		
											switch(month_target_value_pos)
												{
												
												case 1 : 
														temp_month_target_power-=1;
														if(temp_month_target_power < 0 || temp_month_target_power > 65535 ) temp_month_target_power =event1.alarm_month_target;	
														else event1.alarm_month_target=temp_month_target_power;
														break;
												case 2 : 
														temp_month_target_power-=10;
														if(temp_month_target_power < 0 || temp_month_target_power > 65535 ) temp_month_target_power =event1.alarm_month_target;	
														else event1.alarm_month_target=temp_month_target_power;
														break;
												case 3 : 
														temp_month_target_power-=100;
														if(temp_month_target_power < 0 || temp_month_target_power > 65535 ) temp_month_target_power =event1.alarm_month_target;	
														else event1.alarm_month_target=temp_month_target_power;
														break;
												case 4 : 
														temp_month_target_power-=1000;
														if(temp_month_target_power < 0 || temp_month_target_power > 65535 ) temp_month_target_power =event1.alarm_month_target;	
														else event1.alarm_month_target=temp_month_target_power;
														break;
												case 5 : 
														temp_month_target_power-=10000;
														if(temp_month_target_power < 0 || temp_month_target_power > 65535 ) temp_month_target_power =event1.alarm_month_target;	
														else event1.alarm_month_target=temp_month_target_power;
														break;
												default:  break; 
												}
										Lcd_Dsp_Month_Target_Power(); 
					break;

		case UP_KEY_LONG:		
			#if 1
								Beep_Two();
								System_Parameter_Init(SYSTEM_RESET_INITIALIZE);
								return  EXIT_SET_OPERATION;
								#endif
		case UP_KEY_SHORT:			 
								Beep_Oneshort();	
								//if(flat_money_pos >=6) {
								
								//Lcd_Dsp_Flat_Setup(); 
								
								//}
	   					///	printf("000000\n");
											temp_month_target_power = event1.alarm_month_target;		
											switch(month_target_value_pos)
												{
												
												case 1 : 
														temp_month_target_power+=1;
														if(temp_month_target_power < 0 || temp_month_target_power > 65535 ) temp_month_target_power =event1.alarm_month_target;	
														else event1.alarm_month_target=temp_month_target_power;
														break;
												case 2 : 
														temp_month_target_power+=10;
														if(temp_month_target_power < 0 || temp_month_target_power > 65535 ) temp_month_target_power =event1.alarm_month_target;	
														else event1.alarm_month_target=temp_month_target_power;
														break;
												case 3 : 
														temp_month_target_power+=100;
														if(temp_month_target_power < 0 || temp_month_target_power > 65535 ) temp_month_target_power =event1.alarm_month_target;	
														else event1.alarm_month_target=temp_month_target_power;
														break;
												case 4 : 
														temp_month_target_power+=1000;
														if(temp_month_target_power < 0 || temp_month_target_power > 65535 ) temp_month_target_power =event1.alarm_month_target;	
														else event1.alarm_month_target=temp_month_target_power;
														break;
												case 5 : 
														temp_month_target_power+=10000;
														if(temp_month_target_power < 0 || temp_month_target_power > 65535 ) temp_month_target_power =event1.alarm_month_target;	
														else event1.alarm_month_target=temp_month_target_power;
														break;
												default:  break; 
												}
									Lcd_Dsp_Month_Target_Power(); 
										
									
								//LCD_Dsplay_Time_Hour_Minute(Peak.hour[No_Step_Peaktime],Peak.minute[No_Step_Peaktime] );
								//LCD_Dsplay_which_AMPM(No_Step_Peaktime);
								//LCD_Dsplay_which_peak(No_Step_Peaktime);
								//LcdPut_Digit_1(TIMER_SLOT_Digit1,    No_Step_Peaktime+1);   // Display Peaktime slot NO

								break;
												
		case CHANGE_KEY_SHORT:	 
		case CHANGE_KEY_LONG :         // save changed data 		
								Buzzer_Sound_Error();	
		///						printf("Change ...........\n");
								Key_Set_operation = 0; // cmlee    to rotate time month day
								if(event1.alarm_month_target < 0 || event1.alarm_month_target > 65535 )event1.alarm_month_target=65535;
								
								#if 1
								System_Parameter_Init(SYSTEM_SETING);
								Lcd_Dsp_All_Off_Time_SetUp(); 
								#if 1
								RTC_SetTimer(TIME_INIT);
								RTC_Timer_Run();		
								#endif	

								Lcd_Dsp_All_Off_Time_SetUp(); 
								Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
								Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
								Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
								Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
								Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
								//LCD_BufferClear(); // cmlee 
								LCD_TIME_2DOT_ON;																		
								LCD_Blink_Attribute(LCD_INVERSE_DISPLAY_bit);
                           				timer_mSecTimerDelete(mSec_SetUp_Time);
								LCD_Display_Home_Menu();  // cmlee		
								#endif 	
								return  EXIT_SET_OPERATION;
								
		default: 					break;   // cmlee
	

	}
#if 0   // cmlee

       LCD_Dsplay_Week();  
	   
       if(Time_SetUp_Sqc > SET_DAY)
	{				
					LCD_TIME_2DOT_ON;
					LCD_Dsplay_AM_PM();
				 	LCD_Dsplay_Time_Hour_Minute(event1.hours,event1.minutes  );
       }
#endif		
	return Set_Operation_Mode;

}
#endif
//=====================================================================

#define SEND_TIME  					2  // RF 송신 주기 1초  
#define PARING_EXPIRED_TIME  		50  // RF 송신 주기 1초  
#define RF_RADIO_NOT_SEND_NUM  	2  // 1 초 주기 로   2회   송신 출력 금지 전송 

#define DEFAULT_AC_VOLTAGE  220
#define SET_MAX_VOLTAGE	400

#if 0
code	U16 Table_CT_Sensor_AC_Voltage[SET_MAX_VOLTAGE+1]= { 100, // 0
//                                 1      2     3      4     5     6     7       8     9      10      11
					110, 115, 120, 127, 200, 210, 220, 230, 240, 265,   277
};
///#else
code	U16 Table_CT_Sensor_AC_Voltage[SET_MAX_VOLTAGE+1]= { 100, 102, 104, 106, 110, 112, 114, 116, 120, 122, 124, 126, 
															    200, 202, 204, 208, 210, 212, 214, 216, 218, 220, 220, 221, 
															    222, 223, 224, 225, 227, 230, 232, 235, 240, 242, 245, 250, 
															    252, 255, 260, 262, 265, 270, 272, 275, 277	};
#endif

extern void LCD_Refresh(void);
static SET_OPERATION Pairing_Setup(void)
{
	U8 Key;  // i;
	U8 Rf_Rx_Command=0;	
	
//	static U8 Pairing_Channel_ID=0;
	  
	Key = Key_Get();
	
	switch(Set_Operation_Paring_State)
	{
          case TOP_OPERATION_PARING: 
		  					
				Lcd_Put_Number(RF_Channel, Display_Channel, 2);	

			if( Rf_Command_Action_Proc( &Rf_Rx_Command)==NEXT){        // 1)  RF 수신 Command 가  있고  Display_Channel
			
				if(Rf_Rx_Command==PAIRING_CMD)                                      // 2) PAIRING 요청  Command 이면 
				{
					//RF_Send_Command(RF_RADIO_NOT_SEND_CMD, Display_Channel, 0);  // 3) ACK 전송 ( 무선 송출 금지 컨멘드 )
					
					Set_Operation_Paring_State++;
					
					Sec_Pairing_SetTime= timerSecHandleAssign();  							
					timerSecTimerSet(Sec_Pairing_SetTime, SEND_TIME); 	//RF 송신 주기 1초  
					timerSecTimerSet(Sec_Pairing_Failed_SetTime, PARING_EXPIRED_TIME); 	//Paring Time

					TempCnt=0;

					//printf("\n Rf_Rx_Command==PAIRING_CMD");
				}
			}
			if(timeSecTimeExpired(Sec_Pairing_Failed_SetTime)==TIMER_EXPIRED)  // 
			{  						
				Set_Operation_Paring_State=PARING_EXIT;
				return   PAIRING;
			}
			break;

          case RF_RADIO_NOT_SET: 
								
			if(timeSecTimeExpired(Sec_Pairing_SetTime)==TIMER_EXPIRED){  	// 1 Sec 마다  PAIRING_CMD 를 전송한다 
			
				RF_Send_Command(RF_RADIO_NOT_SEND_CMD, Display_Channel, 0);  // 3) ACK 전송 ( 무선 송출 금지 컨멘드 )
				
				timerSecTimerSet(Sec_Pairing_SetTime, 1); 	//RF 송신 주기 1초  
									
				TempCnt++; 
				
				if(TempCnt> RF_RADIO_NOT_SEND_NUM){
									Set_Operation_Paring_State++;
									timerSecTimerSet(Sec_Pairing_SetTime, 0); 	//RF 송신 주기 1초  
									timerSecTimerSet(Sec_Pairing_Failed_SetTime, PARING_EXPIRED_TIME); 	//Paring Time
				}						
			}
			
			if(timeSecTimeExpired(Sec_Pairing_Failed_SetTime)==TIMER_EXPIRED)  // 
			{  						
				Set_Operation_Paring_State=PARING_EXIT;
				return   PAIRING;
			}
							
			break;
				
          case PARING_ID_SET: 
				
	 		if( Rf_Command_Action_Proc( &Rf_Rx_Command)==NEXT){   		// 1)  RF 수신 Command 가  있고 

				if(Rf_Rx_Command==ACK)                     		// 2) ACK 이면  (송신 출력 금지  Command )
				{
					RF_Send_Command(VOLTAGE_SETING_CMD, Display_Channel, CT_Sensor_AC_Voltage);
						
					Set_Operation_Paring_State=PARING_VOLTEGE_SET;

					NOW_ENG_VOLTAGE_ON;
					NOW_ENG_V_ON;
					NOW_ENG_W_OFF;
					
					Set_AC_Voltage=AUTO_AC_VOLTAGE;///DEFAULT_AC_VOLTAGE;
					
					CT_Sensor_AC_Voltage = Set_AC_Voltage;//Table_CT_Sensor_AC_Voltage [Set_AC_Voltage] ;
					#if 0
					 Lcd_Put_Number(Now_Energy_Digit1, (U32)CT_Sensor_AC_Voltage, 5); 
					#else //Added  AUTO Voltate for PIT Type
					 LCD_Put_String(Now_Energy_Digit5, " AoEo", 5);
					 LCDMap.LCD_BitCtrl.SEG4_DIGIT3_4B =0; 
					 LCDMap.LCD_BitCtrl.SEG4_DIGIT3_4G =0;
					 LCDMap.LCD_BitCtrl.SEG6_DIGIT1_6B = 0;
					 LCDMap.LCD_BitCtrl.SEG5_DIGIT2_5A = 0;
					 #endif
					 
					//printf("\n v");
					TempCnt=1;
					timerSecTimerSet(Sec_Pairing_SetTime, SEND_TIME); 	//RF 송신 주기 1초  
					
					timerSecTimerDelete(Sec_Pairing_Failed_SetTime);
					
					return Set_Operation_Mode;							
				}					
	 		}   
			
			if(timeSecTimeExpired(Sec_Pairing_SetTime)==TIMER_EXPIRED)  // 1 Sec 마다  PAIRING_CMD 를 전송한다 
			{  						
				RF_Send_Command(PAIRING_CMD, Display_Channel, 0);
				
				timerSecTimerSet(Sec_Pairing_SetTime, SEND_TIME); 	//RF 송신 주기 1초  
					
				//printf("\n Send id");
			}
			
			if(timeSecTimeExpired(Sec_Pairing_Failed_SetTime)==TIMER_EXPIRED)  // 
			{  						
				Set_Operation_Paring_State=PARING_EXIT;
				return   PARING_EXIT;
			}
			break;
	
          case PARING_VOLTEGE_SET: 
		  	
				switch(Key)
				{	
					case UP_KEY_LONG:
					case UP_KEY_SHORT:		
									Beep_Oneshort();

									if(++Set_AC_Voltage>SET_MAX_VOLTAGE)Set_AC_Voltage=0;
									
									CT_Sensor_AC_Voltage= Set_AC_Voltage;///Table_CT_Sensor_AC_Voltage [Set_AC_Voltage];
									

									timerSecTimerSet(Sec_Pairing_SetTime, 0); 	//RF 송신 주기 1초  

									#if 0
									 Lcd_Put_Number(Now_Energy_Digit1, (U32)CT_Sensor_AC_Voltage, 5); 
									#else //Added  AUTO Voltate for PIT Type
									if(Set_AC_Voltage == AUTO_AC_VOLTAGE) // AUTO => Used PIT Voltage
									{
										LCD_Put_String(Now_Energy_Digit5, " AoEo", 5);
										LCDMap.LCD_BitCtrl.SEG4_DIGIT3_4B =0; 
										LCDMap.LCD_BitCtrl.SEG4_DIGIT3_4G =0;
										LCDMap.LCD_BitCtrl.SEG6_DIGIT1_6B = 0;
										LCDMap.LCD_BitCtrl.SEG5_DIGIT2_5A = 0;
									}
									 else
									 Lcd_Put_Number(Now_Energy_Digit1, (U32)CT_Sensor_AC_Voltage, 5); 
									 #endif
									
									TempCnt=1;	
									break;

					case DOWN_KEY_LONG:		
					case DOWN_KEY_SHORT:		
									Beep_Oneshort();

									if(Set_AC_Voltage==0)Set_AC_Voltage=SET_MAX_VOLTAGE;
									else if(--Set_AC_Voltage<=0)Set_AC_Voltage=SET_MAX_VOLTAGE;

									CT_Sensor_AC_Voltage= Set_AC_Voltage;///Table_CT_Sensor_AC_Voltage [Set_AC_Voltage];
									

									timerSecTimerSet(Sec_Pairing_SetTime, 0); 	//RF 송신 주기 1초  
									
									#if 0
									 Lcd_Put_Number(Now_Energy_Digit1, (U32)CT_Sensor_AC_Voltage, 5); 
									#else //Added  AUTO Voltate for PIT Type
									if(Set_AC_Voltage == AUTO_AC_VOLTAGE) // AUTO => Used PIT Voltage
									{
										 LCD_Put_String(Now_Energy_Digit5, " AoEo", 5);
										LCDMap.LCD_BitCtrl.SEG4_DIGIT3_4B =0; 
										LCDMap.LCD_BitCtrl.SEG4_DIGIT3_4G =0;
										LCDMap.LCD_BitCtrl.SEG6_DIGIT1_6B = 0;
										LCDMap.LCD_BitCtrl.SEG5_DIGIT2_5A = 0;
									}
									 else
									 Lcd_Put_Number(Now_Energy_Digit1, (U32)CT_Sensor_AC_Voltage, 5); 
									 #endif

									TempCnt=1;	
									break;
					default : 		break;
				}
				
		 		if( Rf_Command_Action_Proc( &Rf_Rx_Command)==NEXT){   		// 1)  RF 수신 Command 가  있고 

					if(Rf_Rx_Command==VOLTAGE_SETING_CMD)                     		// 2) ACK 이면  (송신 출력 금지  Command )
					{
						if(Get_Rf_Receive_Data() == CT_Sensor_AC_Voltage)TempCnt=0;	
						else TempCnt=1;				
					}					
		 		}   

				if( timeSecTimeExpired(Sec_Pairing_SetTime)==TIMER_EXPIRED &&TempCnt)  // 1 Sec 마다  PAIRING_CMD 를 전송한다 
				{  												
					RF_Send_Command(VOLTAGE_SETING_CMD, Display_Channel, CT_Sensor_AC_Voltage);
					timerSecTimerSet(Sec_Pairing_SetTime, SEND_TIME); 	//RF 송신 주기 1초  
					
				}
				
				break;
				
          case PARING_EXIT: 
				
			if(timeSecTimeExpired(Sec_Pairing_SetTime)==TIMER_EXPIRED)  // 1 Sec 마다  PAIRING_CMD 를 전송한다 
			{  						
					
				RF_Send_Command(RF_RADIO_START_CMD, Display_Channel, 0);
				
				timerSecTimerSet(Sec_Pairing_SetTime, 1); 	//RF 송신 주기 1초  
				
				if(++TempCnt>2){
								timerSecTimerDelete(Sec_Pairing_SetTime);		
								timerSecTimerDelete(Sec_Pairing_Failed_SetTime);

								return   EXIT_SET_OPERATION;
				}
			}
			
			if(timeSecTimeExpired(Sec_Pairing_Failed_SetTime)==TIMER_EXPIRED)  // 
			{  						
				timerSecTimerDelete(Sec_Pairing_SetTime);
				timerSecTimerDelete(Sec_Pairing_Failed_SetTime);
				LCD_Display_Home_Menu();
				
				return   EXIT_SET_OPERATION;
			}
			break;
		default :   break;   // cmlee
	}

	
	switch(Key)
	{						
		case CHANGE_KEY_LONG:       //   0x02 | 0x10 | 0x20 =0x32
		case CHANGE_KEY_SHORT:	   // 0x02	
			Beep_Oneshort();  

			LCD_Refresh();

			event1.AC_voltage[Display_Channel-1] = Set_AC_Voltage; // save voltage index

			System_Parameter_Init(SYSTEM_SETING);

			//printf("aaaaaa %d, %d", (U16)event1.AC_voltage[Display_Channel-1], (U16)Set_AC_Voltage);
			
			if(Set_Operation_Paring_State==PARING_VOLTEGE_SET|| Key==CHANGE_KEY_LONG ||(Set_Operation_Paring_State==PARING_VOLTEGE_SET&& Key==CHANGE_KEY_SHORT))
				{
			  	//for(i=0;i<10;i++)

				RF_Send_Command(RF_RADIO_START_CMD, Display_Channel, 0);
				timerSecTimerSet(Sec_Pairing_SetTime, SEND_TIME); 	//RF 송신 주기 1초  	
				LCD_Display_Home_Menu();
										
				TempCnt=0;
				Set_Operation_Paring_State=PARING_EXIT;
				//RF_Send_Command(RF_RADIO_START_CMD, Display_Channel, 0); //
			}
			#if 1
			else {    // cmlee abnormal state 
				timerSecTimerSet(Sec_Pairing_Failed_SetTime, 0); 	//RF 송신 주기 1초  	
				LCD_Display_Home_Menu();
				TempCnt=0;
				//return  PAIRING;
				
				}   // cmlee end
			#endif
			Key_Set_operation = 0; // cmlee    to rotate time month day
			Set_Operation_Paring_State=PARING_EXIT;   // when push change key, always change to  previous state   ===> have to check
			//LCD_BufferClear(); // cmlee 
			//return  EXIT_SET_OPERATION;   // cmlee
		default : 		break; // cmlee	
	}
	return Set_Operation_Mode;
}

/*
*********************************************************************************************************
*                                                                   Setup_Operation
*
* Description:      Proximity sensor 입력의 로직이 High에서 Low로 혹은 Low에서 High로 변하였는지를 Check 하여 반환 하는 함수 
*
*
*
* Arguments  :    Check 할 Proximity Sensor 종류 
*                    
*
* Returns    :     변화 정보 
*                 
*********************************************************************************************************
*/
#ifdef SET_CRT_VOLTAGE
U16 Get_Setted_Voltage(U8 ID)
{
	return event1.AC_voltage[ID-1];
}


static SET_OPERATION SetUp_CRT_Voltage(void)
{
	U8 Key;
	  
	Key = Key_Get();
	
	switch(Key)
	{	
		case UP_KEY_LONG:	
			#if 1
								Beep_Two();
								System_Parameter_Init(SYSTEM_RESET_INITIALIZE);
								return  EXIT_SET_OPERATION;
								#endif
		case UP_KEY_SHORT:		
						Beep_Oneshort();

						if(++Set_AC_Voltage>SET_MAX_VOLTAGE)Set_AC_Voltage=0;
						
						CT_Sensor_AC_Voltage= Set_AC_Voltage;///Table_CT_Sensor_AC_Voltage [Set_AC_Voltage];
						
						#if 0
						 Lcd_Put_Number(Now_Energy_Digit1, (U32)CT_Sensor_AC_Voltage, 5); 
						#else //Added  AUTO Voltate for PIT Type
						if(Set_AC_Voltage == AUTO_AC_VOLTAGE)
						{
							 LCD_Put_String(Now_Energy_Digit5, " AoEo", 5);
							LCDMap.LCD_BitCtrl.SEG4_DIGIT3_4B =0; 
							LCDMap.LCD_BitCtrl.SEG4_DIGIT3_4G =0;
							LCDMap.LCD_BitCtrl.SEG6_DIGIT1_6B = 0;
							LCDMap.LCD_BitCtrl.SEG5_DIGIT2_5A = 0;
						}
						 else
						 Lcd_Put_Number(Now_Energy_Digit1, (U32)CT_Sensor_AC_Voltage, 5); 
						 #endif
						
						break;

		case DOWN_KEY_LONG:	
			#if 1
								Beep_Two();
								System_Parameter_Init(SYSTEM_RESET_INITIALIZE);
								return  EXIT_SET_OPERATION;
								#endif
		case DOWN_KEY_SHORT:		
						Beep_Oneshort();

						if(Set_AC_Voltage==0)Set_AC_Voltage=SET_MAX_VOLTAGE;
						else if(--Set_AC_Voltage<=0)Set_AC_Voltage=SET_MAX_VOLTAGE;

						CT_Sensor_AC_Voltage= Set_AC_Voltage;///Table_CT_Sensor_AC_Voltage [Set_AC_Voltage];
				
						#if 0
						 Lcd_Put_Number(Now_Energy_Digit1, (U32)CT_Sensor_AC_Voltage, 5); 
						#else //Added  AUTO Voltate for PIT Type
						if(Set_AC_Voltage == AUTO_AC_VOLTAGE)
						{
							 LCD_Put_String(Now_Energy_Digit5, " AoEo", 5);
							LCDMap.LCD_BitCtrl.SEG4_DIGIT3_4B =0; 
							LCDMap.LCD_BitCtrl.SEG4_DIGIT3_4G =0;
							LCDMap.LCD_BitCtrl.SEG6_DIGIT1_6B = 0;
							LCDMap.LCD_BitCtrl.SEG5_DIGIT2_5A = 0; 
						}
						 else
						 Lcd_Put_Number(Now_Energy_Digit1, (U32)CT_Sensor_AC_Voltage, 5); 
						 #endif

						break;
		default : 		break;
	}

	
	switch(Key)
	{						
		case CHANGE_KEY_LONG:
		case CHANGE_KEY_SHORT:
			Beep_Oneshort();  

			LCD_Refresh();
			Key_Set_operation = 0;

			event1.AC_voltage[Display_Channel-1] = Set_AC_Voltage;
			
			System_Parameter_Init(SYSTEM_SETING);
			Lcd_Dsp_All_Off_Time_SetUp(); 

			RTC_SetTimer(TIME_INIT);
			RTC_Timer_Run();		


			Lcd_Dsp_All_Off_Time_SetUp(); 
			Set_Lcd_Char_Attribute(Now_COST_Digit1, LCD_NORMAL_DISPLAY_bit );
			Set_Lcd_Char_Attribute(Now_COST_Digit2, LCD_NORMAL_DISPLAY_bit );
			Set_Lcd_Char_Attribute(Now_COST_Digit3, LCD_NORMAL_DISPLAY_bit );
			Set_Lcd_Char_Attribute(Now_COST_Digit4, LCD_NORMAL_DISPLAY_bit );
			Set_Lcd_Char_Attribute(Now_COST_Digit5, LCD_NORMAL_DISPLAY_bit );
			LCD_TIME_2DOT_ON;																		
			LCD_Blink_Attribute(LCD_INVERSE_DISPLAY_bit);
			LCD_Display_Home_Menu();

			return  EXIT_SET_OPERATION;
			
		default : 		break;
	}
	return Set_Operation_Mode;
}
#endif


OPERATION_MODE Setup_Operation(void)
{  	

	switch(Set_Operation_Mode)
	{

		case TOP_OPERATION:			Set_Operation_Mode = Select_Set_Operation();  	break;
    
		case TIME_SET:				Set_Operation_Mode = SetUp_Time_Set();			break;     // C1

		case BILLING_RATE:			Set_Operation_Mode = SetUp_Billing_System();     // cmlee       C2
									// printf("   bbb");
									break;		
		case NORMAL_RATE:			
									Set_Operation_Mode = SetUp_flat_Rate();
									break;
#ifdef SET_ONOFFTIMER									
		case SET_TIMER_ONOFF :
									Set_Operation_Mode = SetUp_OnOffTimer();
									break;
#endif

#ifdef SET_CRT_VOLTAGE
		case SET_CRT_VTG:
									Set_Operation_Mode = SetUp_CRT_Voltage();
									break;
#endif

#if 1   // 판매 
		case BILL_INPUT:				Set_Operation_Mode = SetUp_Billing_Rate();        //C3
									break;
#endif		
#if 0  // cmlee NOW  for insertion of time slot & peak rate
		case SET_PEAK_TIME : 		
									Set_Operation_Mode = SetUp_Peak_Time();          // cmlee    C9 
#endif									break;
#if 1
		case SET_MOMENT_POWER_MAX : 
									Set_Operation_Mode = SetUp_Moment_Peak_Power();          // cmlee    C10
									break;
#endif
#if 1
		case SET_MONTH_TARGRT_VALUE : 
									Set_Operation_Mode = SetUp_Month_Target_Power();          // cmlee    C11
									break;
#endif
		case DATA_ERASE:			Set_Operation_Mode = SetUp_Data_Erase();             // C5
									break;
		
#if 0
		case DISPLAY_RSSI:                 Set_Operation_Mode = DISPLAY_RSSI_CONTROL();    // C6
									break;
#endif
#if 1
		case DISPLAY_TEMP:                 Set_Operation_Mode = DISPLAY_TEMPERATURE_CHANGE();    // C6
									break;
#endif
#if 0
		case COST_UNIT : 
									Set_Operation_Mode = SetUp_Cost_Unit();          // cmlee    C11
									break;
#endif
// 판매 end	
		case PAIRING:			
									Set_Operation_Mode = Pairing_Setup();		break;
									
		case EXIT_SET_OPERATION:	
									LCD_FUNCTION_F_OFF;
									Set_Lcd_Char_Attribute(FUNCTION_F, 		LCD_NORMAL_DISPLAY_bit);  // F  깜박거림
								//	Set_Lcd_Char_Attribute(Now_Energy_Digit4, LCD_NORMAL_DISPLAY_bit);     // commented by cmlee if // make not to display C8
			
									return NORMAL_OPERATION;
									break;

		default:						Set_Operation_Mode = TOP_OPERATION;
									break;

	}	

	return SETUP_OPERATION;

}


/*
*********************************************************************************************************
*                                                                   Select_Set_Operation
*
* Description:      SetUp 할 메뉴를 입력 받고 선택 하여 반환 하는 함수  
*
*
*
* Arguments  :    Check 할 Proximity Sensor 종류 
*                    
*
* Returns    :       근접 센서 Edge 변화 정보 
*
*********************************************************************************************************
*/

#define     SETUP_MANU_NUM	 10
#if 0
#if 1
idata const char SetUp_Manu_Display_Data[SETUP_MANU_NUM][5]={" C1  "," C2  ", " C3  "," C4  "," C5  " }; //{"TIME ","PARIG", "BRING" };  {" C1  "," C2  ", " C3  " }
#else
idata const char  SetUp_Manu_Display_Data[SETUP_MANU_NUM][4]={" C1 "," C2 ", " C3 "," C4 "," C5 "," C6 " }; 
#endif 
#endif

static SET_OPERATION Select_Set_Operation(void)
{
	U8 Key, j;          // cmlee
	Key_Set_operation = 1; // cmlee    to rotate time month day
	LCD_FUNCTION_F_ON;
	Set_Lcd_Char_Attribute(FUNCTION_F, LCD_NORMAL_DISPLAY_bit);  // F  깜박거림
	
	Key = Key_Get();
	
	switch(Key)
	{		
		case MENU_KEY_SHORT:		Beep_Oneshort();
									
									if(++Set_Operation_Select > SETUP_MANU_NUM-1) Set_Operation_Select = TOP_OPERATION;
									break;

		case SET_KEY_SHORT:			Beep_Oneshort();

									Set_Lcd_Char_Attribute(FUNCTION_F, LCD_INVERSE_DISPLAY_bit);
									
									Set_Operation_Select++;

				                                switch( Set_Operation_Select)  // SepUp Mode 들어가기전  초기화 
									{  
									    case TIME_SET:										
													RTC_Timer_Stop();
																									 													
													Lcd_Dsp_Year_Setup(LCD_INVERSE_DISPLAY_bit);  //  표시 할 년도 
													
													Time_SetUp_Sqc=SET_YEAR;
													No_Step=0;  
													mSec_SetUp_Time = timer_mSecHandleAssign();

													timer_mSecTimerSet(mSec_SetUp_Time, Long_Key_Tick); 	// Set Time out priode
													break;
									#if 1 //cmlee
									case BILLING_RATE : 
													RTC_Timer_Stop();
													Lcd_Dsp_All_Off_Bill_System_SetUp(); 
													//No_Step=0;  // billing step으로 변경해야 함 
													//Billing_SetUp_Sqc=SET_BASIC_FARE;
												//	Lcd_Dsp_BASIC_Setup(Billing_SetUp_Sqc, No_Step);
													mSec_SetUp_Time = timer_mSecHandleAssign();
													timer_mSecTimerSet(mSec_SetUp_Time, Long_Key_Tick); 	// Set Time out priode	
													
						///							printf("Billing Mode\n");
													break;
									#endif	
									#if 1
									case NORMAL_RATE :        
													break; 
													
									
									#endif
									#ifdef SET_ONOFFTIMER // thhan
									case SET_TIMER_ONOFF :
													RTC_Timer_Stop();
													Timer_Channel=0;
													OnOff_Timer_Sqc=SET_ONOFFTIMER_CHANNEL; 
													Lcd_Dsp_OnOffTimer_Setup(Timer_Channel);
													Attribute.LCD_BitCtrl.SEG40_SETING_TIME_OFF =LCD_NORMAL_DISPLAY_bit; 
													Attribute.LCD_BitCtrl.SEG38_SETING_TIME_ON =LCD_NORMAL_DISPLAY_bit; 
													#if 0
													LcdPut_Digit_1(TIMER_SLOT_Digit1,    Timer_Channel+1);
													Set_Lcd_Char_Attribute(TIMER_SLOT_Digit1, LCD_INVERSE_DISPLAY_bit);
													#else
													LCD_Put_String(TIMER_SLOT_Digit1, "C", 1);
													Set_Lcd_Char_Attribute(TIMER_SLOT_Digit1, LCD_INVERSE_DISPLAY_bit);
													Lcd_Put_Number(RF_Channel, Timer_Channel+1,2);
													#endif
													mSec_SetUp_Time = timer_mSecHandleAssign();
													timer_mSecTimerSet(mSec_SetUp_Time, Long_Key_Tick);
													break;
									#endif
									#ifdef SET_CRT_VOLTAGE// thhan
									case SET_CRT_VTG:
													for(j = 1; j < Max_CHANNEL_ID+1; j ++)
													{
														event1.device_type[j-1] = Get_CT_Device_Type(j);
													}
													
													// PIT Type은 Voltage set 하지 않음.
													//if(event1.device_type[Display_Channel-1] == 0)
													//return TOP_OPERATION;
													
													NOW_ENG_V_ON;
													Set_AC_Voltage = event1.AC_voltage[Display_Channel-1] ;

													//printf("\n vvvvv %d", (U16)Set_AC_Voltage);
													
													CT_Sensor_AC_Voltage= Set_AC_Voltage;///Table_CT_Sensor_AC_Voltage [Set_AC_Voltage];

													if(Set_AC_Voltage == AUTO_AC_VOLTAGE)
													{
														 LCD_Put_String(Now_Energy_Digit5, " AoEo", 5);
														LCDMap.LCD_BitCtrl.SEG4_DIGIT3_4B =0; 
														LCDMap.LCD_BitCtrl.SEG4_DIGIT3_4G =0;
														LCDMap.LCD_BitCtrl.SEG6_DIGIT1_6B = 0;
														LCDMap.LCD_BitCtrl.SEG5_DIGIT2_5A = 0;
													}
													 else
													 Lcd_Put_Number(Now_Energy_Digit1, (U32)CT_Sensor_AC_Voltage, 5); 
													break;
									#endif
									#if 1
									case BILL_INPUT    :
													RTC_Timer_Stop();
													No_Step=0;  // billing step으로 변경해야 함 
													Billing_SetUp_Sqc=SET_BASIC_FARE;
												//	Lcd_Dsp_BASIC_Setup(Billing_SetUp_Sqc, No_Step);
													timer_mSecTimerSet(mSec_SetUp_Time, Long_Key_Tick); 	// Set Time out priode	
												//	printf("Billing Mode\n");
													break;
									#endif
									#if 0 // cmlee
									case SET_PEAK_TIME :         // initialization of peak time
													RTC_Timer_Stop();
													No_Step_Peaktime=0;
													Peaktime_SetUp_Sqc=SET_PEAK_MIN; 
													Lcd_Dsp_PeakTime_Setup(No_Step_Peaktime);
													Attribute.LCD_BitCtrl.SEG40_SETING_TIME_Rate=LCD_NORMAL_DISPLAY_bit;    // Rate Off
													LcdPut_Digit_1(TIMER_SLOT_Digit1,    No_Step_Peaktime+1);   // Display Peaktime slot NO
													Set_Lcd_Char_Attribute(TIMER_SLOT_Digit1, LCD_INVERSE_DISPLAY_bit);
													mSec_SetUp_Time = timer_mSecHandleAssign();
													timer_mSecTimerSet(mSec_SetUp_Time, Long_Key_Tick); 	// Set Time out priode	
							///						printf("PeakTime Mode\n");
													break;
									#endif
									#if 1
									case SET_MOMENT_POWER_MAX :      // C10
													RTC_Timer_Stop();
													Lcd_Dsp_Moment_Power_Max_Setup(); 
													mSec_SetUp_Time = timer_mSecHandleAssign();
													timer_mSecTimerSet(mSec_SetUp_Time, Long_Key_Tick); 	// Set Time out priode	
													break;
									#endif
									#if 1  							// C11
									case SET_MONTH_TARGRT_VALUE : 
													RTC_Timer_Stop();
													Lcd_Dsp_Month_Target_Power();
													mSec_SetUp_Time = timer_mSecHandleAssign();
													timer_mSecTimerSet(mSec_SetUp_Time, Long_Key_Tick); 	
													break;
									#endif
									#if 1
									case DATA_ERASE:        // C4
													
													
													RTC_Timer_Stop();
													Lcd_Dsp_All_Off_Bill_System_SetUp(); 
													mSec_SetUp_Time = timer_mSecHandleAssign();
													timer_mSecTimerSet(mSec_SetUp_Time, Long_Key_Tick); 	// Set Time out priode	
												
													break; 
									#endif
										#if 0
									case DISPLAY_RSSI:        // C10
													
													#if 1
													RTC_Timer_Stop();
													Lcd_Dsp_All_Off_Bill_System_SetUp(); 
													mSec_SetUp_Time = timer_mSecHandleAssign();
													timer_mSecTimerSet(mSec_SetUp_Time, Long_Key_Tick); 	// Set Time out priode	
													#endif 
													break; 
									#endif
									#if 1
									case DISPLAY_TEMP:        // Alternate C10
													
													
													RTC_Timer_Stop();
													Lcd_Dsp_All_Off_Bill_System_SetUp(); 
													mSec_SetUp_Time = timer_mSecHandleAssign();
													timer_mSecTimerSet(mSec_SetUp_Time, Long_Key_Tick); 	// Set Time out priode	
													
													break; 
									#endif
									#if 0      						// C12
									case COST_UNIT : 
													RTC_Timer_Stop();
													Lcd_Dsp_All_Off_Bill_System_SetUp(); 
													mSec_SetUp_Time = timer_mSecHandleAssign();
													timer_mSecTimerSet(mSec_SetUp_Time, Long_Key_Tick); 	
													
													
						///							printf("Billing Mode\n");
													break;
													break;
									#endif



									
									default: 			Set_Operation_Select = TOP_OPERATION;       break;    //cmlee
									}
									
									return Set_Operation_Select;

		case CHANGE_KEY_LONG:		Buzzer_Sound_Save();
									Key_Set_operation = 0; // cmlee    to rotate time month day
									LCD_Display_Home_Menu();
									return EXIT_SET_OPERATION;
	}
	#if 0
	LCD_Put_String(Now_Energy_Digit5,  &SetUp_Manu_Display_Data[ Set_Operation_Select ][0], 5);
	#endif
	switch(Set_Operation_Select+1)
		{
		case TIME_SET: 
				LCD_Put_String(Now_Energy_Digit5, " C1  ", 5);
			      LCD_Put_String(POWER_CONSOMPTION_Digit5,  "CL0CH", 5); 
					break;
		case BILLING_RATE: 
				LCD_Put_String(Now_Energy_Digit5, " C2  ", 5);
				LCD_Put_String(POWER_CONSOMPTION_Digit5,  " BiLL", 5);
					break;
		case NORMAL_RATE: 
				LCD_Put_String(Now_Energy_Digit5, " C3  ", 5);
				LCD_Put_String(POWER_CONSOMPTION_Digit5,  " FAxE", 5);// C3
					break;
		case SET_TIMER_ONOFF: 
				LCD_Put_String(Now_Energy_Digit5, " C4  ", 5);
				LCD_Put_String(POWER_CONSOMPTION_Digit5,  "0N0FF", 5);
					break;
		case SET_CRT_VTG: 
				LCD_Put_String(Now_Energy_Digit5, " C5  ", 5);
				LCD_Put_String(POWER_CONSOMPTION_Digit5,  "  AC ", 5);
					break;
		
		case BILL_INPUT:
				LCD_Put_String(Now_Energy_Digit5, " C6  ", 5);
				LCD_Put_String(POWER_CONSOMPTION_Digit5,  "6tiEA",5);    // TIER
					break;
					
		case SET_MOMENT_POWER_MAX : 
				LCD_Put_String(Now_Energy_Digit5, " C7  ", 5);
				LCD_Put_String(POWER_CONSOMPTION_Digit5,  "PEXH ", 5);
					break;
		case SET_MONTH_TARGRT_VALUE : 
				LCD_Put_String(Now_Energy_Digit5, " C8  ", 5);
				LCD_Put_String(POWER_CONSOMPTION_Digit5,  "tA6t ", 5);
					break;
	#if 1	
		case DATA_ERASE:
				LCD_Put_String(Now_Energy_Digit5, " C9  ", 5);
				LCD_Put_String(POWER_CONSOMPTION_Digit5,  "ExASE", 5);
					break;
	#endif 
	#if 0
		case DISPLAY_RSSI: 
				LCD_Put_String(Now_Energy_Digit5, " C10 ", 5);
				LCD_Put_String(POWER_CONSOMPTION_Digit5,  " C0DE", 5);
					break;
	#endif 	
	#if 1
		case DISPLAY_TEMP: 
				LCD_Put_String(Now_Energy_Digit5, " C10 ", 5);
				LCD_Put_String(POWER_CONSOMPTION_Digit5,  " C  F", 5);
					break;
	#endif 	
		default: break;
		}
	return TOP_OPERATION;
	
}



