Sunteți pe pagina 1din 98

#include "math.

h"
#include "sfr_r825.h"
#include "define.h"
#include "lcd_lib.h"
#include "dataflash.h"

//first_time_datawrite=0xaa; electrical protection off 0xaa


//first_time_datawrite=0x00;electrical protection on 0x00

int i=0;
void display_load_volt(void);
void set_default_value(void);
void on_off_phase_one(void);
void offset(void);
void relay_control(void);

unsigned int surge_check_counter=0;


unsigned char interrupt_delay_counter=0;_Bool in_check_flag=0;//19 feb added

struct
{
unsigned char FP_IM_ON_HR;
unsigned char FP_IM_ON_MIN;
unsigned char FP_IM_OF_HR;
unsigned char FP_IM_OF_MIN;
}st_ob;

_Bool surge_check_flag=0;
void main(void)
{
asm("FCLR I"); //Interrupt disable
prc0=1; //Protect off

//*************************************
// CPU Cl ock Setting
//**************************************
//Note: Include asm("nop")for oscillator's stabilization period after clock
setting is done.
fra20=0;fra21=0;fra22=0; //Divide by 2 mode selected
cm13=0;cm05=1;cm02=0;cm14=0;ocd0=0;ocd1=0;fra00=1;fra01=1;//High speed on-
chip oscillator selected(cm0 bit 2 and 5, cm1 bit 4, ocd bit 0 and 1 and fra0 bit 0
and 1)
ocd2=1; //High speed on-chip oscillator
selected(ocd bit 2)
cm16=0;cm17=0;cm06=0; //No division selected(cm0 bit 6,cm1 bit
6 and 7)
prc0=0; //Protect on

init(); //Inital setting


pd1_0=0;pd1_1=0;pd1_2=0;pd1_3=0;
initialize_lcd ();
initialize_timer_rb ();
set_contrast_control(DEC_CONTRAST); // decrease contrast
set_contrast_control_percentage(25);// increase contrast
start_rb ();
SCL=0;SDA=0;
pd1_0=0;pd1_1=0;pd1_2=0;pd1_3=0;
asm("FSET I"); //Interrupt enabled
wdt_init();
clear_lcd();
{
addr_init();
read_data();
//if(//first_time_datawrite==0xaa)
{
dataflash_data_retrieval();
}
}
set_default_value();
st_ob.FP_IM_ON_HR=int_hour;//interrupt relay on time
st_ob.FP_IM_ON_MIN=int_min;//
st_ob.FP_IM_OF_HR=int_off_hour;////interrupt relay on time
st_ob.FP_IM_OF_MIN=int_off_min;//

/* sunset_hour=17;sunset_min=54;
display_hou(sunset_hour);
display_minute(sunset_min);
while(1);*/

/// first time value set///


initial_flag=1;
write_lcd_ram(0,SYNER);
input_function();

for(loop=0;loop<10;loop++){
write_lcd_ram(1,array_digit[loop]);
write_lcd_ram(2,array_digit[loop]);
write_lcd_ram(3,array_digit[loop]);
write_lcd_ram(4,array_digit[loop]);
write_lcd_ram(5,array_digit[loop]);
write_lcd_ram(6,array_digit[loop]);
write_lcd_ram(7,array_digit[loop]);
general_delay=0;
while(general_delay<100);
}
clear_lcd();
//while(1)
{
do
{
ReadRTC(&RTC_ARR[0]);
BCD_DECIMAL();
}
while((date_dec>31) || (month_dec>12) || (year_dec>99) || (hour_dec>23)
|| (min_dec>59) || second_dec >59);
}

disp_date();
sun_set_rise();
clear_lcd();
cyclic_flag=1;

for(;;) //main processing


{
flux_lower=110;//99
flux_upper=150;//130
volt_upper=1600;
volt_lower=975;
st_ob.FP_IM_ON_HR=int_hour;//interrupt relay on time
st_ob.FP_IM_ON_MIN=int_min;//
st_ob.FP_IM_OF_HR=int_off_hour;////interrupt relay on
time
st_ob.FP_IM_OF_MIN=int_off_min;//

if(p4_3==0)
{ldr_check=0;}
else{ldr_check=1;}

if(INC_input==1 && INC_flag==0)


{
INC_input=0;
cyclic_flag=0;
initial_flag=1;

clear_lcd();write_lcd_ram(0,SYNER);
input_function();

addr_init();read_data();dataflash_data_retrieval();
set_default_value();
cyclic_flag=1;
sun_set_rise();
}
if(DEC_input==1 && DEC_flag==0)
{
DEC_input=0;
initial_flag=1;
cyclic_flag=0;

clear_lcd();write_lcd_ram(0,SYNER);
input_function();

addr_init();read_data();dataflash_data_retrieval();
set_default_value();
cyclic_flag=1;
sun_set_rise();
}
if(OK_input==1 && OK_flag==0)
{
OK_input=0;
cyclic_flag=0;
initial_flag=1;clear_lcd();
write_lcd_ram(0,SYNER);
input_function();

addr_init();read_data();dataflash_data_retrieval();
set_default_value();
cyclic_flag=1;
sun_set_rise();
}
if(RESET_input==1 && RESET_flag==0)
{
RESET_input=0;
cyclic_flag=0;
initial_flag=1;
clear_lcd();clear_lcd();
input_function();

addr_init();read_data();dataflash_data_retrieval();
set_default_value();
cyclic_flag=1;
sun_set_rise();
}
if(standby==0)
{
if(cyclic_count>1000)
{
cyclic_count=0;
cyclic_counter++;
if(cyclic_counter==1)
{

if(LDR_FAULT_FLAG==1)//Low light

write_lcd_ram(8,NULL|(LO & NIGHT));


else

write_lcd_ram(8,NULL|(HI & NIGHT));

write_lcd_ram(9,FIVE_P|(LIGHT & NIGHT));


disp_date();
}
else
if(cyclic_counter==2)
{

if(LDR_FAULT_FLAG==1)//Low light

write_lcd_ram(8,NULL|(LO & NIGHT));


else

write_lcd_ram(8,NULL|(HI & NIGHT));

write_lcd_ram(9,FIVE_P|(LIGHT & NIGHT));


disp_time();

}
else if
(cyclic_counter==3)
{

write_lcd_ram(9,NULL|OFF|(LIGHT & NIGHT));

if(default_define_select==0x00)
{

if(LDR_FAULT_FLAG==1)//Low light

write_lcd_ram(8,DEFAULT|(LO & NIGHT));//


else

write_lcd_ram(8,DEFAULT|(HI & NIGHT));


}
else
{

if(LDR_FAULT_FLAG==1)//Low light

write_lcd_ram(8,DEFINE|(LO & NIGHT));//


else

write_lcd_ram(8,DEFINE|(HI & NIGHT));


}
disp_off_time();

write_lcd_ram(9,NULL|OFF|(LIGHT & NIGHT));


}
else
if(cyclic_counter==4)
{

if(default_define_select==0x00)
{

if(LDR_FAULT_FLAG==1)//Low light

write_lcd_ram(8,DEFAULT|(LO & NIGHT));//


else

write_lcd_ram(8,DEFAULT|(HI & NIGHT));


}
else
{

if(LDR_FAULT_FLAG==1)//Low light

write_lcd_ram(8,DEFINE|(LO & NIGHT));//


else

write_lcd_ram(8,DEFINE|(HI & NIGHT));


}
disp_on_time();

write_lcd_ram(9,NULL|(LIGHT & NIGHT));


}

if(cyclic_counter>4)cyclic_counter=0;
}
else
{

}
}

//if(RTC_CALCULATE>1000)
{
do
{
ReadRTC(&RTC_ARR[0]);
BCD_DECIMAL();
}
while((date_dec>31) ||
(month_dec>12) || (year_dec>99) || (hour_dec>23) || (min_dec>59) || second_dec
>59);
//min_dec=0;second_dec=0
;hour_dec=0;month_dec;year_dec=0;day_dec=0;
RTC_Min = min_dec+
(hour_dec*60);
RTC_CALCULATE=0;

}
if(hour_dec==17 || (hour_dec==18)||
(hour_dec==19)|| (hour_dec==20)|| (hour_dec==21)|| (hour_dec==22)||
(hour_dec==23)|| (hour_dec==00)|| (hour_dec==1)|| (hour_dec==2)|| (hour_dec==3)||
(hour_dec==4)|| (hour_dec==5)|| (hour_dec==6))
{
in_check_flag=1;
}

if(default_define_select==0x00)
sun_set_rise();
/////////for interrupt time cntrol////
if(RTC_Min<((sunset_hour*60)+sunset_min) &&
RTC_Min>((sunrise_hour*60)+sunrise_min ))
{
LDR_CALCULATION();
{

LUX=(LDR_COUNT);//*2500)/256)*LDR_CONST;
if(LUX<=flux_lower )// turning on
the RELAY
{
upper_count_start=0;
lower_count_start=1;
upper_count=0;
if(lower_count>1500)//checked

{
LDR_FAULT_FLAG=1;
}
//LDR_flag=0;
}
else if(LUX>flux_upper)// turning
off the RELAY
{
lower_count_start=0;
lower_count=0;
upper_count_start=1;
if(upper_count>1500)//checked
{
LDR_FAULT_FLAG=0;
}
}
else
{
upper_count_start=0;
lower_count_start=0;
lower_count=0;
upper_count=0;
}
}
}

if(first_time_datawrite==0x00)
{

VOLT_CURR_CAL();

if(volt_data>(volt_upper) || volt_data<(volt_lower))//290//150
{
VOLT_FAULT_FLAG=1;

//standby =
1;cyclic_flag=0;
}
//100 //100
else
if((volt_data<(volt_upper-45)) && (volt_data>(volt_lower+45)))//270//160
{

VOLT_FAULT_FLAG=0;standby = 0;cyclic_flag=1;
}

/*
if(curr_data>=current_fix)//maximunload 50
{
// relay turn off

surge_check_flag=1;

if(surge_check_counter>800)
{

CURRENT_FAULT_FLAG=1;
// standby =
1;cyclic_flag=0;
}
else
{
//surge_chec
k_counter=0;
curr_data=0;
}
}
else
if(curr_data<(current_fix-0))//current_fix//30
{

surge_check_counter=0;surge_check_flag=0;
}
*/
}
/////////////////////////////////added
today////////////////////////
//default_define_check
default_st:

if(default_define_select==0x00)//default settig
{

}
else
{//define

if((array_hour[(month_dec*2)-1]>23) || (array_min[(month_dec*2)-1]>59))//sunset
time
{

default_define_select=0x00;//go in deafult
goto
default_st;
}

if((array_hour[(month_dec*2)]>23) || (array_min[(month_dec*2)]>59))//sunrise
{

default_define_select=0x00;
goto
default_st;
}

if((array_hour[(month_dec*2)-1]==00) && (array_min[(month_dec*2)-1]==00))//sunset


time
{

default_define_select=0x00;//go in deafult
goto
default_st;
}

if((array_hour[(month_dec*2)]==00) &&
(array_min[(month_dec*2)]==00))//sunrise
{

default_define_select=0x00;
goto
default_st;
}

sunset_hour=array_hour[(month_dec*2)-1];

sunset_min=array_min[(month_dec*2)-1];

sunrise_hour=array_hour[(month_dec*2)];

sunrise_min=array_min[(month_dec*2)];

}
//for checking relay
condition
if(LDR_FAULT_FLAG==0 &&
CURRENT_FAULT_FLAG==0 && VOLT_FAULT_FLAG==0 )
{
on_off_phase_one();//time_checked
write_lcd_ram(0,SYNER);
}
else
{ //undervolt /
overvolt /overload/optical protection

if(VOLT_FAULT_FLAG==1 || CURRENT_FAULT_FLAG==1)// || u_ob_f.st_ob_f.ovlr==1)


{
RELAY_on=0;
RELAY_off=1;//make relay
off

if(CURRENT_FAULT_FLAG==1 && VOLT_FAULT_FLAG==0)


{

write_lcd_ram(0,OVER|LOAD|SYNER);////display_overload();
}

if(VOLT_FAULT_FLAG==1 && CURRENT_FAULT_FLAG==0)


{

if(volt_data>volt_upper-25)//30//60

write_lcd_ram(0,OVER|VOLT|SYNER);//display_overvolt();
else
if(volt_data<=volt_lower+25)//30//60

write_lcd_ram(0,LOW|VOLT|SYNER);//display_lowvolt();
}

if(VOLT_FAULT_FLAG==1 && CURRENT_FAULT_FLAG==1)


{

write_lcd_ram(0,LOAD|VOLT|OVER|SYNER);//display_load_volt();
}

}
else
{

cyclic_flag=1;standby=0;

on_off_phase_one();//time_checked

write_lcd_ram(0,SYNER);
}

if(RTC_Min<((sunset_hour*60)+sunset_min) &&
RTC_Min>((sunrise_hour*60)+sunrise_min ))
{
NIGHT=0xff;

if(VOLT_FAULT_FLAG==0 && CURRENT_FAULT_FLAG==0)// && u_ob_f.st_ob_f.uvr==0 )


{
if(LDR_FAULT_FLAG==1)
{
RELAY_on=1;
RELAY_off=0;//make
relay on
//LED_ONE_G
=1;LED_ONE_R=0;

}
else if
(LDR_FAULT_FLAG==0)
{
RELAY_on=0;
RELAY_off=1;//make
relay off
//LED_ONE_G
=0;LED_ONE_R=1;
}
}
}
else
{
NIGHT=0x00;
}
}

if(SCADA_MODE==1)
{
if(SCADA_RELAY_ON==1)
{RELAY_on=1;RELAY_off=0;}//RELAY ON }
else
{RELAY_off=1;RELAY_on=0;}//RELAY Off}
}
relay_control();
}

{ asm("NOP");}
}

void on_off_phase_one(void)
{

if((((st_ob.FP_IM_ON_HR*60)+st_ob.FP_IM_ON_MIN)>((sunrise_hour*60)+sunrise_min ))
&&
(((st_ob.FP_IM_OF_HR*60)+st_ob.FP_IM_OF_MIN)>((sunset_hour*60)+sunset_min )))///fir
st half before 00:00
{
if((RTC_Min>=((sunset_hour*60)+sunset_min+int_del_min )) &&
(RTC_Min<((st_ob.FP_IM_OF_HR*60)+st_ob.FP_IM_OF_MIN)) &&
(RTC_Min<((st_ob.FP_IM_ON_HR*60)+st_ob.FP_IM_ON_MIN)) &&
(RTC_Min>=((sunrise_hour*60)+sunrise_min-int_del_min)) )
{
RELAY_on=1;
RELAY_off=0;//make relay on
}
else if((RTC_Min>=((sunset_hour*60)+sunset_min+int_del_min )) &&
(RTC_Min>=((st_ob.FP_IM_OF_HR*60)+st_ob.FP_IM_OF_MIN)) &&
(RTC_Min<((st_ob.FP_IM_ON_HR*60)+st_ob.FP_IM_ON_MIN)) &&
(RTC_Min>=((sunrise_hour*60)+sunrise_min-int_del_min)) )
{
RELAY_on=0;
RELAY_off=1;//make relay off
}
else if((RTC_Min>=((sunset_hour*60)+sunset_min+int_del_min )) &&
(RTC_Min>=((st_ob.FP_IM_OF_HR*60)+st_ob.FP_IM_OF_MIN)) &&
(RTC_Min>=((st_ob.FP_IM_ON_HR*60)+st_ob.FP_IM_ON_MIN)) &&
(RTC_Min>=((sunrise_hour*60)+sunrise_min-int_del_min)) )
{
RELAY_on=1;
RELAY_off=0;//make relay on

}
else if((RTC_Min<((sunset_hour*60)+sunset_min+int_del_min )) &&
(RTC_Min<((st_ob.FP_IM_OF_HR*60)+st_ob.FP_IM_OF_MIN)) &&
(RTC_Min<((st_ob.FP_IM_ON_HR*60)+st_ob.FP_IM_ON_MIN)) &&
(RTC_Min<((sunrise_hour*60)+sunrise_min-int_del_min)) )
{
RELAY_on=1;
RELAY_off=0;//make relay on

}
else if((RTC_Min<((sunset_hour*60)+sunset_min+int_del_min )) &&
(RTC_Min>=((sunrise_hour*60)+sunrise_min-int_del_min)) )//&&
(RTC_Min<((FP_IM_OF_HR*60)+FP_IM_OF_MIN)) &&
(RTC_Min<((FP_IM_ON_HR*60)+FP_IM_ON_MIN)) &&
(RTC_Min<=((sunrise_hour*60)+sunrise_min-K_TWI_MIN)) )
{
RELAY_on=0;
RELAY_off=1;//make relay oFF

}
else
if((((st_ob.FP_IM_ON_HR*60)+st_ob.FP_IM_ON_MIN)<((sunrise_hour*60)+sunrise_min ))
&&
(((st_ob.FP_IM_OF_HR*60)+st_ob.FP_IM_OF_MIN)<((sunset_hour*60)+sunset_min )))///sec
ond half before 00:00
{
if((RTC_Min>=((sunset_hour*60)+sunset_min+int_del_min )) &&
(RTC_Min>=((st_ob.FP_IM_OF_HR*60)+st_ob.FP_IM_OF_MIN)) &&
(RTC_Min>=((st_ob.FP_IM_ON_HR*60)+st_ob.FP_IM_ON_MIN)) &&
(RTC_Min>=((sunrise_hour*60)+sunrise_min-int_del_min)) )
{
RELAY_on=1;
RELAY_off=0;//make relay on

}
else if((RTC_Min<((sunset_hour*60)+sunset_min+int_del_min )) &&
(RTC_Min<=((st_ob.FP_IM_OF_HR*60)+st_ob.FP_IM_OF_MIN)) &&
(RTC_Min<=((st_ob.FP_IM_ON_HR*60)+st_ob.FP_IM_ON_MIN)) &&
(RTC_Min<=((sunrise_hour*60)+sunrise_min-int_del_min)) )
{
RELAY_on=1;
RELAY_off=0;//make relay on
}
else if((RTC_Min<((sunset_hour*60)+sunset_min+int_del_min )) &&
(RTC_Min>=((st_ob.FP_IM_OF_HR*60)+st_ob.FP_IM_OF_MIN)) &&
(RTC_Min<=((st_ob.FP_IM_ON_HR*60)+st_ob.FP_IM_ON_MIN)) &&
(RTC_Min<=((sunrise_hour*60)+sunrise_min-int_del_min)) )
{
RELAY_on=0;
RELAY_off=1;//make relay off
}
else if((RTC_Min<((sunset_hour*60)+sunset_min+int_del_min )) &&
(RTC_Min>=((st_ob.FP_IM_OF_HR*60)+st_ob.FP_IM_OF_MIN)) &&
(RTC_Min>=((st_ob.FP_IM_ON_HR*60)+st_ob.FP_IM_ON_MIN)) &&
(RTC_Min<((sunrise_hour*60)+sunrise_min-int_del_min)) )
{
RELAY_on=1;
RELAY_off=0;//make relay on

}
else if((RTC_Min<((sunset_hour*60)+sunset_min+int_del_min )) &&
(RTC_Min>=((sunrise_hour*60)+sunrise_min-int_del_min)) )//&&
(RTC_Min<((FP_IM_OF_HR*60)+FP_IM_OF_MIN)) &&
(RTC_Min<((FP_IM_ON_HR*60)+FP_IM_ON_MIN)) &&
(RTC_Min<=((sunrise_hour*60)+sunrise_min-K_TWI_MIN)) )
{
RELAY_on=0;
RELAY_off=1;//make relay off
}
}
else
if((((st_ob.FP_IM_ON_HR*60)+st_ob.FP_IM_ON_MIN)<((sunrise_hour*60)+sunrise_min ))
&&
(((st_ob.FP_IM_OF_HR*60)+st_ob.FP_IM_OF_MIN)>=((sunset_hour*60)+sunset_min )))///se
cond half before 00:00 and after 0000
{
if((RTC_Min>=((sunset_hour*60)+sunset_min+int_del_min )) &&
(RTC_Min<((st_ob.FP_IM_OF_HR*60)+st_ob.FP_IM_OF_MIN)) &&
(RTC_Min>=((st_ob.FP_IM_ON_HR*60)+st_ob.FP_IM_ON_MIN)) &&
(RTC_Min>=((sunrise_hour*60)+sunrise_min-int_del_min)) )
{
RELAY_on=1;
RELAY_off=0;//make relay on

}
else if((RTC_Min>=((sunset_hour*60)+sunset_min+int_del_min )) &&
(RTC_Min>=((st_ob.FP_IM_OF_HR*60)+st_ob.FP_IM_OF_MIN)) &&
(RTC_Min>=((st_ob.FP_IM_ON_HR*60)+st_ob.FP_IM_ON_MIN)) &&
(RTC_Min>=((sunrise_hour*60)+sunrise_min-int_del_min)) )
{
RELAY_on=0;
RELAY_off=1;//make relay off
}
else if((RTC_Min<=((sunset_hour*60)+sunset_min+int_del_min )) &&
(RTC_Min<=((st_ob.FP_IM_OF_HR*60)+st_ob.FP_IM_OF_MIN)) &&
(RTC_Min<((st_ob.FP_IM_ON_HR*60)+st_ob.FP_IM_ON_MIN)) &&
(RTC_Min<=((sunrise_hour*60)+sunrise_min-int_del_min)) )
{
RELAY_on=0;
RELAY_off=1;//make relay on
}
else if((RTC_Min<=((sunset_hour*60)+sunset_min+int_del_min )) &&
(RTC_Min<=((st_ob.FP_IM_OF_HR*60)+st_ob.FP_IM_OF_MIN)) &&
(RTC_Min>=((st_ob.FP_IM_ON_HR*60)+st_ob.FP_IM_ON_MIN)) &&
(RTC_Min<=((sunrise_hour*60)+sunrise_min-int_del_min)) )
{
RELAY_on=1;
RELAY_off=0;//make relay on

}
else if((RTC_Min<=((sunset_hour*60)+sunset_min+int_del_min )) &&
(RTC_Min>=((sunrise_hour*60)+sunrise_min-int_del_min)) )//&&
(RTC_Min<((FP_IM_OF_HR*60)+FP_IM_OF_MIN)) &&
(RTC_Min<((FP_IM_ON_HR*60)+FP_IM_ON_MIN)) &&
(RTC_Min<=((sunrise_hour*60)+sunrise_min-K_TWI_MIN)) )
{
RELAY_on=0;
RELAY_off=1;//make relay off

}
}
}

void relay_control(void)
{
//signal relay controlling//

if(RELAY_on==1) // signal pulse


{
if(relay_already_off==1)
{
relay_on_off_counter=0;
RELAY_S =0;//AB_LED=1;
RELAY_R =1;//NO_LED=0;
relay_already_on=1;
relay_already_off=0;
}
}
if(RELAY_off==1)
{
if(relay_already_on==1)
{
relay_on_off_counter=0;
RELAY_S =1;//AB_LED=0;
RELAY_R =0;//NO_LED=1;
relay_already_on=0;
relay_already_off=1;
}
}
}

void default_pgm(void)
{
clear_lcd();
display_OK();
general_delay=0;
while(general_delay<500);
//default_pgm_flag=1;
//date month year setting
{
date1:
clear_lcd();
write_lcd_ram(0,SYNER);
date_flag=1;

shift_counter=0;data0=0;data1=1;data2=0;data3=1;data4=0;data5=1;
do
{
ReadRTC(&RTC_ARR[0]);
BCD_DECIMAL();
}
while((date_dec>31) || (month_dec>12) || (year_dec>99) || (hour_dec>23) ||
(min_dec>59) || second_dec >59);

data1=date_dec%10;
date_dec=date_dec-data1;date_dec=date_dec/10;
data0=date_dec%10;

data3=month_dec%10;
month_dec=month_dec-data3;month_dec=month_dec/10;
data2=month_dec%10;

data5=year_dec%10;
year_dec=year_dec-data4;year_dec=year_dec/10;
data4=year_dec%10;

write_lcd_ram(1,array_digit[1]|DATE);
write_lcd_ram(9,FIVE_P);
while(date_flag==1)
{
if(shift_counter==0)
{
if(blink==0){
write_lcd_ram(2,(array_digit[data0 &
0xff]));blink=1;}//for date logo display
else{write_lcd_ram(2,0x00);blink=0;}
write_lcd_ram(3,array_digit[data1 & 0xff]|
THREE_P);
write_lcd_ram(4,(array_digit[data2 & 0xff]));
write_lcd_ram(5,array_digit[data3 & 0xff]);
write_lcd_ram(6,(array_digit[data4 & 0xff]));
write_lcd_ram(7,array_digit[data5 & 0xff]);
}
else if(shift_counter==1)
{
write_lcd_ram(2,(array_digit[data0 & 0xff]));//for
date logo display
if(blink==0){write_lcd_ram(3,array_digit[data1 &
0xff]|THREE_P);blink=1;}
else{write_lcd_ram(3,0x00|THREE_P);blink=0;}
write_lcd_ram(4,(array_digit[data2 & 0xff]));
write_lcd_ram(5,array_digit[data3 & 0xff]);
write_lcd_ram(6,(array_digit[data4 & 0xff]));
write_lcd_ram(7,array_digit[data5 & 0xff]);
}
else if(shift_counter==2)
{
write_lcd_ram(2,(array_digit[data0 & 0xff]));//for
date logo display
write_lcd_ram(3,array_digit[data1 & 0xff]|THREE_P);

if(blink==0){write_lcd_ram(4,(array_digit[data2
& 0xff]));blink=1;}
else{write_lcd_ram(4,0x00);blink=0;}
write_lcd_ram(5,array_digit[data3 & 0xff]);
write_lcd_ram(6,(array_digit[data4 & 0xff]));
write_lcd_ram(7,array_digit[data5 & 0xff]);
}
else if(shift_counter==3)
{
write_lcd_ram(2,(array_digit[data0 & 0xff]));//for
date logo display
write_lcd_ram(3,array_digit[data1 & 0xff]|THREE_P);
write_lcd_ram(4,(array_digit[data2 & 0xff]));
if(blink==0){write_lcd_ram(5,array_digit[data3 &
0xff]);blink=1;}
else{write_lcd_ram(5,0x00);blink=0;}
write_lcd_ram(6,(array_digit[data4 & 0xff]));
write_lcd_ram(7,array_digit[data5 & 0xff]);
}
else if(shift_counter==4)
{
write_lcd_ram(2,(array_digit[data0 & 0xff]));//for
date logo display
write_lcd_ram(3,array_digit[data1 & 0xff]|THREE_P);
write_lcd_ram(4,(array_digit[data2 & 0xff]));
write_lcd_ram(5,array_digit[data3 & 0xff]);
if(blink==0){write_lcd_ram(6,(array_digit[data4 &
0xff]));blink=1;}
else{write_lcd_ram(6,0x00);blink=0;}
write_lcd_ram(7,array_digit[data5 & 0xff]);
}
else if(shift_counter==5)
{
write_lcd_ram(2,(array_digit[data0 & 0xff]));//for
date logo display
write_lcd_ram(3,array_digit[data1 & 0xff]|THREE_P);
write_lcd_ram(4,(array_digit[data2 & 0xff]));
write_lcd_ram(5,array_digit[data3 & 0xff]);
write_lcd_ram(6,(array_digit[data4 & 0xff]));
if(blink==0){write_lcd_ram(7,array_digit[data5 &
0xff]);blink=1;}
else{write_lcd_ram(7,0x00);blink=0;}
}

if(INC_input==1 && INC_flag==0 )


{
INC_input=0;

if(shift_counter==0)
{
data0++;
if((data0*10+data1)>31){data0=3;data1=0;}
/*if(data0>3)
data0=3 ;*/

}
else if(shift_counter==1)
{
data1++;
if((data0*10+data1)>31){data0=3;data1=0;}
}
else if(shift_counter==2)
{
data2++;
if((data2*10+data3)>12){data2=1;data3=0;}
}
else if(shift_counter==3)
{
data3++;
if((data2*10+data3)>12){data2=1;data3=0;}

}
else if(shift_counter==4)
{
data4++;
if((data4*10+data5)>99){data4=0;data4=0;}

}
else if(shift_counter==5)
{
data5++;
if((data4*10+data5)>99){data4=0;data4=0;}
}
//display_value_id(PASSWORD);
}
if(DEC_input==1 && DEC_flag==0 && one_det==0 )
{
DEC_input=0;

if(shift_counter==0)
{
if(data0>=1)
data0--;
}
else if(shift_counter==1)
{
if(data1>=1)
data1--;
}
else if(shift_counter==2)
{
if(data2>=1)
data2--;
}
else if(shift_counter==3)
{
if(data3>=1)
data3--;
}
else if(shift_counter==4)
{
if(data4>=1)
data4--;
}
else if(shift_counter==5)
{
if(data5>=1)
data5--;
}

}
if(OK_input==1 && OK_flag==0)
{
OK_input=0;
date_flag=0;
in_date=((10*data0)+data1);
in_month=((10*data2)+data3);
in_year=((10*data4)+data5);
date_flag=0;
write_lcd_ram(7,array_digit[data5 & 0xff]|
0x10);
general_delay=0;
while(general_delay<500);

}
if(RESET_input==1 && RESET_flag==0)
{
RESET_input=0;
if(shift_counter<6)
shift_counter++;
else if(shift_counter>5){
shift_counter=0;
data0=0;data1=0;data2=0;data3=0;data4=0;data5=0;
}
}
}

write_lcd_ram(6,(array_digit[data4 & 0xff]|0x10));


write_lcd_ram(7,(array_digit[data5 & 0xff]|0x10));

date_ok=1;
while(date_ok)
{
if(INC_input==1 && INC_flag==0 )
{
INC_input=0;date_ok=0;
goto date1;
}
if(DEC_input==1 && DEC_flag==0 )
{
DEC_input=0;date_ok=0;
goto date1;
}
if(OK_input==1 && OK_flag==0 )
{
OK_input=0; date_ok=0;
}
if(RESET_input==1 && RESET_flag==0 )
{
RESET_input=0; date_ok=0;
goto date1;
}
}

///hour_:min_
time1:
clear_lcd();
write_lcd_ram(0,SYNER);
time_flag=1;
shift_counter=0;data0=0;data1=0;data2=0;data3=0;data4=0;data5=0;

data1=hour_dec%10;
hour_dec=hour_dec-data1;hour_dec=hour_dec/10;
data0=hour_dec%10;

data3=min_dec%10;
min_dec=min_dec-data3;min_dec=min_dec/10;
data2=min_dec%10;

data5=second_dec%10;
second_dec=second_dec-data4;second_dec=second_dec/10;
data4=second_dec%10;

write_lcd_ram(1,array_digit[2]);//SERIAL NO
while(time_flag==1)
{
if(shift_counter==0)
{
if(blink==0)
{write_lcd_ram(2,array_digit[data0 & 0xff]);blink=1;}
else
{write_lcd_ram(2,0x00);blink=0;}
write_lcd_ram(3,(array_digit[data1
& 0xff]|THREE_P));
write_lcd_ram(4,(array_digit[data2
& 0xff]));
write_lcd_ram(5,array_digit[data3 &
0xff]|TIME);
}
else if (shift_counter==1)
{
write_lcd_ram(2,array_digit[data0 &
0xff]);
if(blink==0){write_lcd_ram(3,
(array_digit[data1 & 0xff]|THREE_P));blink=1;}
else {write_lcd_ram(3,0x00|
THREE_P);blink=0;}
write_lcd_ram(4,(array_digit[data2
& 0xff]));
write_lcd_ram(5,array_digit[data3 &
0xff]|TIME);
}
else if (shift_counter==2)
{
write_lcd_ram(2,array_digit[data0 &
0xff]);
write_lcd_ram(3,(array_digit[data1
& 0xff]|THREE_P));
if(blink==0){write_lcd_ram(4,
(array_digit[data2 & 0xff]));blink=1;}
else
{write_lcd_ram(4,0x00);blink=0;}
write_lcd_ram(5,array_digit[data3 &
0xff]|TIME);
}
else if(shift_counter==3)
{
write_lcd_ram(2,array_digit[data0 &
0xff]);
write_lcd_ram(3,(array_digit[data1
& 0xff]|THREE_P));
write_lcd_ram(4,(array_digit[data2
& 0xff]));
if(blink==0)
{write_lcd_ram(5,array_digit[data3 & 0xff]|TIME);blink=1;}
else {write_lcd_ram(5,0x00|
TIME);blink=0;}
}

if(INC_input==1 && INC_flag==0 )


{
INC_input=0;

if(shift_counter==0)
{
data0++;
if((data0*10+data1)>23)
{data0=0;data1=0;}

}
else if(shift_counter==1)
{
data1++;
if((data0*10+data1)>23)
{data0=0;data1=0;}
}
else if(shift_counter==2)
{
data2++;
if((data2*10+data3)>59)
{data2=0;data3=0;}
}
else if(shift_counter==3)
{
data3++;
if((data2*10+data3)>59)
{data2=0;data3=0;}
}

//display_value_id(PASSWORD);
}
if(DEC_input==1 && DEC_flag==0 &&
one_det==0 )
{
DEC_input=0;
if(shift_counter==0)
{
if(data0>=1)
data0--;
}
else if(shift_counter==1)
{
if(data1>=1)
data1--;
}
else if(shift_counter==2)
{
if(data2>=1)
data2--;
}
else if(shift_counter==3)
{
if(data3>=1)
data3--;
}

}
if(OK_input==1 && OK_flag==0)
{
OK_input=0;
date_flag=0;

in_hour=((10*data0)+data1);
in_min=((10*data2)+data3);
time_flag=0;
write_lcd_ram(7,array_digit[data5 &
0xff]|0x10);
general_delay=0;
while(general_delay<500);

}
if(RESET_input==1 && RESET_flag==0)
{

if(shift_counter<4)
shift_counter++;
else if(shift_counter>3){
shift_counter=0;

data0=0;data1=0;data2=0;data3=0;data4=0;data5=0; }

RESET_input=0;

}
}

write_lcd_ram(6,0x10);
write_lcd_ram(7,0x10);// display_Press_OK();
time_ok=1;
while(time_ok)
{
if(INC_input==1 && INC_flag==0 )
{
INC_input=0;time_ok=0;
goto time1;
}
if(DEC_input==1 && DEC_flag==0 )
{
DEC_input=0;time_ok=0;
goto time1;
}
if(OK_input==1 && OK_flag==0 )
{
OK_input=0; time_ok=0;
}
if(RESET_input==1 && RESET_flag==0 )
{
RESET_input=0; time_ok=0;
goto time1;
}
}
}
// interrupt on time
//this is the time for sun rise- time add

if(maintenance==0)//relay on time--IM ON TIME SERIAL NO 3--RELAY ON TIME


{
inter1:
clear_lcd();
write_lcd_ram(0,SYNER);
inter_flag=1;
shift_counter=0;data0=0;data1=0;data2=0;data3=0;data4=0;data5=0;

data1=int_hour%10;
int_hour=int_hour-data1;int_hour=int_hour/10;
data0=int_hour%10;

data3=int_min%10;
int_min=int_min-data3;int_min=int_min/10;
data2=int_min%10;

write_lcd_ram(1,array_digit[3]);//SERIAL NO
while(inter_flag==1)
{

if(shift_counter==0)
{
if(blink==0)
{write_lcd_ram(2,array_digit[data0 & 0xff]|IM);blink=1;}
else
{write_lcd_ram(2,0x00|IM);blink=0;}

write_lcd_ram(3,array_digit[data1 & 0xff]|THREE_P);


write_lcd_ram(4,
(array_digit[data2 & 0xff]|ON));

write_lcd_ram(5,array_digit[data3 & 0xff]|TIME);


}
else
if(shift_counter==1)
{
write_lcd_ram(2,array_digit[data0 & 0xff]|IM);
if(blink==0)
{write_lcd_ram(3,array_digit[data1 & 0xff]|THREE_P);blink=1;}
else
{write_lcd_ram(3,0x00|THREE_P);blink=0;}
write_lcd_ram(4,
(array_digit[data2 & 0xff]|ON));

write_lcd_ram(5,array_digit[data3 & 0xff]|TIME);


}
else
if(shift_counter==2)
{

write_lcd_ram(2,array_digit[data0 & 0xff]|IM);

write_lcd_ram(3,array_digit[data1 & 0xff]|THREE_P);


if(blink==0)
{write_lcd_ram(4,(array_digit[data2 & 0xff]|ON));blink=1;}
else
{write_lcd_ram(4,0x00|ON);blink=0;}

write_lcd_ram(5,array_digit[data3 & 0xff]|TIME);


}
else
if(shift_counter==3)
{

write_lcd_ram(2,array_digit[data0 & 0xff]|IM);

write_lcd_ram(3,array_digit[data1 & 0xff]|THREE_P);


write_lcd_ram(4,
(array_digit[data2 & 0xff]|ON));
if(blink==0)
{write_lcd_ram(5,array_digit[data3 & 0xff]|TIME);blink=1;}
else
{write_lcd_ram(5,0x00|TIME);blink=0;}
}

if(INC_input==1 && INC_flag==0 )


{

INC_input=0;

if(shift_counter==0)
{
data0+
+;

if((data0*10+data1)>23){data0=0;data1=0;} //time hour

}
else
if(shift_counter==1)
{
data1+
+;

if((data0*10+data1)>23){data0=0;data1=0;} //time hour

}
else
if(shift_counter==2)
{
data2+
+;

if((data2*10+data3)>59){data2=0;data3=0;} //time minute

}
else
if(shift_counter==3)
{
data3+
+;

if((data2*10+data3)>59){data2=0;data3=0;} //time minute

//disp
lay_value_id(PASSWORD);
}

if(DEC_input==1 && DEC_flag==0 && one_det==0 )


{

DEC_input=0;

if(shift_counter==0)
{

if(data0>=1)

data0--;

}
else
if(shift_counter==1)
{

if(data1>=1)

data1--;

}
else
if(shift_counter==2)
{

if(data2>=1)

data2--;

}
else
if(shift_counter==3)
{

if(data3>=1)

data3--;
}

if(OK_input==1 && OK_flag==0)


{

OK_input=0;

inter_flag=0;

int_hour=((10*data0)+data1);// after

int_min=((10*data2)+data3);

inter_flag=0;

write_lcd_ram(7,OK);//DISPLAY OK

general_delay=0;

while(general_delay<500);

if(RESET_input==1 && RESET_flag==0)


{

if(shift_counter<4)

shift_counter++;
else
if(shift_counter>3){

shift_counter=0;

data0=0;data1=0;data2=0;data3=0;data4=0;data5=0; }

RESET_input=0;

}
}

write_lcd_ram(6,0x10);
write_lcd_ram(7,0x10);// display_Press_OK();
inter_ok=1;
while(inter_ok)
{
if(INC_input==1 && INC_flag==0 )
{
INC_input=0;inter_ok=0;
goto inter1;
}
if(DEC_input==1 && DEC_flag==0 )
{
DEC_input=0;inter_ok=0;
goto inter1;
}
if(OK_input==1 && OK_flag==0 )
{
OK_input=0; inter_ok=0;
}
if(RESET_input==1 && RESET_flag==0 )
{
RESET_input=0; inter_ok=0;
goto inter1;
}
}
//////

// interrupt off time


//this is the time for sun rise- time add
inter_off1: ////relay off time--IM OFF TIME SERIAL NO 4--RELAY OFF TIME
clear_lcd();
write_lcd_ram(0,SYNER);
inter_off_flag=1;
shift_counter=0;data0=0;data1=0;data2=0;data3=0;data4=0;data5=0;

data1=int_off_hour%10;
int_off_hour=int_off_hour-data1;int_off_hour=int_off_hour/10;
data0=int_off_hour%10;

data3=int_off_min%10;
int_off_min=int_off_min-data3;int_off_min=int_off_min/10;
data2=int_off_min%10;

write_lcd_ram(1,array_digit[4]);//SERIAL NO
write_lcd_ram(9,OFF);//SERIAL NO
while(inter_off_flag==1)
{
if(shift_counter==0)
{
if(blink==0)
{write_lcd_ram(2,array_digit[data0 & 0xff]|IM);blink=1;}
else
{write_lcd_ram(2,0x00|IM);blink=0;}

write_lcd_ram(3,array_digit[data1 & 0xff]|THREE_P);


write_lcd_ram(4,
(array_digit[data2 & 0xff]));

write_lcd_ram(5,array_digit[data3 & 0xff]|TIME);


}
else
if(shift_counter==1)
{

write_lcd_ram(2,array_digit[data0 & 0xff]|IM);


if(blink==0)
{write_lcd_ram(3,array_digit[data1 & 0xff]|THREE_P);blink=1;}
else
{write_lcd_ram(3,0x00|THREE_P);blink=0;}
write_lcd_ram(4,
(array_digit[data2 & 0xff]));

write_lcd_ram(5,array_digit[data3 & 0xff]|TIME);


}
else
if(shift_counter==2)
{

write_lcd_ram(2,array_digit[data0 & 0xff]|IM);

write_lcd_ram(3,array_digit[data1 & 0xff]|THREE_P);


if(blink==0)
{write_lcd_ram(4,(array_digit[data2 & 0xff]));blink=1;}
else
{write_lcd_ram(4,0x00);blink=0;}

write_lcd_ram(5,array_digit[data3 & 0xff]|TIME);


}
else
if(shift_counter==3)
{

write_lcd_ram(2,array_digit[data0 & 0xff]|IM);

write_lcd_ram(3,array_digit[data1 & 0xff]|THREE_P);


write_lcd_ram(4,
(array_digit[data2 & 0xff]));
if(blink==0)
{write_lcd_ram(5,array_digit[data3 & 0xff]|TIME);blink=1;}
else
{write_lcd_ram(5,0x00|TIME);blink=0;}
}

if(INC_input==1 && INC_flag==0 )


{

INC_input=0;

if(shift_counter==0)
{
data0+
+;

if((data0*10+data1)>23){data0=0;data1=0;} //time hour

}
else
if(shift_counter==1)
{
data1+
+;

if((data0*10+data1)>23){data0=0;data1=0;} //time hour


}
else
if(shift_counter==2)
{
data2+
+;

if((data2*10+data3)>59){data2=0;data3=0;} //time minute

}
else
if(shift_counter==3)
{
data3+
+;

if((data2*10+data3)>59){data2=0;data3=0;} //time minute

//disp
lay_value_id(PASSWORD);
}

if(DEC_input==1 && DEC_flag==0 && one_det==0 )


{

DEC_input=0;

if(shift_counter==0)
{

if(data0>=1)

data0--;

}
else
if(shift_counter==1)
{

if(data1>=1)

data1--;

}
else
if(shift_counter==2)
{

if(data2>=1)

data2--;
}
else
if(shift_counter==3)
{

if(data3>=1)
data3--;
}

if(OK_input==1 && OK_flag==0)


{

OK_input=0;

inter_flag=0;

int_off_hour=((10*data0)+data1);

int_off_min=((10*data2)+data3);

inter_off_flag=0;

write_lcd_ram(7,OK);//DISPLAY OK

general_delay=0;

while(general_delay<500);

if(RESET_input==1 && RESET_flag==0)


{

if(shift_counter<4)

shift_counter++;
else
if(shift_counter>3){

shift_counter=0;

data0=0;data1=0;data2=0;data3=0;data4=0;data5=0; }

RESET_input=0;
}
}

write_lcd_ram(6,0x10);
write_lcd_ram(7,0x10);// display_Press_OK();
interoff_ok=1;
while(interoff_ok)
{
if(INC_input==1 && INC_flag==0 )
{
INC_input=0;interoff_ok=0;
goto inter_off1;
}
if(DEC_input==1 && DEC_flag==0 )
{
DEC_input=0;interoff_ok=0;
goto inter_off1;
}
if(OK_input==1 && OK_flag==0 )
{
OK_input=0; interoff_ok=0;
}
if(RESET_input==1 && RESET_flag==0 )
{
RESET_input=0; interoff_ok=0;
goto inter_off1;
}
}
}
///interrupt delay
//this is the time for sun set+ time add
int_del1:
clear_lcd();
write_lcd_ram(0,SYNER);
int_del_flag=1;
shift_counter=0;data0=0;data1=0;data2=0;data3=0;data4=0;data5=0;

data1=int_del_hour%10;
int_del_hour=int_del_hour-data1;int_del_hour=int_del_hour/10;
data0=int_del_hour%10;

data3=int_del_min%10;
int_del_min=int_del_min-data3;int_del_min=int_del_min/10;
data2=int_del_min%10;

write_lcd_ram(1,array_digit[5]);//SERIAL NO
write_lcd_ram(0,TW|SYNER);//tilight
while(int_del_flag==1)
{

if(shift_counter==0)
{
if(blink==0)
{write_lcd_ram(2,array_digit[data0 & 0xff]);blink=1;}
else
{write_lcd_ram(2,0x00);blink=0;}

write_lcd_ram(3,array_digit[data1 & 0xff]|THREE_P);


write_lcd_ram(4,
(array_digit[data2 & 0xff]));

write_lcd_ram(5,array_digit[data3 & 0xff]);


}
else
if(shift_counter==1)
{

write_lcd_ram(2,array_digit[data0 & 0xff]);


if(blink==0)
{write_lcd_ram(3,array_digit[data1 & 0xff]|THREE_P);blink=1;}
else
{write_lcd_ram(3,0x00|THREE_P);blink=0;}
write_lcd_ram(4,
(array_digit[data2 & 0xff]));
write_lcd_ram(5,array_digit[data3 & 0xff]);
}
else
if(shift_counter==2)
{

write_lcd_ram(2,array_digit[data0 & 0xff]);

write_lcd_ram(3,array_digit[data1 & 0xff]|THREE_P);


if(blink==0)
{write_lcd_ram(4,(array_digit[data2 & 0xff]));blink=1;}
else
{write_lcd_ram(4,0x00);blink=0;}

write_lcd_ram(5,array_digit[data3 & 0xff]);


}
else
if(shift_counter==3)
{

write_lcd_ram(2,array_digit[data0 & 0xff]);

write_lcd_ram(3,array_digit[data1 & 0xff]|THREE_P);


write_lcd_ram(4,
(array_digit[data2 & 0xff]));
if(blink==0)
{write_lcd_ram(5,array_digit[data3 & 0xff]);blink=1;}
else
{write_lcd_ram(5,0x00);blink=0;}
}

if(INC_input==1 && INC_flag==0 )


{

INC_input=0;

if(shift_counter==0)
{
data0+
+;

if(data0>0)

data0=0 ;
}
else
if(shift_counter==1)
{
data1+
+;

if(data1>0)

data1=0 ;
}
else
if(shift_counter==2)
{
data2+
+;

if((data2*10+data3)>59){data2=0;data3=0;} //time minute

}
else
if(shift_counter==3)
{
data3+
+;

if((data2*10+data3)>59){data2=0;data3=0;} //time minute

//disp
lay_value_id(PASSWORD);
}

if(DEC_input==1 && DEC_flag==0 && one_det==0 )


{

DEC_input=0;

if(shift_counter==0)
{

if(data0>=1)

data0--;

}
else
if(shift_counter==1)
{

if(data1>=1)

data1--;

}
else
if(shift_counter==2)
{

if(data2>=1)

data2--;
}
else
if(shift_counter==3)
{

if(data3>=1)

data3--;

}
}

if(OK_input==1 && OK_flag==0)


{

OK_input=0;

int_del_hour=((10*data0)+data1);

int_del_min=((10*data2)+data3);

int_del_flag=0;

write_lcd_ram(7,OK);//DISPLAY OK

general_delay=0;

while(general_delay<500);

if(RESET_input==1 && RESET_flag==0)


{

RESET_input=0;

if(shift_counter<4)

shift_counter++;
else
if(shift_counter>3){

shift_counter=0;

data0=0;data1=0;data2=0;data3=0;data4=0;data5=0; }

RESET_input=0;

}
}

write_lcd_ram(6,0x10);
write_lcd_ram(7,0x10);// display_Press_OK();
intdel_ok=1;
while(intdel_ok)
{
if(INC_input==1 && INC_flag==0 )
{
INC_input=0;intdel_ok=0;
goto int_del1;
}
if(DEC_input==1 && DEC_flag==0 )
{
DEC_input=0;intdel_ok=0;
goto int_del1;
}
if(OK_input==1 && OK_flag==0 )
{
OK_input=0; intdel_ok=0;
}
if(RESET_input==1 && RESET_flag==0 )
{
RESET_input=0; intdel_ok=0;
goto int_del1;
}
}
//longitude lattitude
long1:
clear_lcd();
write_lcd_ram(0,SYNER);
long_det_flag=1;
shift_counter=0;data0=0;data1=0;data2=0;data3=0;data4=0;data5=0;

data1=long_degree%10;
long_degree=long_degree-data1;long_degree=long_degree/10;
data0=long_degree%10;

data3=long_min%10;
long_min=long_min-data3;long_min=long_min/10;
data2=long_min%10;

general_delay=0;
while(general_delay<600);
write_lcd_ram(1,array_digit[6]);//SERIAL NO
write_lcd_ram(8,LONG);//SERIAL NO
write_lcd_ram(9,DOT);//SERIAL NO
while(long_det_flag==1)
{
if(shift_counter==0)
{
if(blink==0)
{write_lcd_ram(3,array_digit[data0 & 0xff]);blink=1;}
else
{write_lcd_ram(3,0x00);blink=0;}

write_lcd_ram(4,array_digit[data1 & 0xff]);

write_lcd_ram(5,array_digit[data2 & 0xff]);

write_lcd_ram(6,array_digit[data3 & 0xff]);


}
else
if(shift_counter==1)
{

write_lcd_ram(3,array_digit[data0 & 0xff]);


if(blink==0)
{write_lcd_ram(4,array_digit[data1 & 0xff]);blink=1;}
else
{write_lcd_ram(4,0x00);blink=0;}
write_lcd_ram(5,
(array_digit[data2 & 0xff]));

write_lcd_ram(6,array_digit[data3 & 0xff]);


}
else
if(shift_counter==2)
{

write_lcd_ram(3,array_digit[data0 & 0xff]);

write_lcd_ram(4,array_digit[data1 & 0xff]);


if(blink==0)
{write_lcd_ram(5,(array_digit[data2 & 0xff]));blink=1;}
else
{write_lcd_ram(5,0x00);blink=0;}

write_lcd_ram(6,array_digit[data3 & 0xff]);


}
else
if(shift_counter==3)
{

write_lcd_ram(3,array_digit[data0 & 0xff]);

write_lcd_ram(4,array_digit[data1 & 0xff]);


write_lcd_ram(5,
(array_digit[data2 & 0xff]));
if(blink==0)
{write_lcd_ram(6,array_digit[data3 & 0xff]);blink=1;}
else
{write_lcd_ram(6,0x00);blink=0;}
}

if(INC_input==1 && INC_flag==0 )


{

INC_input=0;

if(shift_counter==0)
{
data0+
+;

if(data0>8)

data0=9 ;
}
else
if(shift_counter==1)
{
data1+
+;

if(data1>8)

data1=9 ;
}
else
if(shift_counter==2)
{
data2+
+;

if(data2>8)
data2=9 ;
}
else
if(shift_counter==3)
{
data3+
+;

if(data3>8)

data3=9 ;
}

//disp
lay_value_id(PASSWORD);
}

if(DEC_input==1 && DEC_flag==0 && one_det==0 )


{

DEC_input=0;

if(shift_counter==0)
{

if(data0>=1)

data0--;
}
else
if(shift_counter==1)
{

if(data1>=1)

data1--;

}
else
if(shift_counter==2)
{

if(data2>=1)

data2--;

}
else
if(shift_counter==3)
{

if(data3>=1)

data3--;
}

}
if(OK_input==1 && OK_flag==0)
{

OK_input=0;
//date
_flag=0;

long_degree=((10*data0)+data1);

long_min=((10*data2)+data3);

long_det_flag=0;

write_lcd_ram(7,OK);//DISPLAY OK

general_delay=0;

while(general_delay<500);

if(RESET_input==1 && RESET_flag==0)


{

RESET_input=0;

if(shift_counter<4)

shift_counter++;
else
if(shift_counter>3){

shift_counter=0;

data0=0;data1=0;data2=0;data3=0;data4=0;data5=0; }

}
}
write_lcd_ram(6,0x10);
write_lcd_ram(7,0x10);// display_Press_OK();
long_ok=1;
while(long_ok)
{
if(INC_input==1 && INC_flag==0 )
{
INC_input=0;long_ok=0;
goto long1;
}
if(DEC_input==1 && DEC_flag==0 )
{
DEC_input=0;long_ok=0;
goto long1;
}
if(OK_input==1 && OK_flag==0 )
{
OK_input=0; long_ok=0;
}
if(RESET_input==1 && RESET_flag==0 )
{
RESET_input=0; long_ok=0;
goto long1;
}
}

////lattitude detail
lat1:
clear_lcd();
write_lcd_ram(0,SYNER);
lat_det_flag=1;
shift_counter=0;data0=0;data1=0;data2=0;data3=0;data4=0;data5=0;

data1=lat_deg%10;
lat_deg=lat_deg-data1;lat_deg=lat_deg/10;
data0=lat_deg%10;

data3=lat_min%10;
lat_min=lat_min-data3;lat_min=lat_min/10;
data2=lat_min%10;

general_delay=0;
while(general_delay<600);
write_lcd_ram(1,array_digit[7]);//SERIAL NO
write_lcd_ram(8,LAT);//SERIAL NO
write_lcd_ram(9,DOT);//SERIAL NO
while(lat_det_flag==1)
{

if(shift_counter==0)
{
if(blink==0)
{write_lcd_ram(3,array_digit[data0 & 0xff]);blink=1;}
else
{write_lcd_ram(3,0x00);blink=0;}

write_lcd_ram(4,array_digit[data1 & 0xff]);


write_lcd_ram(5,
(array_digit[data2 & 0xff]));

write_lcd_ram(6,array_digit[data3 & 0xff]);


}
else
if(shift_counter==1)
{

write_lcd_ram(3,array_digit[data0 & 0xff]);


if(blink==0)
{write_lcd_ram(4,array_digit[data1 & 0xff]);blink=1;}
else
{write_lcd_ram(4,0x00);blink=0;}
write_lcd_ram(5,
(array_digit[data2 & 0xff]));

write_lcd_ram(6,array_digit[data3 & 0xff]);


}
else
if(shift_counter==2)
{

write_lcd_ram(3,array_digit[data0 & 0xff]);

write_lcd_ram(4,array_digit[data1 & 0xff]);


if(blink==0)
{write_lcd_ram(5,(array_digit[data2 & 0xff]));blink=1;}
else
{write_lcd_ram(5,0x00);blink=0;}

write_lcd_ram(6,array_digit[data3 & 0xff]);


}
else
if(shift_counter==3)
{

write_lcd_ram(3,array_digit[data0 & 0xff]);

write_lcd_ram(4,array_digit[data1 & 0xff]);


write_lcd_ram(5,
(array_digit[data2 & 0xff]));
if(blink==0)
{write_lcd_ram(6,array_digit[data3 & 0xff]);blink=1;}
else
{write_lcd_ram(6,0x00);blink=0;}
}

if(INC_input==1 && INC_flag==0 )


{

INC_input=0;

if(shift_counter==0)
{
data0+
+;

if(data0>8)

data0=9 ;
}
else
if(shift_counter==1)
{
data1+
+;

if(data1>8)

data1=9 ;
}
else
if(shift_counter==2)
{
data2+
+;

if(data2>8)
data2=9 ;
}
else
if(shift_counter==3)
{
data3+
+;

if(data3>8)

data3=9 ;
}

//disp
lay_value_id(PASSWORD);
}

if(DEC_input==1 && DEC_flag==0 && one_det==0 )


{

DEC_input=0;

if(shift_counter==0)
{

if(data0>=1)

data0--;

}
else
if(shift_counter==1)
{

if(data1>=1)

data1--;

}
else
if(shift_counter==2)
{

if(data2>=1)

data2--;

}
else
if(shift_counter==3)
{

if(data3>=1)

data3--;

}
}

if(OK_input==1 && OK_flag==0)


{

OK_input=0;
//
date_flag=0;

lat_deg=((10*data0)+data1);

lat_min=((10*data2)+data3);

lat_det_flag=0;

write_lcd_ram(7,OK);//DISPLAY OK

general_delay=0;

while(general_delay<500);

if(RESET_input==1 && RESET_flag==0)


{

if(shift_counter<4)

shift_counter++;
else
if(shift_counter>3){

shift_counter=0;

data0=0;data1=0;data2=0;data3=0;data4=0;data5=0; }

RESET_input=0;
}
}

write_lcd_ram(6,0x10);
write_lcd_ram(7,0x10);// display_Press_OK();
lat_ok=1;
while(lat_ok)
{
if(INC_input==1 && INC_flag==0 )
{
INC_input=0;lat_ok=0;
goto lat1;
}
if(DEC_input==1 && DEC_flag==0 )
{
DEC_input=0;lat_ok=0;
goto lat1;
}
if(OK_input==1 && OK_flag==0 )
{
OK_input=0; lat_ok=0;
}
if(RESET_input==1 && RESET_flag==0 )
{
RESET_input=0; lat_ok=0;
goto lat1;
}
}

// voltage upper limit


if(maintenance==1)
{
uvolt1:
clear_lcd();
write_lcd_ram(0,SYNER);
data0=0;data1=0;data2=0;data3=0;data4=0;data5=0;
volt_uflag=1;display_Press_OK();
general_delay=0;
while(general_delay<600);
write_lcd_ram(0,OVER|VOLT|SYNER);//SERIAL NO
write_lcd_ram(1,array_digit[8]);//SERIAL NO
ch0=1;ch1=0;ch2=0; //Port P0 group: AN3 is selected(adcon0 bit 0-
3)
while(volt_uflag==1)
{

volt_c_count=0;volt_upper=0;//ii=0;
for(ik=0;ik<50;ik+
+)
{
adst=1;
while(adst);

volt_c_count=volt_c_count+ad;
}

volt_c_count=(volt_c_count/50);

volt_upper=volt_c_count*(2500/1024);
volt_c_count=932;

display_value(volt_c_count);

if(OK_input==1 && OK_flag==0)


{

OK_input=0;

volt_uflag=0;

volt_c_count=0;volt_upper=0;//ii=0;

for(ik=0;ik<50;ik++)

adst=1;
while(adst);

volt_c_count=volt_c_count+ad;

volt_c_count=(volt_c_count/50);

volt_upper=volt_c_count*(2500/1024);

display_value(volt_upper);

volt_upper_1=(0xff & volt_upper);

volt_upper_2=(0xff &(volt_upper>>8));

write_lcd_ram(7,OK);//DISPLAY OK

general_delay=0;

while(general_delay<500);
}
}

general_delay=0;
while(general_delay<600);

write_lcd_ram(6,0x10);
write_lcd_ram(7,0x10);// display_Press_OK();
uvolt_ok=1;
while(uvolt_ok)
{
if(INC_input==1 && INC_flag==0 )
{
INC_input=0;uvolt_ok=0;
goto uvolt1;
}
if(DEC_input==1 && DEC_flag==0 )
{
DEC_input=0;uvolt_ok=0;
goto uvolt1;
}
if(OK_input==1 && OK_flag==0 )
{
OK_input=0; uvolt_ok=0;
}
if(RESET_input==1 && RESET_flag==0 )
{
RESET_input=0; uvolt_ok=0;
goto uvolt1;
}
}

// voltage lower limit


lvolt1:
clear_lcd();
write_lcd_ram(0,SYNER);
data0=0;data1=0;data2=0;data3=0;data4=0;data5=0;
volt_lflag=1;display_Press_OK();
general_delay=0;
while(general_delay<500);
write_lcd_ram(0,LOW|VOLT|SYNER);//SERIAL NO
write_lcd_ram(1,array_digit[9]);//SERIAL NO
ch0=1;ch1=0;ch2=0; //Port P0 group: AN3 is selected(adcon0 bit 0-
3)
while(volt_lflag==1)
{

volt_c_count=0;volt_upper=0;//ii=0;
for(ik=0;ik<50;ik+
+)
{
adst=1;
while(adst);

volt_c_count=volt_c_count+ad;
}

volt_c_count=(volt_c_count/50);

volt_lower=volt_c_count*(2500/1024);
volt_c_count=932;

display_value(volt_c_count);

if(OK_input==1 && OK_flag==0)


{

OK_input=0;

volt_lflag=0;

volt_c_count=0;volt_lower=0;

for(ik=0;ik<50;ik++)

adst=1;

while(adst);

volt_c_count=volt_c_count+ad;

volt_c_count=(volt_c_count/50);

volt_lower=volt_c_count*(2500/1024);

display_value(volt_lower);

volt_lower_1=(0xff & volt_lower);


volt_lower_2=(0xff &(volt_lower>>8));

write_lcd_ram(7,OK);//DISPLAY OK

general_delay=0;

while(general_delay<500);
}

write_lcd_ram(6,0x10);
write_lcd_ram(7,0x10);// display_Press_OK();
lvolt_ok=1;
while(lvolt_ok)
{
if(INC_input==1 && INC_flag==0 )
{
INC_input=0;lvolt_ok=0;
goto lvolt1;
}
if(DEC_input==1 && DEC_flag==0 )
{
DEC_input=0;lvolt_ok=0;
goto lvolt1;
}
if(OK_input==1 && OK_flag==0 )
{
OK_input=0; lvolt_ok=0;
}
if(RESET_input==1 && RESET_flag==0 )
{
RESET_input=0; lvolt_ok=0;
goto lvolt1;
}
}

//lux upper value


lux_u1:
clear_lcd();
write_lcd_ram(0,SYNER);
general_delay=0;
while(general_delay<600);
lux_uflag=1;display_Press_OK();
general_delay=0;
while(general_delay<500);
write_lcd_ram(8,HI);//LO
write_lcd_ram(9,LIGHT);
write_lcd_ram(1,array_digit[0]);//SERIAL NO
write_lcd_ram(0,0x20|SYNER);//serial No
ch0=1;ch1=1;ch2=0; //actual programme
bits=0;
while(lux_uflag==1)
{
LDR_COUNT=0;
for(ik=0;ik<50;ik++)
{
adst=1;
while(adst);
LDR_COUNT=LDR_COUNT+ad;
}
LDR_COUNT=LDR_COUNT/50;
flux_upper=LDR_COUNT;// to be commented
//flux_upper=255;
display_value(flux_upper);

if(OK_input==1 && OK_flag==0)


{
lux_uflag=0;
OK_input=0;
LDR_COUNT=0;
for(ik=0;ik<50;ik++)
{
adst=1;
while(adst);
LDR_COUNT=LDR_COUNT+ad;
}
LDR_COUNT=LDR_COUNT/50;
flux_upper=LDR_COUNT;// to be commented
//flux_upper=255;
display_value(flux_upper);
bits=1;
}
}

write_lcd_ram(6,0x10);
write_lcd_ram(7,0x10);// display_Press_OK();
ulux_ok=1;
while(ulux_ok)
{
if(INC_input==1 && INC_flag==0 )
{
INC_input=0;ulux_ok=0;
goto lux_u1;
}
if(DEC_input==1 && DEC_flag==0 )
{
DEC_input=0;ulux_ok=0;
goto lux_u1;
}
if(OK_input==1 && OK_flag==0 )
{
OK_input=0; ulux_ok=0;
}
if(RESET_input==1 && RESET_flag==0 )
{
RESET_input=0; ulux_ok=0;
goto lux_u1;
}
}

//lux lower value


lux_l1:
clear_lcd();write_lcd_ram(0,SYNER);
while(general_delay<500);
lux_lflag=1;display_Press_OK();
general_delay=0;
while(general_delay<500);
write_lcd_ram(1,array_digit[1]);//SERIAL NO
write_lcd_ram(0,0x20|SYNER);//serial No
write_lcd_ram(8,LO);//HI
write_lcd_ram(9,LIGHT);
ch0=1;ch1=1;ch2=0; //actual programme
bits=0;
while(lux_lflag==1)
{

LDR_COUNT=0;
for(ik=0;ik<50;ik++)
{
adst=1;
while(adst);
LDR_COUNT=LDR_COUNT+ad;
}
LDR_COUNT=LDR_COUNT/50;
flux_lower=LDR_COUNT;// to be commented
//flux_lower=255;
display_value(flux_lower);

if(OK_input==1 && OK_flag==0)


{
lux_lflag=0;
OK_input=0;LDR_COUNT=0;

for(ik=0;ik<50;ik++)
{
adst=1;
while(adst);
LDR_COUNT=LDR_COUNT+ad;
}
LDR_COUNT=LDR_COUNT/50;
flux_lower=LDR_COUNT; //to be commented
bits=1;
}
}

write_lcd_ram(6,0x10);
write_lcd_ram(7,0x10);// display_Press_OK();
llux_ok=1;
while(llux_ok)
{
if(INC_input==1 && INC_flag==0 )
{
INC_input=0;llux_ok=0;
goto lux_l1;
}
if(DEC_input==1 && DEC_flag==0 )
{
DEC_input=0;llux_ok=0;
goto lux_l1;
}
if(OK_input==1 && OK_flag==0 )
{
OK_input=0; llux_ok=0;
}
if(RESET_input==1 && RESET_flag==0 )
{
RESET_input=0; llux_ok=0;
goto lux_l1;
}
}

// load calibration
load1:
clear_lcd();
write_lcd_ram(0,SYNER);
current_flag=1;display_Press_OK();
general_delay=0;
while(general_delay<600);
write_lcd_ram(1,array_digit[2]);//SERIAL NO
write_lcd_ram(0,0x20|LOAD|OVER|SYNER);//serial No
ch0=0;ch1=1;ch2=0;//AN2 current channel

while(current_flag==1)
{
current_fix_count=0;
current_fix=0;
for(ik=0;ik<50;ik++)
{

adst=1;
while(adst);

current_fix_count=current_fix_count+ad;//((curr_count*2500)/1024)*curr_const;
}

current_fix_count=(current_fix_count/50);

current_fix=current_fix_count*(2500/1024);
current_fix=132;
display_value(current_fix);

if(OK_input==1 && OK_flag==0)


{
current_flag=0;
OK_input=0;
current_fix_count=0;
current_fix=0;
for(ik=0;ik<50;ik++)
{

adst=1;
while(adst);

current_fix_count=current_fix_count+ad;//((curr_count*2500)/1024)*curr_const;
}

current_fix_count=(current_fix_count/50);

current_fix=current_fix_count*(2500/1024);
display_value(current_fix);
current_fix_1=(0xff & current_fix);
current_fix_2=(0xff
&(current_fix>>8));
general_delay=0;
while(general_delay<500);
write_lcd_ram(7,OK);//

}
}
write_lcd_ram(6,PRESS);
write_lcd_ram(7,OK);// display_Press_OK();
load_ok=1;
while(load_ok)
{
if(INC_input==1 && INC_flag==0 )
{
INC_input=0;load_ok=0;
goto load1;
}
if(DEC_input==1 && DEC_flag==0 )
{
DEC_input=0;load_ok=0;
goto load1;
}
if(OK_input==1 && OK_flag==0 )
{
OK_input=0; load_ok=0;
}
if(RESET_input==1 && RESET_flag==0 )
{
RESET_input=0; load_ok=0;
goto load1;
}
}
}
}

void define_pgm(void)
{
display_OK();
general_delay=0;
while(general_delay<1000);// 2 sec
define_sequence();

void define_sequence(void)
{

//display text pasword


sequence_data=1;
general_delay=0;
while(general_delay<1000);
data0=0;data1=0;data2=0;data3=0;shift_counter=0;
sequence_data=1;month_counter=0;
{
while(sequence_data==1)
{
if(shift_counter==0)
{
if(blink==0)
{write_lcd_ram(2,array_digit[data0 & 0xff]);blink=1;}
else
{write_lcd_ram(2,0x00);blink=0;}

write_lcd_ram(3,array_digit[data1 & 0xff]|THREE_P);


write_lcd_ram(4,
(array_digit[data2 & 0xff]));

write_lcd_ram(5,array_digit[data3 & 0xff]);


}
else
if(shift_counter==1)
{

write_lcd_ram(2,array_digit[data0 & 0xff]);


if(blink==0)
{write_lcd_ram(3,array_digit[data1 & 0xff]|THREE_P);blink=1;}
else
{write_lcd_ram(3,0x00|THREE_P);blink=0;}
write_lcd_ram(4,
(array_digit[data2 & 0xff]));

write_lcd_ram(5,array_digit[data3 & 0xff]);


}
else
if(shift_counter==2)
{

write_lcd_ram(2,array_digit[data0 & 0xff]);

write_lcd_ram(3,array_digit[data1 & 0xff]|THREE_P);


if(blink==0)
{write_lcd_ram(4,(array_digit[data2 & 0xff]));blink=1;}
else
{write_lcd_ram(4,0x00);blink=0;}

write_lcd_ram(5,array_digit[data3 & 0xff]);


}
else
if(shift_counter==3)
{

write_lcd_ram(2,array_digit[data0 & 0xff]);

write_lcd_ram(3,array_digit[data1 & 0xff]|THREE_P);


write_lcd_ram(4,
(array_digit[data2 & 0xff]));
if(blink==0)
{write_lcd_ram(4,array_digit[data3 & 0xff]);blink=1;}
else
{write_lcd_ram(5,0x00);blink=0;}
}
if(month_counter
%2==0)
{

write_lcd_ram(9,0x00);//on time
write_lcd_ram(4,(array_digit[data2 & 0xff])|ON);//on time

write_lcd_ram(5,array_digit[data3 & 0xff]|TIME);

}
else
{

write_lcd_ram(9,OFF);//on time

write_lcd_ram(5,array_digit[data3 & 0xff]|TIME);

if(month_counter==0 || month_counter==1)
{

write_lcd_ram(1,array_digit[1]);
}
else
if(month_counter==2 || month_counter==3)
{

write_lcd_ram(1,array_digit[2]);
}
else
if(month_counter==4 || month_counter==5)
{

write_lcd_ram(1,array_digit[3]);
}
else
if(month_counter==6 || month_counter==7)
{

write_lcd_ram(1,array_digit[4]);
}
else
if(month_counter==8 || month_counter==9)
{

write_lcd_ram(1,array_digit[5]);
}
else
if(month_counter==10 || month_counter==11)
{

write_lcd_ram(1,array_digit[6]);
}
else
if(month_counter==12 || month_counter==13)
{

write_lcd_ram(1,array_digit[7]);
}
else
if(month_counter==14 || month_counter==15)
{

write_lcd_ram(1,array_digit[8]);
}
else
if(month_counter==16 || month_counter==17)
{

write_lcd_ram(1,array_digit[9]);
}
else
if(month_counter==18 || month_counter==19)
{

write_lcd_ram(1,array_digit[0]);

write_lcd_ram(0,OP|SYNER);
}
else
if(month_counter==20 || month_counter==21)
{

write_lcd_ram(1,array_digit[1]);

write_lcd_ram(0,OP|SYNER);
}
else
if(month_counter==22 || month_counter==23)
{

write_lcd_ram(1,array_digit[2]);

write_lcd_ram(0,OP|SYNER);
}

if(INC_input==1 &&
INC_flag==0 )
{

INC_input=0;

if(shift_counter==0)
{
data0+
+;

if(data0>2)

data0=2 ;

if(data0*10+data1>23){data0=2;data1=3;}
}
else
if(shift_counter==1)
{
data1+
+;

if(data0==2)
{

if(data1>3)

data1=3 ;

else

if(data0<2)

if(data1>9)

data1=9 ;

if(data0*10+data1>23){data0=2;data1=3;}
}
else
if(shift_counter==2)
{
data2+
+;

if(data2>5)

data2=5 ;
}
else
if(shift_counter==3)
{
data3+
+;

if(data3>8)

data3=9 ;
}
//disp
lay_value_id(PASSWORD);
}

if(DEC_input==1 && DEC_flag==0 )


{

DEC_input=0;

if(shift_counter==0)
{
data0--;

if(data0<1)

data0=0;

if(data0*10+data1>23){data0=2;data1=3;}
}
else
if(shift_counter==1)
{

data1--;

if(data1<1)

data1=0 ;

if(data0*10+data1>23){data0=2;data1=3;}
}
else
if(shift_counter==2)
{

data2--;

if(data2<1)

data2=0;
}
else
if(shift_counter==3)
{

data3--;

if(data3<1)

data3=0;
}

if(OK_input==1 && OK_flag==0)


{

OK_input=0;shift_counter=0;

general_delay=0;

while(general_delay<500);

//sequ
ence_data=1;
//data
0=0;data1=0;data2=0;data3=0;
//if(s
hift_counter==4)
{
display_OK();//for two second

general_delay=0;

while(general_delay<500);

month_counter++;

if(month_counter%2==0)

array_hour[month_counter]=(10*data0)+data1;

array_min[month_counter]=(10*data2)+data3;

else

array_hour[month_counter]=(10*data0)+data1;

array_min[month_counter]=(10*data2)+data3;

if(month_counter<=24)

if(month_counter==24)

{sequence_data=0;}

shift_counter=0;

data0=0;data1=0;data2=0;data3=0;

//serial_no_display(month_counter);
}
}

if(RESET_input==1 && RESET_flag==0)


{

shift_counter++;

if(shift_counter>3)

shift_counter=0;
RESET_input=0;
}
}
}
}

void display_OK(void)
{
write_lcd_ram(7,0x10);//
}

void display_default_define(void)
{
default_define=0;default_flag=0;define_flag=0;
clear_lcd();
write_lcd_ram(0,SYNER);
while(default_define==0)
{
while(default_flag==0)
{
write_lcd_ram(8,0x01);////display_default();
general_delay_flag=1;
if(general_delay_counter>1000)//2 sec
{
general_delay_flag=0;
general_delay_counter=0;
default_flag=1;
define_flag=0;
}
else if(OK_input==1 && OK_flag==0)
{

default_define_select=0x00;// for dafult program to


execute
default_define=1;
OK_input=0;
define_flag=1;
default_flag=1;
}
}
while(define_flag==0)
{
write_lcd_ram(8,0x10);//display_define();
general_delay_flag=1;
if(general_delay_counter>1000)
{
general_delay_flag=0;
general_delay_counter=0;
define_flag=1;//display_define();
default_flag=0;
}
else if(OK_input==1 && OK_flag==0)
{
define_pgm();
default_define=1;
default_define_select=0xab;// for define program to
execute
OK_input=0;
define_flag=1;//display_define();
default_flag=1;
}
}
}
default_pgm();
}

void Display_Prog_set(void)
{
write_lcd_ram(2,0x67);//P
write_lcd_ram(3,0xE7);//R
write_lcd_ram(4,0xCF);//G
write_lcd_ram(5,array_digit[5]);//S
write_lcd_ram(6,0x4f);//E
write_lcd_ram(7,0x4e);//t
}
void init(void)
{

prc3=1;
vca25=1;
vw0c0=1;
vw0c6=1;
//**************************************
// Port0 Setting
//**************************************
//Read/write data to register P0
prc2=1; //Enable write to PD0
pd0=0x87; // Port P0 direction register
// pu01=1; // Pull-ups for P04 - P07 on
// pu00=1;

//**************************************
// Port1 Setting
//**************************************
//Read/write data to register P1
pd1=0x10; // Port P1 direction register
pu02=1; // Pull-ups for P10 - P13 on
pu03=1; // Pull-ups for P14 - P17 on

//**************************************
// Port2 Setting
//**************************************
//Read/write data to register P2
pd2=0xFF; // Port P2 direction register
p2drr=0x00; // Port P2 drive capacity control
register

//**************************************
// Port3 Setting
//**************************************
//Read/write data to register P3
pd3=0xAB; // Port P3 direction register
pu06=1; // Pull-ups for P30, P31 and P33 on

//**************************************
// Port4 Setting
//**************************************
//Read/write data to register P4
pd4=0x00; //Port P4 direction register
pu11=1; // Pull-ups for P44 - P45 on

//**************************************
// Port6 Setting
//**************************************
//Read/write data to register P6
pd6=0x3F; // Port P6 direction register
pu15=1; // Pull-ups for P64 - P67 on
p6_2=0;
p6_1=0;

//2 msec delay


//**************************************
// Timer RA Setting// 2msec
//**************************************
tck0_tramr=0;tck1_tramr=0;tck2_tramr=0; //count source:f1(tramr bit 4 to 6)
trapre=249; //Timer value for timer mode or half
period timing for pulse output mode
tra=159; //Timer value for timer mode or half
period timing for pulse output mode
tmod0_tramr=0;tmod1_tramr=0;tmod2_tramr=0;//Timer mode(tramr bit 0-2)
traic=0x06; //Set interrupt piority level
7(traic)
tstart_tracr=1; //Set tstart_tracr=1 to start Timer RA counting
//Note: Timer RA does not start yet for event counter mode. The first active
edge of external signal is used not to decrement the timer count register but to
start timer RA. The second active edge will trigger the first decrement on timer
count register.

//**************************************
// ADC Setting
//**************************************
//When using the repeat mode, use the undivided XIN clock as the CPU clock.
Do not select the fOCO-F as ADC operating clock
//Note:For 8-bit resolution, when conversion finished, read AD result at AD
register(00C0H).
//Note:For 10-bit resolution, when conversion finished, read AD result at AD
register(00C0H,00C1H).
//Set AN0 pin to input port direction

prc2=1;
pd0_4=0;// LDR1//an3
pd0_3=0;// LDR2//an4
pd0_6=0;//VDC//an1
pd0_5=0;//Idcan2
pu00=1;pu01=1;
vcut=1;adgsel0=0;ch0=0;ch1=0;ch2=1; //Port P0 group: AN4 is
selected(adcon0 bit 0-3)
vcut=1;adgsel0=0;ch0=1;ch1=0;ch2=0; //Port P0 group: AN1 is
selected(adcon0 bit 0-3)
vcut=1;adgsel0=0;ch0=0;ch1=1;ch2=0; //Port P0 group: AN2 is
selected(adcon0 bit 0-3)
vcut=1;adgsel0=0;ch0=1;ch1=1;ch2=0; //Port P0 group: AN3 is
selected(adcon0 bit 0-3)

md=0; //One-shot mode selected(adcon0 bit


3)
cks1=0; cks0=0; //f4 selected(adcon1 bit 4 and
adcon0 bit 7)
bits=1; //8-bit mode selected(adcon1 bit 3)
smp=0; //Without sample and hold
selected(adcon2 bit 0)
adst=1; //A/D conversion starts(adcon0 bit
6)
adic=0x00; //Set interrupt piority level
0(adic)

//**************************************
// INT0 Interrupt Setting
//**************************************
//Note: Set INT0 hardware interrupt pins to input.
int0ic=0x17; //Set interrupt piority level and
active edge(int0ic)
int0en=1; //Input enable enabled(inten bit 0)
int0pl=0; //One edge selected(inten bit 1)
int0f0=0; int0f1=0; //No filter selected(intf bit 0 and
1)

//**************************************
// Key Input Interrupt Setting
//**************************************
//Note: Set key input hardware interrupt pins to input.
kupic=0xFF; //Interrupt piority level 7
selected(kupic bit 0-3)
kien=0x07; //Set key input enable and input
polarity

/// 2msec interrupt of timer


void timer(void)
{
if(upper_count_start==1)
{
upper_count++;
}
if(lower_count_start==1)
{
lower_count++;
}

if(relay_already_on==1 && relay_already_off==0)//make relay on


{
AB_LED=1;//green
NO_LED=0;//red
}
else if(relay_already_on==0 && relay_already_off==1)//make relay on
{
if(VOLT_FAULT_FLAG==1 || CURRENT_FAULT_FLAG==1)
{
AB_LED=0;//green
Blink_counter++;
if(Blink_counter>500)
{
NO_LED=~NO_LED;//red
Blink_counter=0;
}
}
else
{
AB_LED=0;//green
NO_LED=1;//red
}
}

//Restart WDT
if(watch_dog==1)
{
wdtr = 0x00;
wdtr = 0xff;
}

if(surge_check_flag==1)
surge_check_counter++;
else
surge_check_counter=0;

indication_counter++;

if(get_out_counter==1)
get_out_count++;
else
get_out_count=0;

if(initial_flag==1)
initial_counter++;

if(initial_counter>10000)initial_flag=0;

if(cyclic_flag==1)
cyclic_count++;

if(general_delay_flag==1)
general_delay_counter++;
else
general_delay_counter=0;

if(general_delay<5000)
general_delay++;

if(key_bounce_flag==1)
{
key_bounce_counter++;
if(key_bounce_counter>=100)
{
key_bounce_counter=0;key_bounce_flag=0;
}
}

if(start_counter==1)
relay_on_off_counter++;
key_scan();
RTC_CALCULATE++;
}

void VOLT_CURR_CAL(void)
{
ch0=1;ch1=0;ch2=0; //Port P0 group: AN3 is selected(adcon0 bit 0-3)
volt_c_count=0;//ii=0;
for(ik=0;ik<100;ik++)
{
adst=1;
while(adst);
volt_c_count=volt_c_count+ad;
asm("nop");
}
volt_c_count=(volt_c_count/100);
volt_data=volt_c_count*(2500/1024);
if(0<volt_data<50)
asm("nop");

ch0=0;ch1=1;ch2=0;//AN2 current channel


current_fix_count=0;
for(ik=0;ik<100;ik++)
{
adst=1;
while(adst);
current_fix_count=current_fix_count+ad;//((curr_count*2500)/1024)*curr_const;
}
current_fix_count=(current_fix_count/100);
curr_data=current_fix_count*(2500/1024);
}

void LDR_CALCULATION(void)
{
ch0=1;ch1=1;ch2=0; //actual port
bits=0;LDR_COUNT=0;
for(ik=0;ik<200;ik++)
{
adst=1;
while(adst);
LDR_COUNT=LDR_COUNT+ad;
LDR_flag=1;
}
bits=1;
LDR_COUNT=LDR_COUNT/200;
}

void key_scan(void)
{

if(key_bounce_flag==0)
{
if(INC==0)// && DEC==1 && OK==1 && RESET==1)
{
key_bounce_flag=1;
INC_input=1;
}
else
{
INC_input=0;
INC_flag=0;
one_det=0;
}

if(DEC==0)// && INC==1 && OK==1 && RESET==1)


{
key_bounce_flag=1;
DEC_input=1;
}
else
{
DEC_input=0;
DEC_flag=0;
one_det=0;
}

if(p1_2==0)// && DEC==1 && INC==1 &&


RESET==1)
{
key_bounce_flag=1;
OK_input=1;
}
else
{
OK_input=0;
OK_flag=0;
one_det=0;
}
if(RESET==0)// && DEC==1 && OK==1 &&
INC==1)
{
key_bounce_flag=1;
RESET_input=1;
}
else
{
RESET_input=0;
RESET_flag=0;
one_det=0;
}

if(RESET==0 && DEC==0 && OK==1 &&


INC==1)
{
key_bounce_flag=1;
password_input=1;
}
else
{
//password_input=0;
password_flag=0;
}
}
}
///////////////////RTC code///////
void vTime_Init(void)
{

WriteBYTE(0x00,0x00);idelay();//added//0x08
WriteBYTE(0x01,0x00);idelay();//added//0x08
WriteBYTE(0x02,0x00);idelay();//added//0x08
WriteBYTE(0x03,0x01);idelay();//added//0x08
WriteBYTE(0x04,0x01);idelay();//added//0x08
WriteBYTE(0x05,0x01);idelay();//added//0x08
WriteBYTE(0x06,0x01);idelay();//added//0x08
WriteBYTE(0x07,0x80);idelay();//added//0x08
idelay();//added
idelay();//added
idelay();//added

ReadRTC(&RTC_ARR[0]);
RTC_ARR[0] = 0x80;//0;//0x00; //RTC_ARR[0] & 0x7F; // enable
oscillator (bit 7=0)
RTC_ARR[1]
=myDec2Bcd(in_min);//in_min;//0x24;//in_min;//0x37;//55;//in_minhour_dec;//0x00;
// minute = 59
RTC_ARR[2]
=myDec2Bcd(in_hour);;//in_hour;//0x20;//in_hour;//5;//in_hhour_decour; // hour = 05
,24-hour mode(bit 6=0)
RTC_ARR[3] =0x09;// Day = 1 or Mon n 3rd bitvbate
RTC_ARR[4]
=myDec2Bcd(in_date);;//in_date;//0x05;//in_date;//0x1e;//in_date; // Date = 30
RTC_ARR[5]
=myDec2Bcd(in_month);;//in_month;//0x06;//in_month;//1;//in_month; // month =
August
RTC_ARR[6] =myDec2Bcd(in_year);;//in_year;//9;//in_year; // year = 20
RTC_ARR[7] =0x03;//
//0x40;//for pulse out put

do
{
WriteRTC(&RTC_ARR[0]); // Set RTC
for(im=0;im<=300;im++);
ReadRTC(&RTC_ARR[0]);
asm("nop");
}
while((ob.hour_ob2.hour_bcd!=myDec2Bcd(in_hour))&&
(ob.date_ob2.date_bcd!=myDec2Bcd(in_date))&& (ob.month_ob2.month_bcd!
=myDec2Bcd(in_month))&& (ob.year_ob2.year_bcd!=myDec2Bcd(in_year)));
asm("nop");
}
}

void WriteRTC(unsigned char *buff)


{

Start();
WriteI2C(0xDE);
idelay();//added
WriteI2C(0x00);
idelay();//added
WriteI2C(*(buff+0));
idelay();//added
WriteI2C(*(buff+1));
idelay();//added
WriteI2C(*(buff+2));
idelay();//added
WriteI2C(*(buff+3));
idelay();//added
WriteI2C(*(buff+4));
idelay();//added
WriteI2C(*(buff+5));
idelay();//added
WriteI2C(*(buff+6));
idelay();//added
WriteI2C(*(buff+7));
Stop();
idelay();//added
//WriteBYTE(0x08,*(buff+6));//0x08 // commented on 13may 2012
// WriteBYTE(0x08,0xE6);//Syner subtraction
WriteBYTE(0x08,50);//syner subtraction
idelay();//added
}

//void WriteBYTE(unsigned char Addr,unsigned char Data)

void WriteI2C(unsigned char Data)


{
unsigned char i;
SCL=0;
idelay();

for (i=0;i<8;i++)
{
SDA = (Data & 0x80) ? 1:0;
Data<<=1;
idelay();
SCL=1;
idelay();
idelay();
SCL=0;
idelay();
}
SDA = 1;
SDA_Input;
idelay();
SCL = 1;
idelay();
idelay();
SDA_Output;
SCL = 0;
}
void WriteBYTE(unsigned char Addr,unsigned char Data)
{
Start();
WriteI2C(0xDE);
WriteI2C(Addr);
WriteI2C(Data);
Stop();
}

void idelay(void)
{
int i;
for (i=0; i<2; i++);//i<2
}

void ReadRTC(unsigned char * buff)


{
Start();
WriteI2C(0xDE);
WriteI2C(0x00);
Start();
WriteI2C(0xDF);
ob.sec_ob2.sec_bcd=ReadI2C(RTC_ACK); // Second
ob.sec_ob2.sec_bcd=(ob.sec_ob2.sec_bcd & 0x7F);
ob.min_ob2.min_bcd=ReadI2C(RTC_ACK); // Minute
ob.min_ob2.min_bcd= (ob.min_ob2.min_bcd & 0x7F);
ob.hour_ob2.hour_bcd=ReadI2C(RTC_ACK); // hour
ob.hour_ob2.hour_bcd=(ob.hour_ob2.hour_bcd & 0x3F);
ob.day_ob2.day_bcd=ReadI2C(RTC_ACK); // Day
ob.day_ob2.day_bcd=(ob.day_ob2.day_bcd & 0x07);
ob.date_ob2.date_bcd=ReadI2C(RTC_ACK); // date
ob.date_ob2.date_bcd= (ob.date_ob2.date_bcd & 0x3F);
ob.month_ob2.month_bcd=ReadI2C(RTC_ACK); // month
ob.month_ob2.month_bcd= (ob.month_ob2.month_bcd & 0x1F);
ob.year_ob2.year_bcd=ReadI2C(RTC_ACK); // year
ob.year_ob2.year_bcd=(ob.year_ob2.year_bcd & 0xff);
Stop();

void Start(void)
{
SDA = 1;
SCL = 1;
idelay();
idelay();
SDA = 0;
idelay();
idelay();
SCL = 0;
idelay();
}
void Stop(void)
{
SDA = 0;
idelay();
idelay();
SCL = 1;
idelay();
idelay();
SDA = 1;
idelay();
}

unsigned char ReadI2C(char ACK_Bit)


{

unsigned char Data=0,i;

SCL = 0;

SDA_Input;
// SDA = 1;
for (i=0;i<8;i++)
{
Data<<= 1;
SCL = 1;
idelay();
idelay();
Data = (Data | SDA);
SCL = 0;
idelay();
}

SDA_Output;
idelay();

if (ACK_Bit == 1)
SDA = 0; // Send ACK
else
SDA = 1; // Send NO ACK

idelay();
SCL = 1;
idelay();
idelay();
SCL = 0;
idelay();
idelay();
SDA = 1;
idelay();
return Data;
}

void sun_set_rise(void)
{
//while(1)
/*{
do
{
ReadRTC(&RTC_ARR[0]);
BCD_DECIMAL();
}
while((date_dec>31) || (month_dec>12) || (year_dec>99) || (hour_dec>23) ||
(min_dec>59) || second_dec >59);
}*/

// LATTITUDE=11.52;
// LONGTITUDE=75.21;
LATTITUDE=((float)lat_min)/100;
LATTITUDE=LATTITUDE+lat_deg;

LONGTITUDE=((float)long_min)/100;
LONGTITUDE=LONGTITUDE+long_degree;
date_value(date_dec,month_dec,year_dec);//ok
//date_value(2,12,15);//DV we got //E --->ok
JULIAN_DAY(K_DV);//F //JULIAN DAY --->OK
JULIAN_CENTU(K_JULI_DAY);//G JULIAN CENT --->OK
MEAN_OBLIQ_ECLIPTIC(K_JUL_CENT);//Q2 mean obliq_ecliptic -->OK
GEO_MEAN_ANOM_SUN(K_JUL_CENT);//J2 GEO_MEAN_ANOM_SUN--->OK
SUN_EQN_CTR(K_GEO_MEAN_ANOM_SUN,K_JUL_CENT);//L2 SUN_EQN_of CTR--> deviation
in result
GEO_MEAN_LONG_SUN(K_JUL_CENT);//GEO_MEAN_LONG_SUN I2--> slight point
deviation
SUN_TRUE_LONG(K_GEO_MEAN_LONG_SUN,K_SUN_EQN_CTR);//M2 SUN_TRUE_LONG -->
slight point deviation
SUN_APP_LONG(K_SUN_TRUE_LONG,K_JUL_CENT);//P2 SUN_APP_LONG --> slight point
deviation
OBLIQ_CORR(K_M_OBLIQ_ECLIPTIC,K_JUL_CENT);//R2 OBLIQ_CORR --> slight point
deviation
ECCENT_EARTH_ORBIT(K_JUL_CENT);//K2 Eccent Earth Orbit --> slight point
deviation
VAR_Y(K_OBLIQ_CORR);// U2 VARY_Y --> slight point deviation
SUN_DECLINE(K_OBLIQ_CORR,K_SUN_APP_LONG);//Sun Declin (deg) T2

EQN_OF_TIME(K_VAR_Y,K_GEO_MEAN_LONG_SUN,K_GEO_MEAN_ANOM_SUN,K_ECCENT_EARTH_ORBIT);/
/V2 EQN OF TIME
HA_SUNRISE(K_SUN_DECLINE,LATTITUDE);//W2
SOLAR_NOON(LONGTITUDE,5.5,K_EQN_OF_TIME);//solar noon X
SUNRISE_TIME(K_SOLAR_NOON,K_HA_SUNRISE);//Y sunrise
SUNSET_TIME(K_SOLAR_NOON,K_HA_SUNRISE);//Z sunset

total_hr=K_SUNRISE_TIME*24;
sunrise_hour=(char)total_hr;
sunrise_min=(total_hr-sunrise_hour)*60;
total_hr=K_SUNSET_TIME*24;
sunset_hour=(char)total_hr;
sunset_min=(total_hr-sunset_hour)*60;
asm("NOP");
}

void BCD_DECIMAL(void)
{
second_dec=myBcd2Dec(ob.sec_ob2.sec_bcd);//
(10*(4*(ob.sec_ob2.sec_ob1.sec_bcd_6)+2*(ob.sec_ob2.sec_ob1.sec_bcd_5)+1*(ob.sec_ob
2.sec_ob1.sec_bcd_4))) +
(8*(ob.sec_ob2.sec_ob1.sec_bcd_3)+4*(ob.sec_ob2.sec_ob1.sec_bcd_2)+2*(ob.sec_ob2.se
c_ob1.sec_bcd_1)+1*(ob.sec_ob2.sec_ob1.sec_bcd_0));
min_dec=myBcd2Dec(ob.min_ob2.min_bcd );//
(10*(4*(ob.min_ob2.min_ob1.min_bcd_6)+2*(ob.min_ob2.min_ob1.min_bcd_5)+1*(ob.min_ob
2.min_ob1.min_bcd_4))) +
(8*(ob.min_ob2.min_ob1.min_bcd_3)+4*(ob.min_ob2.min_ob1.min_bcd_2)+2*(ob.min_ob2.mi
n_ob1.min_bcd_1)+1*(ob.min_ob2.min_ob1.min_bcd_0));
hour_dec=myBcd2Dec(ob.hour_ob2.hour_bcd);//
(10*(4*(0)+2*(ob.hour_ob2.hour_ob1.hour_bcd_5)+1*(ob.hour_ob2.hour_ob1.hour_bcd_4))
) +
(8*(ob.hour_ob2.hour_ob1.hour_bcd_3)+4*(ob.hour_ob2.hour_ob1.hour_bcd_2)+2*(ob.hour
_ob2.hour_ob1.hour_bcd_1)+1*(ob.hour_ob2.hour_ob1.hour_bcd_0));
day_dec=myBcd2Dec(ob.day_ob2.day_bcd);//(10*(4*(0)+2*(0)+1*(0))) +
(8*(0)+4*(ob.day_ob2.day_ob1.day_bcd_2)+2*(ob.day_ob2.day_ob1.day_bcd_1)+1*(ob.day_
ob2.day_ob1.day_bcd_0));
date_dec=myBcd2Dec(ob.date_ob2.date_bcd);//
(10*(4*(0)+2*(ob.date_ob2.date_ob1.date_bcd_5)+1*(ob.date_ob2.date_ob1.date_bcd_4))
) +
(8*(ob.date_ob2.date_ob1.date_bcd_3)+4*(ob.date_ob2.date_ob1.date_bcd_2)+2*(ob.date
_ob2.date_ob1.date_bcd_1)+1*(ob.date_ob2.date_ob1.date_bcd_0));
month_dec=myBcd2Dec(ob.month_ob2.month_bcd);//
(10*(4*(0)+2*(0)+1*(ob.month_ob2.month_ob1.month_bcd_4))) +
(8*(ob.month_ob2.month_ob1.month_bcd_3)+4*(ob.month_ob2.month_ob1.month_bcd_2)+2*(o
b.month_ob2.month_ob1.month_bcd_1)+1*(ob.month_ob2.month_ob1.month_bcd_0));
year_dec=myBcd2Dec(ob.year_ob2.year_bcd);//
(10*(8*(ob.year_ob2.year_ob1.year_bcd_7)+(4*(ob.year_ob2.year_ob1.year_bcd_6)+2*(ob
.year_ob2.year_ob1.year_bcd_5)+1*(ob.year_ob2.year_ob1.year_bcd_4)))) +
(8*(ob.year_ob2.year_ob1.year_bcd_3)+4*(ob.year_ob2.year_ob1.year_bcd_2)+2*(ob.year
_ob2.year_ob1.year_bcd_1)+1*(ob.year_ob2.year_ob1.year_bcd_0));
}

void clear_lcd(void)
{
unsigned char loop=0;
for(loop==0;loop<=9;loop++)
{
write_lcd_ram(loop,0x00);//s
}
}

void display_value(unsigned int data)


{
unsigned char unit,ten,hundred,thousand;
unit=(data%10);
data=(data-unit)/10;
ten=data%10;
data=(data-ten)/10;
hundred=data%10;
data=(data-hundred)/10;
thousand=data;

if(thousand==0)
write_lcd_ram(2,array_digit[0]);
else if (thousand==1)
write_lcd_ram(2,array_digit[1]);
else if (thousand==2)
write_lcd_ram(2,array_digit[2]);
else if (thousand==3)
write_lcd_ram(2,array_digit[3]);
else if (thousand==4)
write_lcd_ram(2,array_digit[4]);
else if (thousand==5)
write_lcd_ram(2,array_digit[5]);
else if (thousand==6)
write_lcd_ram(2,array_digit[6]);
else if (thousand==7)
write_lcd_ram(2,array_digit[7]);
else if (thousand==8)
write_lcd_ram(2,array_digit[8]);
else if (thousand==9)

if(hundred==0)
write_lcd_ram(3,array_digit[0]);
else if (hundred==1)
write_lcd_ram(3,array_digit[1]);
else if (hundred==2)
write_lcd_ram(3,array_digit[2]);
else if (hundred==3)
write_lcd_ram(3,array_digit[3]);
else if (hundred==4)
write_lcd_ram(3,array_digit[4]);
else if (hundred==5)
write_lcd_ram(3,array_digit[5]);
else if (hundred==6)
write_lcd_ram(3,array_digit[6]);
else if (hundred==7)
write_lcd_ram(3,array_digit[7]);
else if (hundred==8)
write_lcd_ram(3,array_digit[8]);
else if (hundred==9)
write_lcd_ram(3,array_digit[9]);

if(ten==0)
write_lcd_ram(4,array_digit[0]);
else if (ten==1)
write_lcd_ram(4,array_digit[1]);
else if (ten==2)
write_lcd_ram(4,array_digit[2]);
else if (ten==3)
write_lcd_ram(4,array_digit[3]);
else if (ten==4)
write_lcd_ram(4,array_digit[4]);
else if (ten==5)
write_lcd_ram(4,array_digit[5]);
else if (ten==6)
write_lcd_ram(4,array_digit[6]);
else if (ten==7)
write_lcd_ram(4,array_digit[7]);
else if (ten==8)
write_lcd_ram(4,array_digit[8]);
else if (ten==9)
write_lcd_ram(4,array_digit[9]);

if(unit==0)
write_lcd_ram(5,array_digit[0]);
else if (unit==1)
write_lcd_ram(5,array_digit[1]);
else if (unit==2)
write_lcd_ram(5,array_digit[2]);
else if (unit==3)
write_lcd_ram(5,array_digit[3]);
else if (unit==4)
write_lcd_ram(5,array_digit[4]);
else if (unit==5)
write_lcd_ram(5,array_digit[5]);
else if (unit==6)
write_lcd_ram(5,array_digit[6]);
else if (unit==7)
write_lcd_ram(5,array_digit[7]);
else if (unit==8)
write_lcd_ram(5,array_digit[8]);
else if (unit==9)
write_lcd_ram(5,array_digit[9]);

void display_value_id(unsigned int data)


{
unsigned char unit,ten,hundred,thousand;
unit=(data%10);
data=(data-unit)/10;
ten=data%10;
data=(data-ten)/10;
hundred=(data%10);
data=(data-hundred)/10;
thousand=data;

if(thousand==0)
write_lcd_ram(2,array_digit[0]);
else if (thousand==1)
write_lcd_ram(2,array_digit[1]);
else if (thousand==2)
write_lcd_ram(2,array_digit[2]);
else if (thousand==3)
write_lcd_ram(2,array_digit[3]);
else if (thousand==4)
write_lcd_ram(2,array_digit[4]);
else if (thousand==5)
write_lcd_ram(2,array_digit[5]);
else if (thousand==6)
write_lcd_ram(2,array_digit[6]);
else if (thousand==7)
write_lcd_ram(2,array_digit[7]);
else if (thousand==8)
write_lcd_ram(2,array_digit[8]);
else if (thousand==9)
write_lcd_ram(2,array_digit[9]);

if(hundred==0)
write_lcd_ram(3,array_digit[0]);
else if (hundred==1)
write_lcd_ram(3,array_digit[1]);
else if (hundred==2)
write_lcd_ram(3,array_digit[2]);
else if (hundred==3)
write_lcd_ram(3,array_digit[3]);
else if (hundred==4)
write_lcd_ram(3,array_digit[4]);
else if (hundred==5)
write_lcd_ram(3,array_digit[5]);
else if (hundred==6)
write_lcd_ram(3,array_digit[6]);
else if (hundred==7)
write_lcd_ram(3,array_digit[7]);
else if (hundred==8)
write_lcd_ram(3,array_digit[8]);
else if (hundred==9)
write_lcd_ram(3,array_digit[9]);

if(ten==0)
write_lcd_ram(4,array_digit[0]);
else if (ten==1)
write_lcd_ram(4,array_digit[1]);
else if (ten==2)
write_lcd_ram(4,array_digit[2]);
else if (ten==3)
write_lcd_ram(4,array_digit[3]);
else if (ten==4)
write_lcd_ram(4,array_digit[4]);
else if (ten==5)
write_lcd_ram(4,array_digit[5]);
else if (ten==6)
write_lcd_ram(4,array_digit[6]);
else if (ten==7)
write_lcd_ram(4,array_digit[7]);
else if (ten==8)
write_lcd_ram(4,array_digit[8]);
else if (ten==9)
write_lcd_ram(4,array_digit[9]);

if(unit==0)
write_lcd_ram(5,array_digit[0]);
else if (unit==1)
write_lcd_ram(5,array_digit[1]);
else if (unit==2)
write_lcd_ram(5,array_digit[2]);
else if (unit==3)
write_lcd_ram(5,array_digit[3]);
else if (unit==4)
write_lcd_ram(5,array_digit[4]);
else if (unit==5)
write_lcd_ram(5,array_digit[5]);
else if (unit==6)
write_lcd_ram(5,array_digit[6]);
else if (unit==7)
write_lcd_ram(5,array_digit[7]);
else if (unit==8)
write_lcd_ram(5,array_digit[8]);
else if (unit==9)
write_lcd_ram(5,array_digit[9]);
}

//////////VOID READ DATA/////////

void read_data(void)
{
unsigned char ii;
if(*read_addr != 0xFF)
{
// read_addr--;
for(ii=(data_size-1);ii>0;ii--)
{
read_array[ii]=*read_addr;
read_addr--;
}
read_array[ii]=*read_addr;
read_addr--;
}
else
{
for(ii=(data_size-1);ii>0;ii--)
{
read_array[ii]=0;
}
}
}

void addr_init(void){

write_addr = BLOCK_A;

// Bank record check


while( write_addr <= BLOCK_B_END ){
// Record all ff check
for(;;)
{
if( *write_addr != 0xff )
{
write_addr++; // Check address renew
array_size=0;
}
else
{
write_addr++;
array_size++;
if(array_size==data_size)
{
write_addr=write_addr-data_size;
goto here;
}
}
}
}
here:
if(write_addr >= BLOCK_B_END+1){
/* if BLOCK A and BLOCK B are full then BLOCK A erase */
block_erase(BLOCK_A);
write_addr = BLOCK_A;
read_addr = BLOCK_B_END;
block_select = BLOCK_A_SELECT;
}else if(write_addr >= BLOCK_B){
/* Use BLOCK B */
block_select = BLOCK_B_SELECT;
if(write_addr != BLOCK_B) read_addr = write_addr - 1;
else read_addr = write_addr;

}else{
/* Use BLOCK A */
block_select = BLOCK_A_SELECT;
if(write_addr != BLOCK_A) read_addr = write_addr - 1;
else read_addr = write_addr;
}

}// End Function

/
***********************************************************************************
*
Name: block_erase
Parameters: Erase block address
Returns: Erase result
Description: Block erase
***********************************************************************************
*/
unsigned char block_erase(unsigned char *ers_addr){
unsigned char erase_result;
/* If use interrupt then clear i flag... */
/* asm("fclr i "); */

/* flash control register set */


fmr01 = 0;
asm(" "); /* Description for preventing the abbreviation by
optimization */
fmr01 = 1; /* CPU rewrite enable */
fmr11 = 0;
asm(" "); /* Description for preventing the abbreviation by
optimization */
fmr11 = 1; /* EW1 mode */

*ers_addr = 0x20; /* Block erase command write


*/
*ers_addr = 0xd0; /* Block erase command write
*/
while( fmr00 != 1 ); /* Ready check */

/* Erase status check */


if( fmr07 == 1 ){
*ers_addr = 0x50; /* Clear stutus register */
erase_result = ERASE_ERR;
}else{
erase_result = COMPLETE;
}
/* flash control register reset */
fmr01 = 0; /* CPU rewrite disable */

/* If use interrupt then set i flag... */


/* asm("fset i "); */

return erase_result;
}

unsigned char flash_write(unsigned char *data){


unsigned char result = COMPLETE;

if( data_write( data ) != COMPLETE ){


/* Program error occurence */
result = result | PROGRAM_ERR; /* if program error
*/
}
/* Next write address update */
write_addr++;

if( (block_select == BLOCK_A_SELECT) && (write_addr > BLOCK_A_END) ){


/* BLOCK A all write */
if( block_erase( BLOCK_B ) != COMPLETE ){
/* Erase error occurence */
result = result | ERASE_ERR;
}
block_select = BLOCK_B_SELECT;
write_addr = BLOCK_B;
}else if((block_select == BLOCK_B_SELECT) && (write_addr > BLOCK_B_END) ){
/* BLOCK B all write */
if( block_erase( BLOCK_A ) != COMPLETE ){
/* Erase error occurence */
result = result | ERASE_ERR;
}
block_select = BLOCK_A_SELECT;
write_addr = BLOCK_A;
}

return result;

/
***********************************************************************************
*
Name: data_write
Parameters: Record data address
Returns: Program result
Description: Record program
***********************************************************************************
*/
unsigned char data_write( unsigned char *write_data ){
unsigned char program_result = COMPLETE;
int i; /* loop counter
*/
/* If use interrupt then clear i flag... */
/* asm("fclr i "); */

/* flash control register set */


fmr01 = 0;
asm(" "); /* Description for preventing the abbreviation by
optimization */
fmr01 = 1; /* CPU rewrite enable */
fmr11 = 0;
asm(" "); /* Description for preventing the abbreviation by
optimization */
fmr11 = 1; /* EW1 mode */

*write_addr = 0x40;
*write_addr = *write_data;

while( fmr00 != 1 ); /* Ready check */


/* Program status check */
if( fmr06 == 1 ){
/* Program error */
*write_addr = 0x50; /* Clear stutus register */
program_result = PROGRAM_ERR;
}
/* flash control register reset */
fmr01 = 0; /* CPU rewrite disable */

/* If use interrupt then set i flag... */


/* asm("fset i "); */

return program_result;
}
void write_parameter(void)
{
unsigned char ii;
// To save divide_factor value
asm("FCLR I"); //Disable all the Interrupts
// divide_factor1= Offset_value1;

for(ii=0;ii<=(data_size-1);ii++)
{
ptr_counter=&write_array[ii];
result = flash_write(ptr_counter);
}
asm("FSET I"); //Enable all the Interrupts
asm("FSET I"); //Enable all the Interrupts

void dataflash_data_collect(void)
{
unsigned char loop =0;

//for(loop=0;loop<10;loop++)
{
write_array[0]=int_hour;
write_array[1]=int_min;//te;
write_array[2]=int_del_hour;//
write_array[3]=int_del_min;//
write_array[4]=long_degree;
write_array[5]=long_min;
write_array[6]=lat_deg;//on_time;
write_array[7]=lat_min;//;
write_array[8]=volt_upper_1;//
write_array[9]=volt_upper_2;//write;
write_array[10]=volt_lower_1;
write_array[11]=volt_lower_2;
write_array[12]=flux_upper;
write_array[13]=flux_lower;
write_array[14]=current_fix_1;//to change
write_array[15]=array_hour[1];
write_array[16]=array_hour[2];;
write_array[17]=array_hour[3];;
write_array[18]=array_hour[4];;
write_array[19]=array_hour[5];;
write_array[20]=array_hour[6];;
write_array[21]=array_hour[7];;
write_array[22]=array_hour[8];;
write_array[23]=array_hour[9];;
write_array[24]=array_hour[10];;
write_array[25]=array_hour[11];;
write_array[26]=array_hour[12];;
write_array[27]=array_hour[13];;
write_array[28]=array_hour[14];;
write_array[29]=array_hour[15];;
write_array[30]=array_hour[16];;
write_array[31]=array_hour[17];;
write_array[32]=array_hour[18];;
write_array[33]=array_hour[19];;
write_array[34]=array_hour[20];;
write_array[35]=array_hour[21];;
write_array[36]=array_hour[22];;
write_array[37]=array_hour[23];;
write_array[38]=array_hour[24];;
write_array[39]=array_min[1];;
write_array[40]=array_min[2];;
write_array[41]=array_min[3];;
write_array[42]=array_min[4];;
write_array[43]=array_min[5];//[1];;
write_array[44]=array_min[6];
write_array[45]=array_min[7];;
write_array[46]=array_min[8];;
write_array[47]=array_min[9];;
write_array[48]=array_min[10];;
write_array[49]=array_min[11];;
write_array[50]=array_min[12];;
write_array[51]=array_min[13];;
write_array[52]=array_min[14];;
write_array[53]=array_min[15];;
write_array[54]=array_min[16];;
write_array[55]=array_min[17];;
write_array[56]=array_min[18];;
write_array[57]=array_min[19];;
write_array[58]=array_min[20];;
write_array[59]=array_min[21];;
write_array[60]=array_min[22];;
write_array[61]=array_min[23];;
write_array[62]=array_min[24];;
write_array[63]=default_define_select;
write_array[64]=first_time_datawrite;
write_array[65]=volt_c_1;
write_array[66]=volt_c_2;
write_array[67]=current_fix_2;
write_array[68]=int_off_hour;
write_array[69]=int_off_min;
//write_array[12]=volt_lower_1;
//write_array[13]=volt_lower_2;
}
}

void dataflash_data_retrieval(void)
{
unsigned char loop =0;

//0 for(loop=0;loop<10;loop++)
{
int_hour=read_array[0];
int_min=read_array[1];
int_del_hour=read_array[2];
int_del_min=read_array[3];
long_degree=read_array[4];
long_min=read_array[5];
lat_deg=read_array[6];;
lat_min=read_array[7];
volt_upper_1=read_array[8];
volt_upper_2=read_array[9];
volt_lower_1=read_array[10];
volt_lower_2=read_array[11];
flux_upper=read_array[12];
flux_lower=read_array[13];
current_fix_1=read_array[14];
array_hour[1]=read_array[15];
array_hour[2]=read_array[16];
array_hour[3]=read_array[17];
array_hour[4]=read_array[18];
array_hour[5]=read_array[19];
array_hour[6]=read_array[20];;
array_hour[7]=read_array[21];
array_hour[8]=read_array[22];
array_hour[9]=read_array[23];
array_hour[10]=read_array[24];
array_hour[11]=read_array[25];
array_hour[12]=read_array[26];
array_hour[13]=read_array[27];
array_hour[14]=read_array[28];
array_hour[15]=read_array[29];
array_hour[16]=read_array[30];
array_hour[17]=read_array[31];
array_hour[18]=read_array[32];
array_hour[19]=read_array[33];
array_hour[20]=read_array[34];;
array_hour[21]=read_array[35];
array_hour[22]=read_array[36];
array_hour[23]=read_array[37];
array_hour[24]=read_array[38];
array_min[1]=read_array[39];
array_min[2]=read_array[40];
array_min[3]=read_array[41];
array_min[4]=read_array[42];
array_min[5]=read_array[43];
array_min[6]=read_array[44];
array_min[7]=read_array[45];
array_min[8]=read_array[46];
array_min[9]=read_array[47];
array_min[10]=read_array[48];;
array_min[11]=read_array[49];
array_min[12]=read_array[50];
array_min[13]=read_array[51];
array_min[14]=read_array[52];
array_min[15]=read_array[53];
array_min[16]=read_array[54];
array_min[17]=read_array[55];
array_min[18]=read_array[56];
array_min[19]=read_array[57];
array_min[20]=read_array[58];
array_min[21]=read_array[59];
array_min[22]=read_array[60];
array_min[23]=read_array[61];
array_min[24]=read_array[62];;
default_define_select=read_array[63];
first_time_datawrite=read_array[64];
volt_c_1=read_array[65];
volt_c_2=read_array[66];
current_fix_2=read_array[67];
int_off_hour=read_array[68];
int_off_min=read_array[69];
volt_upper=(0xff & volt_upper_2);
volt_upper=((volt_upper<<8) | volt_upper_1);
volt_lower=(0xff & volt_lower_2);
volt_lower=((volt_lower<<8) | volt_lower_1);
volt_c=(0xff & volt_c_2);
volt_c=((volt_c<<8) | volt_c_1);
current_fix=(0xff & current_fix_2);
current_fix=((current_fix<<8) | current_fix_1);
}
}

void dataflash_write(void)
{
write_parameter();
}

void display_hou(unsigned char data3 )


{
unsigned char unit,ten,hundred;
unit=(data3%10);
data3=(data3-unit)/10;
ten=data3;
//if(cyclic_counter==1)
{
if(ten==0)
write_lcd_ram(2,(array_digit[0]));
else if (ten==1)
write_lcd_ram(2,(array_digit[1]));
else if (ten==2)
write_lcd_ram(2,(array_digit[2]));
else if (ten==3)
write_lcd_ram(2,(array_digit[3]));
else if (ten==4)
write_lcd_ram(2,(array_digit[4]));
else if (ten==5)
write_lcd_ram(2,(array_digit[5]));
else if (ten==6)
write_lcd_ram(2,(array_digit[6]));
else if (ten==7)
write_lcd_ram(2,(array_digit[7]));
else if (ten==8)
write_lcd_ram(2,(array_digit[8]));
else if (ten==9)
write_lcd_ram(2,(array_digit[9]));

}
/*else
{

if(ten==0)
write_lcd_ram(0,(array_digit[0]));
else if (ten==1)
write_lcd_ram(0,(array_digit[1]));
else if (ten==2)
write_lcd_ram(0,(array_digit[2]));
else if (ten==3)
write_lcd_ram(0,(array_digit[3]));
else if (ten==4)
write_lcd_ram(0,(array_digit[4]));
else if (ten==5)
write_lcd_ram(0,(array_digit[5]));
else if (ten==6)
write_lcd_ram(0,(array_digit[6]));
else if (ten==7)
write_lcd_ram(0,(array_digit[7]));
else if (ten==8)
write_lcd_ram(0,(array_digit[8]));
else if (ten==9)
write_lcd_ram(0,(array_digit[9]));
}
*/

//if(cyclic_counter==2)
{
if(unit==0)
write_lcd_ram(3,(array_digit[0]|THREE_P));
else if (unit==1)
write_lcd_ram(3,(array_digit[1]|THREE_P));
else if (unit==2)
write_lcd_ram(3,(array_digit[2]|THREE_P));
else if (unit==3)
write_lcd_ram(3,(array_digit[3]|THREE_P));
else if (unit==4)
write_lcd_ram(3,(array_digit[4]|THREE_P));
else if (unit==5)
write_lcd_ram(3,(array_digit[5]|THREE_P));
else if (unit==6)
write_lcd_ram(3,(array_digit[6]|THREE_P));
else if (unit==7)
write_lcd_ram(3,(array_digit[7]|THREE_P));
else if (unit==8)
write_lcd_ram(3,(array_digit[8]|THREE_P));
else if (unit==9)
write_lcd_ram(3,(array_digit[9]|THREE_P));
}
/*
else
{
if(unit==0)
write_lcd_ram(1,array_digit[0]);
else if (unit==1)
write_lcd_ram(1,array_digit[1]);
else if (unit==2)
write_lcd_ram(1,array_digit[2]);
else if (unit==3)
write_lcd_ram(1,array_digit[3]);
else if (unit==4)
write_lcd_ram(1,array_digit[4]);
else if (unit==5)
write_lcd_ram(1,array_digit[5]);
else if (unit==6)
write_lcd_ram(1,array_digit[6]);
else if (unit==7)
write_lcd_ram(1,array_digit[7]);
else if (unit==8)
write_lcd_ram(1,array_digit[8]);
else if (unit==9)
write_lcd_ram(1,array_digit[9]);
}
*/
}

void display_minute(unsigned char data3)


{
unsigned char unit,ten,hundred;
unit=(data3%10);
data3=(data3-unit)/10;
ten=data3%10;

if(cyclic_counter==4)
{
write_lcd_ram(9,NULL);
if(ten==0)//unit
write_lcd_ram(4,array_digit[0]|ON);
else if (ten==1)
write_lcd_ram(4,array_digit[1]|ON);
else if (ten==2)
write_lcd_ram(4,array_digit[2]|ON);
else if (ten==3)
write_lcd_ram(4,array_digit[3]|ON);
else if (ten==4)
write_lcd_ram(4,array_digit[4]|ON);
else if (ten==5)
write_lcd_ram(4,array_digit[5]|ON);
else if (ten==6)
write_lcd_ram(4,array_digit[6]|ON);
else if (ten==7)
write_lcd_ram(4,array_digit[7]|ON);
else if (ten==8)
write_lcd_ram(4,array_digit[8]|ON);
else if (ten==9)
write_lcd_ram(4,array_digit[9]|ON);
}
else
{
if(ten==0)
write_lcd_ram(4,(array_digit[0]));
else if (ten==1)
write_lcd_ram(4,(array_digit[1]));
else if (ten==2)
write_lcd_ram(4,(array_digit[2]));
else if (ten==3)
write_lcd_ram(4,(array_digit[3]));
else if (ten==4)
write_lcd_ram(4,(array_digit[4]));
else if (ten==5)
write_lcd_ram(4,(array_digit[5]));
else if (ten==6)
write_lcd_ram(4,(array_digit[6]));
else if (ten==7)
write_lcd_ram(4,(array_digit[7]));
else if (ten==8)
write_lcd_ram(4,(array_digit[8]));
else if (ten==9)
write_lcd_ram(4,(array_digit[9]));
}

if(cyclic_counter==2)
{
if(unit==0)
write_lcd_ram(5,array_digit[0]|TIME);
else if (unit==1)
write_lcd_ram(5,array_digit[1]|TIME);
else if (unit==2)
write_lcd_ram(5,array_digit[2]|TIME);
else if (unit==3)
write_lcd_ram(5,array_digit[3]|TIME);
else if (unit==4)
write_lcd_ram(5,array_digit[4]|TIME);
else if (unit==5)
write_lcd_ram(5,array_digit[5]|TIME);
else if (unit==6)
write_lcd_ram(5,array_digit[6]|TIME);
else if (unit==7)
write_lcd_ram(5,array_digit[7]|TIME);
else if (unit==8)
write_lcd_ram(5,array_digit[8]|TIME);
else if (unit==9)
write_lcd_ram(5,array_digit[9]|TIME);
}
else if(cyclic_counter==3)
{
write_lcd_ram(9,OFF);
if(unit==0)
write_lcd_ram(5,array_digit[0]|TIME);
else if (unit==1)
write_lcd_ram(5,array_digit[1]|TIME);
else if (unit==2)
write_lcd_ram(5,array_digit[2]|TIME);
else if (unit==3)
write_lcd_ram(5,array_digit[3]|TIME);
else if (unit==4)
write_lcd_ram(5,array_digit[4]|TIME);
else if (unit==5)
write_lcd_ram(5,array_digit[5]|TIME);
else if (unit==6)
write_lcd_ram(5,array_digit[6]|TIME);
else if (unit==7)
write_lcd_ram(5,array_digit[7]|TIME);
else if (unit==8)
write_lcd_ram(5,array_digit[8]|TIME);
else if (unit==9)
write_lcd_ram(5,array_digit[9]|TIME);
}
else if(cyclic_counter==4)
{
write_lcd_ram(9,NULL);
if(unit==0)
write_lcd_ram(5,array_digit[0]|TIME);
else if (unit==1)
write_lcd_ram(5,array_digit[1]|TIME);
else if (unit==2)
write_lcd_ram(5,array_digit[2]|TIME);
else if (unit==3)
write_lcd_ram(5,array_digit[3]|TIME);
else if (unit==4)
write_lcd_ram(5,array_digit[4]|TIME);
else if (unit==5)
write_lcd_ram(5,array_digit[5]|TIME);
else if (unit==6)
write_lcd_ram(5,array_digit[6]|TIME);
else if (unit==7)
write_lcd_ram(5,array_digit[7]|TIME);
else if (unit==8)
write_lcd_ram(5,array_digit[8]|TIME);
else if (unit==9)
write_lcd_ram(5,array_digit[9]|TIME);
}
else
{
if(unit==0)
write_lcd_ram(5,array_digit[0]);
else if (unit==1)
write_lcd_ram(5,array_digit[1]);
else if (unit==2)
write_lcd_ram(5,array_digit[2]);
else if (unit==3)
write_lcd_ram(5,array_digit[3]);
else if (unit==4)
write_lcd_ram(5,array_digit[4]);
else if (unit==5)
write_lcd_ram(5,array_digit[5]);
else if (unit==6)
write_lcd_ram(5,array_digit[6]);
else if (unit==7)
write_lcd_ram(5,array_digit[7]);
else if (unit==8)
write_lcd_ram(5,array_digit[8]);
else if (unit==9)
write_lcd_ram(5,array_digit[9]);
}

}
void display_second(unsigned char data3)
{

unsigned char unit,ten,hundred;


unit=(data3%10);
data3=(data3-unit)/10;
ten=data3;

if(ten==0)
write_lcd_ram(6,(array_digit[0]));
else if (ten==1)
write_lcd_ram(6,(array_digit[1]));
else if (ten==2)
write_lcd_ram(6,(array_digit[2]));
else if (ten==3)
write_lcd_ram(6,(array_digit[3]));
else if (ten==4)
write_lcd_ram(6,(array_digit[4]));
else if (ten==5)
write_lcd_ram(6,(array_digit[5]));
else if (ten==6)
write_lcd_ram(6,(array_digit[6]));
else if (ten==7)
write_lcd_ram(6,(array_digit[7]));
else if (ten==8)
write_lcd_ram(6,(array_digit[8]));
else if (ten==9)
write_lcd_ram(6,(array_digit[9]));

if(unit==0)
write_lcd_ram(7,array_digit[0]);
else if (unit==1)
write_lcd_ram(7,array_digit[1]);
else if (unit==2)
write_lcd_ram(7,array_digit[2]);
else if (unit==3)
write_lcd_ram(7,array_digit[3]);
else if (unit==4)
write_lcd_ram(7,array_digit[4]);
else if (unit==5)
write_lcd_ram(7,array_digit[5]);
else if (unit==6)
write_lcd_ram(7,array_digit[6]);
else if (unit==7)
write_lcd_ram(7,array_digit[7]);
else if (unit==8)
write_lcd_ram(7,array_digit[8]);
else if (unit==9)
write_lcd_ram(7,array_digit[9]);
}

void display_Press_OK(void)
{

void display_overload(void)
{

void display_data_set(void)
{

void display_current(void)
{

void display_upper_volt(void)
{

void display_lower_volt(void)
{

void password_input_function(void)
{
//display text pasword
write_lcd_ram(0,SYNER);
password_data=1;
display_value_id(PASSWORD);
general_delay=0;
while(general_delay<1000);
get_out_counter=1;get_out_count=0;shift_counter=0;
while(password_data==1)
{
if(INC_input==1 &&
INC_flag==0)
{
get_out_count=0;
INC_input=0;

if(shift_counter==0)
{
data0++;
if(data0>8)
data0=9 ;

write_lcd_ram(2,array_digit[data0 & 0xff]);

write_lcd_ram(3,array_digit[data1 & 0xff]);

write_lcd_ram(4,array_digit[data2 & 0xff]);

write_lcd_ram(5,array_digit[data3 & 0xff]);

}
else if(shift_counter==1)
{
data1++;
if(data1>8)
data1=9 ;

write_lcd_ram(2,array_digit[data0 & 0xff]);

write_lcd_ram(3,array_digit[data1 & 0xff]);

write_lcd_ram(4,array_digit[data2 & 0xff]);

write_lcd_ram(5,array_digit[data3 & 0xff]);

}
else if(shift_counter==2)
{
data2++;
if(data2>8)
data2=9 ;

write_lcd_ram(2,array_digit[data0 & 0xff]);

write_lcd_ram(3,array_digit[data1 & 0xff]);

write_lcd_ram(4,array_digit[data2 & 0xff]);

write_lcd_ram(5,array_digit[data3 & 0xff]);

}
else if(shift_counter==3)
{
data3++;
if(data3>8)
data3=9 ;

write_lcd_ram(2,array_digit[data0 & 0xff]);

write_lcd_ram(3,array_digit[data1 & 0xff]);

write_lcd_ram(4,array_digit[data2 & 0xff]);

write_lcd_ram(5,array_digit[data3 & 0xff]);


}
//display_value_id(PASSWORD);
}
if(DEC_input==1 && DEC_flag==0 )
{
get_out_count=0;
DEC_input=0;
if(shift_counter==0)
{
data0--;
if(data0<2)
data0=1;

write_lcd_ram(2,array_digit[data0 & 0xff]);

write_lcd_ram(3,array_digit[data1 & 0xff]);

write_lcd_ram(4,array_digit[data2 & 0xff]);

write_lcd_ram(5,array_digit[data3 & 0xff]);

}
else if(shift_counter==1)
{
data1--;
if(data1<2)
data1=1 ;

write_lcd_ram(2,array_digit[data0 & 0xff]);

write_lcd_ram(3,array_digit[data1 & 0xff]);

write_lcd_ram(4,array_digit[data2 & 0xff]);

write_lcd_ram(5,array_digit[data3 & 0xff]);

}
else if(shift_counter==2)
{
data2--;
if(data2<2)
data2=1;

write_lcd_ram(2,array_digit[data0 & 0xff]);

write_lcd_ram(3,array_digit[data1 & 0xff]);

write_lcd_ram(4,array_digit[data2 & 0xff]);

write_lcd_ram(5,array_digit[data3 & 0xff]);

}
else if(shift_counter==3)
{
data3--;
if(data3<2)
data3=1;

write_lcd_ram(2,array_digit[data0 & 0xff]);

write_lcd_ram(3,array_digit[data1 & 0xff]);

write_lcd_ram(4,array_digit[data2 & 0xff]);


write_lcd_ram(5,array_digit[data3 & 0xff]);
}

}
if(OK_input==1 && OK_flag==0)
{
OK_input=0;shift_counter+
+;one_det=1;
get_out_count=0;

write_lcd_ram(2,array_digit[data0 & 0xff]);

write_lcd_ram(3,array_digit[data1 & 0xff]);

write_lcd_ram(4,array_digit[data2 & 0xff]);

write_lcd_ram(5,array_digit[data3 & 0xff]);


if(data0==1 && data1==2 &&
data2==3 && data3==4 && shift_counter==4)
{
maintenance=0;
display_OK();//for two
second
general_delay=0;

while(general_delay<1000);
write_lcd_ram(0,SYNER);
Display_Prog_set();
general_delay=0;
prog_set_flag=0;
while(prog_set_flag==0)
{

if(OK_input==1 &&
OK_flag==0)
{
OK_input=0;

display_default_define();

prog_set_flag=1;

rtc_initialize=1;
}
}
password_data=0;
RESET_input=0;

get_out_counter=0;get_out_count=0;
}///for lab maintenance
else if(data0==6 && data1==4
&& data2==2 && data3==8 && shift_counter==4)
{
maintenance=1;
display_OK();//for two
second
general_delay=0;
while(general_delay<1000);
Display_Prog_set();
general_delay=0;
prog_set_flag=0;
while(prog_set_flag==0)
{
if(OK_input==1 &&
OK_flag==0)
{
OK_input=0;

display_default_define();

prog_set_flag=1;

rtc_initialize=1;
}
}
password_data=0;
RESET_input=0;

get_out_counter=0;get_out_count=0;
}
else if(data0==7 && data1==7
&& data2==7 && data3==7 && shift_counter==4)// FOR REMOVING ELECTRICAL
{
AB_LED=0;
NO_LED=0;

if(first_time_datawrite==0x00)
{

first_time_datawrite=0xaa; //ELECTRICAL_PROTECTION=OFF GREEN LED ON FOR


TEN SECOND RED LED IS OFF

dataflash_data_collect();

dataflash_write();
asm("nop");
loop_led=0;

while(loop_led<5)
{
AB_LED=0;
NO_LED=1;

indication_counter=0;

while(indication_counter<1000);
AB_LED=0;
NO_LED=0;
loop_led++;
}
}
else
{

first_time_datawrite=0x00; //ELECTRICAL_PROTECTION=ON RED LED ON FOR TEN SECOND


GREEN LED IS OFF

dataflash_data_collect();

dataflash_write();
asm("nop");
loop_led=0;

while(loop_led<5)
{
AB_LED=1;
NO_LED=0;

indication_counter=0;

while(indication_counter<1000);
AB_LED=0;
NO_LED=0;
loop_led++;
}
}

get_out_counter=0;get_out_count=0; password_data=0;

/*if(ELECTRICAL_PROTECTI
ON == ON)//read_array[64];//electrical protection on 0x00 //electrical
protection off 0xaa
{

ELECTRICAL_PROTECTION=OFF
GREEN LED ON FOR TEN
SECOND
RED LED IS OFF
}
ELSE
{

ELECTRICAL_PROTECTION=ON
RED LED ON FOR TEN
SECOND
GREEN LED IS OFF
}*/
}
else
{

get_out_counter=1;get_out_count=0;// start timer for 5 secto geet out of


this condition
}
}
if(RESET_input==1 && RESET_flag==0)
{
get_out_count=0;
one_det=1;
RESET_input=0;
password_data=1;
display_value_id(0000);
password_input=0;
shift_counter=0;

data0=0;data1=0;data2=0;data3=0;
//first_time_datawrite=0x00;
}

if(get_out_count>7000)
{

password_data=0;get_out_count=0;get_out_counter=0;
rtc_initialize=0;
}
}

void disp_date(void)
{
write_lcd_ram(1,array_digit[1]|0x10);///serial_no_display(1);and date

display_hou(date_dec);
display_minute(month_dec);
display_second(year_dec);
}

void disp_time(void)
{
write_lcd_ram(1,array_digit[2]);///serial_no_display(2);
display_hou(hour_dec);//ob.hour_ob2.hour_bcd);
display_minute(min_dec);//ob.min_ob2.min_bcd);
display_second(second_dec);//ob.sec_ob2.sec_bcd)
}

void disp_off_time(void)
{
write_lcd_ram(1,array_digit[3]);////serial_no_display(3);
if(default_define_select==0x00)
{
display_hou(sunrise_hour);
display_minute(sunrise_min);
}
else
{
display_hou(array_hour[2*(month_dec)]);// on time is on the odd
locstion
display_minute(array_min[2*(month_dec)]);
}
write_lcd_ram(6,0x00);
write_lcd_ram(7,0x00);

}
void disp_on_time(void)
{
write_lcd_ram(1,array_digit[4]);////serial_no_display(4);
if(default_define_select==0x00)
{
display_hou(sunset_hour);
display_minute(sunset_min);
}
else
{
display_hou(array_hour[1+2*(month_dec-1)]);// ooff time is on the odd
locstion
display_minute(array_min[1+2*(month_dec-1)]);
}

write_lcd_ram(6,0x00);
write_lcd_ram(7,0x00);
}

void display_overvolt(void)
{

}
void display_lowvolt(void)
{

void display_load_volt(void)
{
}

void input_function(void)
{
initial_flag=1;
initial_counter=0;
general_delay=0;

while(initial_flag==1)
{
if(INC_input==1 && INC_flag==0)
{
INC_input=0;
password_input_function();
//first_time_datawrite=0xaa;// save in dataflash
// rtc_initialize=1;
initial_flag=0;
}

if(DEC_input==1 && DEC_flag==0)


{
DEC_input=0;
password_input_function();
//dataflash_data_collect();
//dataflash_write();
//first_time_datawrite=0xaa;// save in
dataflash
//rtc_initialize=1;
initial_flag=0;
}
if(OK_input==1 && OK_flag==0)
{

OK_input=0;
password_input_function();
//dataflash_data_collect();
//dataflash_write();
//first_time_datawrite=0xaa;// save in dataflash
initial_flag=0;
// rtc_initialize=1;
}
if(RESET_input==1 && RESET_flag==0)
{
RESET_input=0;
password_input_function();
//first_time_datawrite=0xaa;// save in dataflash
//dataflash_data_collect();
//dataflash_write();
// rtc_initialize=1;
initial_flag=0;
}
if(rtc_initialize==1)
{

dataflash_data_collect();
dataflash_write();
asm("nop");
vTime_Init();
rtc_initialize=0;
AB_LED=1;
NO_LED=1;
indication_counter=0;
while(indication_counter<2000);
AB_LED=0;
NO_LED=0;
watch_dog=1;
wdts = 0xff;
}

if(general_delay>200)// 5sec
{
initial_flag=0;
rtc_initialize=0;
watch_dog=1;
wdts = 0xff;
}
}
sun_set_rise();

unsigned char myBcd2Dec(unsigned char bcd){


return ((bcd >> 4)*10+(bcd & 0x0F));
}

unsigned char myDec2Bcd(unsigned char dec){


return (((dec/10)<<4)+(dec%10));
}

void wdt_init(void)
{
/* switch BCLK to f8 so we have a longer timeout period */

/* unprotect Clock mode register0 so we can modify clock */


prcr = 3;

/* Watchdog function after it times out:0 -(default) generate interrupt, 1 -


resets the MCU */
pm12 = 1;
/* 0 (default) - jumps to the watchdog interrupt routine */
/* 1 - resets the MCU */

/* protect PM1 */
prcr = 0;

/* prescaler is div by 128 watchdog timer period = (32,768 x 128) / (2.5MHz) =


1.677s */
// wdc7 = 1;

/* Start Watchdog Timer by writing any value to wdts register (value


always resets to 0x7fff when written to) */
wdtr = 0x00;
wdtr = 0xFF;
// wdts = 0xff;
}

void serial_no_display(unsigned char num)


{

void set_default_value(void)
{

if(volt_upper_2<=1 || volt_lower_2<=1 || current_fix_1<1)


{
int_hour=read_array[0];
int_min=read_array[1];
int_del_hour=read_array[2];
int_del_min=read_array[3];
long_degree=76;//read_array[4];
long_min=95;//read_array[5];
lat_deg=8;//read_array[6];;
lat_min=48;//read_array[7];
volt_upper_1=204;//read_array[8];
volt_upper_2=6;//read_array[9];
volt_lower_1=232;//read_array[10];
volt_lower_2=3;//read_array[11];
flux_upper=52;//read_array[12];
flux_lower=38;//read_array[13];
current_fix_1=20;//read_array[14];
array_hour[1]=read_array[15];
array_hour[2]=read_array[16];
array_hour[3]=read_array[17];
array_hour[4]=read_array[18];
array_hour[5]=read_array[19];
array_hour[6]=read_array[20];;
array_hour[7]=read_array[21];
array_hour[8]=read_array[22];
array_hour[9]=read_array[23];
array_hour[10]=read_array[24];
array_hour[11]=read_array[25];
array_hour[12]=read_array[26];
array_hour[13]=read_array[27];
array_hour[14]=read_array[28];
array_hour[15]=read_array[29];
array_hour[16]=read_array[30];
array_hour[17]=read_array[31];
array_hour[18]=read_array[32];
array_hour[19]=read_array[33];
array_hour[20]=read_array[34];;
array_hour[21]=read_array[35];
array_hour[22]=read_array[36];
array_hour[23]=read_array[37];
array_hour[24]=read_array[38];
array_min[1]=read_array[39];
array_min[2]=read_array[40];
array_min[3]=read_array[41];
array_min[4]=read_array[42];
array_min[5]=read_array[43];
array_min[6]=read_array[44];
array_min[7]=read_array[45];
array_min[8]=read_array[46];
array_min[9]=read_array[47];
array_min[10]=read_array[48];;
array_min[11]=read_array[49];
array_min[12]=read_array[50];
array_min[13]=read_array[51];
array_min[14]=read_array[52];
array_min[15]=read_array[53];
array_min[16]=read_array[54];
array_min[17]=read_array[55];
array_min[18]=read_array[56];
array_min[19]=read_array[57];
array_min[20]=read_array[58];
array_min[21]=read_array[59];
array_min[22]=read_array[60];
array_min[23]=read_array[61];
array_min[24]=read_array[62];;
default_define_select=read_array[63];
first_time_datawrite=0x00;//read_array[64];//electrical
protection on 0x00 //electrical protection off 0xaa
volt_c_1=read_array[65];
volt_c_2=read_array[66];
current_fix_2=1;//read_array[67];
int_off_hour=read_array[68];
int_off_min=read_array[69];
volt_upper=(0xff & volt_upper_2);
volt_upper=((volt_upper<<8) | volt_upper_1);
volt_lower=(0xff & volt_lower_2);
volt_lower=((volt_lower<<8) | volt_lower_1);
volt_c=(0xff & volt_c_2);
volt_c=((volt_c<<8) | volt_c_1);
current_fix=(0xff & current_fix_2);
current_fix=((current_fix<<8) | current_fix_1);
volt_upper=1566;
volt_lower=984;
flux_upper=129;
flux_lower=99;
}
}

///astronomical//
void SUNSET_TIME(double solar_noon,double ha_sunrise)//Z sunset
{
K_SUNSET_TIME=(solar_noon*1440+ha_sunrise*4)/1440;
}

void SUNRISE_TIME(double solar_noon,double ha_sunrise)//Y sunrise


{
K_SUNRISE_TIME=(solar_noon*1440-ha_sunrise*4)/1440;
}
//Solar Noon (LST) X2 (720-4*$B$3-V2+$B$4*60)/1440
void SOLAR_NOON(double longtitude,double time_zone,double eqn_of_time)//X2
{
K_SOLAR_NOON=(720-4*longtitude-eqn_of_time+time_zone*60)/1440;
}
//HA Sunrise (deg) W2 DEGREES(ACOS(COS(RADIANS(90.833))/
(COS(RADIANS($B$2))*COS(RADIANS(T2)))-TAN(RADIANS($B$2))*TAN(RADIANS(T2))))
void HA_SUNRISE(double sun_decline,double lattitude)//w2 lattitude in deg
{
//K_HA_SUNRISE=DEGREES(acos(cos(0.0175*(90.833))/
(cos(0.0175*(lattitude))*cos(0.0175*(sun_decline)))-
tan(0.0175*(lattitude))*tan(0.0175*(sun_decline))));
double
temp_o,temp_two,temp_three,temp_fou,temp_five,temp_six,temp_seven,temp_eight;
temp_o=(0.0175*(90.833));
temp_two=(0.0175*(lattitude));
temp_three=(0.0175*(sun_decline));
temp_fou=0.0175*(lattitude);
temp_five=0.0175*(sun_decline);
temp_six=(cos(temp_two)*cos(temp_three));
temp_seven=tan(temp_fou)*tan(temp_five);
temp_eight=(cos(temp_o)/temp_six-temp_seven);
K_HA_SUNRISE=(acos(temp_eight));
K_HA_SUNRISE=K_HA_SUNRISE/0.0175;
}

//Eq of Time (minutes) V2 4*DEGREES(U2*SIN(2*RADIANS(I2))-2*K2*SIN(RADIANS(J2))


+4*K2*U2*SIN(RADIANS(J2))*COS(2*RADIANS(I2))-0.5*U2*U2*SIN(4*RADIANS(I2))-
1.25*K2*K2*SIN(2*RADIANS(J2)))
void EQN_OF_TIME(double vary_y,double geo_mean_long_sun,double
geo_mean_anom_sun,double eccent_earth_orbit)//u2,i2,j2,k2
{
double
temp_o,temp_two,temp_three,temp_fo,temp_five,temp_six,temp_seven,temp_eight,temp_ni
ne,temp_ten,temp_eleven;
//K_EQN_OF_TIME=4*DEGREES(vary_y*sin(2*0.0175*(geo_mean_long_sun))-
2*eccent_earth_orbit*sin(0.0175*(geo_mean_anom_sun))
+4*eccent_earth_orbit*vary_y*sin(0.0175(geo_mean_anom_sun))*cos(2*0.0175(geo_mean_l
ong_sun))-0.5*vary_y*vary_y*sin(4*0.0175(geo_mean_long_sun))-
1.25*eccent_earth_orbit*eccent_earth_orbit*sin(2*0.0175(geo_mean_anom_sun)));
temp_o=2*0.0175*(geo_mean_long_sun);
temp_two=vary_y*sin(temp_o);
temp_three=0.0175*(geo_mean_anom_sun);
temp_fo=2*eccent_earth_orbit*sin(temp_three);
temp_five=0.0175*(geo_mean_anom_sun);
temp_six=2*0.0175*(geo_mean_long_sun);
temp_seven=eccent_earth_orbit*vary_y*sin(temp_five)*cos(temp_six);
temp_eight=4*0.0175*(geo_mean_long_sun);
temp_nine=vary_y*vary_y*sin(temp_eight);
temp_ten=2*0.0175*(geo_mean_anom_sun);
temp_eleven=eccent_earth_orbit*eccent_earth_orbit*sin(temp_ten);
K_EQN_OF_TIME=(temp_two)-temp_fo+(4*temp_seven)-(0.5*temp_nine)-
(1.25*temp_eleven);
K_EQN_OF_TIME=4*(K_EQN_OF_TIME/0.0175);
}

void SUN_DECLINE(double obliq_corr,double sun_app_long)//Sun Declin (deg) T2


{
//K_SUN_DECLINE=DEGREES(asin(sin(0.0175*(obliq_corr))*sin(0.0175*(sun_app_lon
g))));
double temp_o,temp_two,temp_three;
temp_o=0.0175*(obliq_corr);
temp_two=0.0175*(sun_app_long);
temp_three=sin(temp_o)*sin(temp_two);
K_SUN_DECLINE=(asin(temp_three));
K_SUN_DECLINE=K_SUN_DECLINE/0.0175; //FOR DEGREE CONVERSION
}

//var y U2 TAN(RADIANS(R2/2))*TAN(RADIANS(R2/2))
void VAR_Y(double obliq_corr)//U2
{
K_VAR_Y=tan(0.0175*(obliq_corr/2))*tan(0.0175*(obliq_corr/2));
}

//Eccent Earth Orbit K2 0.016708634-G2*(0.000042037+0.0000001267*G2)


void ECCENT_EARTH_ORBIT(double jul_cent)//Eccent Earth Orbit K2 0.016708634-
G2*(0.000042037+0.0000001267*G2)
{
K_ECCENT_EARTH_ORBIT=0.016708634-jul_cent*(0.000042037+0.0000001267*jul_cent);
}

//Obliq Corr (deg) R2 Q2+0.00256*COS(RADIANS(125.04-1934.136*G2))


void OBLIQ_CORR(double mean_obliq_ecliptic,double jul_cent)//R2 OBLIQ_CORR
{
K_OBLIQ_CORR=mean_obliq_ecliptic+0.00256*cos(0.0175*(125.04-
1934.136*jul_cent));
}

//Sun App Long (deg)P2 M2-0.00569-0.00478*SIN(RADIANS(125.04-1934.136*G2))


void SUN_APP_LONG(double sun_true_long,double jul_cent)// SUN_APP_LONG P2
{
K_SUN_APP_LONG=sun_true_long-0.00569-0.00478*sin(0.0175*(125.04-
1934.136*jul_cent));
}

void SUN_TRUE_LONG(double geo_mean_long_sun,double sun_eqn_ctr)//M2=I2+L2


{
K_SUN_TRUE_LONG=geo_mean_long_sun+sun_eqn_ctr;
}

void GEO_MEAN_LONG_SUN(double jul_cent)//GEO_MEAN_LONG_SUN I2


{
double number;
number=280.46646+jul_cent*(36000.76983 + jul_cent*0.0003032);
K_GEO_MEAN_LONG_SUN=((unsigned int)number)%360;
//K_GEO_MEAN_LONG_SUN=number%360;
//K_GEO_MEAN_LONG_SUN=MOD(280.46646+jul_cent*(36000.76983 +
jul_cent*0.0003032),360);
}

void SUN_EQN_CTR(double k_Geo_mean_snomaly_sun,double jul_cent)//L2SUN_EQN_of CTR


{
double
temp_o,temp_two,temp_three,temp_fou,temp_five,temp_six,temp_seven,temp_eight,temp_n
ine,temp_ten,temp_ele,temp_twe;
/*temp_o=(k_Geo_mean_snomaly_sun*0.0175);
temp_two=jul_cent*(0.004817+0.000014*jul_cent);
temp_three=(2*k_Geo_mean_snomaly_sun*.0175);
temp_fou=0.000101*jul_cent;
temp_five=0.0175*(3*k_Geo_mean_snomaly_sun);
temp_six=(sin(temp_o)*(1.914602-temp_two));
temp_seven=(sin(temp_three)*(0.019993-temp_fou));
temp_eight=(sin(temp_five)*0.000289);
K_SUN_EQN_CTR=temp_six+temp_seven+temp_eight;*/
temp_o=(k_Geo_mean_snomaly_sun*0.0175);
temp_two=0.000014*jul_cent;
temp_three=(0.004817+temp_two);
temp_fou=jul_cent*temp_three;
temp_five=(2*k_Geo_mean_snomaly_sun*0.0175);
temp_six=0.000101*jul_cent;
temp_seven=0.019993-temp_six;
temp_eight=sin(temp_five)*(temp_seven);
temp_nine=(1.914602-temp_fou);
temp_ten=sin(temp_o)*temp_nine;
temp_ele=(3*k_Geo_mean_snomaly_sun*0.0175);
temp_twe=sin(temp_ele)*0.000289;
K_SUN_EQN_CTR=temp_ten+temp_eight+temp_twe;
}

void GEO_MEAN_ANOM_SUN(double jul_cent)//J2 GEO_MEAN_ANOM_SUN


{
K_GEO_MEAN_ANOM_SUN=357.52911+jul_cent*(35999.05029 - 0.0001537*jul_cent);
}
void MEAN_OBLIQ_ECLIPTIC(double jul_cent)//Q2 mean obliq_ecliptic
{
K_M_OBLIQ_ECLIPTIC=23+(26+((21.448-jul_cent*(46.815+jul_cent*(0.00059-
jul_cent*0.001813))))/60)/60;
}

void JULIAN_CENTU(double jul_day)//G2 julian cent


{
K_JUL_CENT=(jul_day-2451545);
K_JUL_CENT=K_JUL_CENT/36525;
}

void JULIAN_DAY(double dat_val)//f2 julian day


{
double temp;
temp=5.5/24;
K_JULI_DAY=K_DV+2415018.5+1.6-temp;
K_JULI_DAY=K_JULI_DAY-1.5308;
}

void date_value(unsigned char date,unsigned char month,unsigned char year)//E


{
if(year==14)
{
K_DV=41639;//40
K_DV=K_DV+30*(month-1)+date;
}
else if(year==15)
{
K_DV=42004;//5
K_DV=K_DV+30*(month-1)+date;
}
else if(year==16)
{
K_DV=42369;//70
K_DV=K_DV+30*(month-1)+date;
}
else if(year==17)
{
K_DV=42735;//36
K_DV=K_DV+30*(month-1)+date;
}
else if(year==18)
{
K_DV=43100;//1
K_DV=K_DV+30*(month-1)+date;
}
else if(year==19)
{
K_DV=43465;//6
K_DV=K_DV+30*(month-1)+date;
}
else if(year==20)
{
K_DV=43830;//1
K_DV=K_DV+30*(month-1)+date;
}
else if(year==21)
{
K_DV=44196;//7
K_DV=K_DV+30*(month-1)+date;
}
else if(year==22)
{
K_DV=44561;//2
K_DV=K_DV+30*(month-1)+date;
}
else if(year==23)
{
K_DV=44926;//7
K_DV=K_DV+30*(month-1)+date;
}
else if(year==24)
{
K_DV=45291;//2
K_DV=K_DV+30*(month-1)+date;
}
else
{
K_DV=45291;//2
K_DV=K_DV+30*(month-1)+date;
}
if(month==1)
{}
else if (month==2)
{K_DV=K_DV+1;}
else if (month==3)
{K_DV=K_DV+1-2;}
else if (month==4)
{K_DV=K_DV+1-2+1;}
else if (month==5)
{K_DV=K_DV;}
else if (month==6)
{K_DV=K_DV+1;}
else if (month==7)
{K_DV=K_DV+1;}
else if (month==8)
{K_DV=K_DV+1+1;}
else if (month==9)
{K_DV=K_DV+1+1+1;}
else if (month==10)
{K_DV=K_DV+1+1+1;}
else if (month==11)
{K_DV=K_DV+1+1+1+1;}
else
{K_DV=K_DV+1+1+1+1;}
}

S-ar putea să vă placă și