Hi all!

i want to save my data in the eeprom of pic16f877a. here is my code. i don't know where i am going wrong. kindly help me.
here is the part of my code for your ease. please ignore declerations. i am writing the full code related to eeprom.
Code:
void main()
{
//............................EEPROM default data...............................
 if ( EEPROM_Read(0x30)== 0);
 {
 EEPROM_Write(0x30, 0x0A );           // Write data to address 0x30 as default
 gen_wt=  EEPROM_Read(0x30);          // generator warm up time = 10sec
 }
 
 if ( EEPROM_Read(0x38)== 0);
 {
 EEPROM_Write(0x38, 0x02 );           // Write data to address 0x38 as default
 self_ont= EEPROM_Read(0x38);         // Self ON time = 2sec
 }
 
 if ( EEPROM_Read(0x40)== 0);
 {
 EEPROM_Write(0x40, 0x05 );           // Write data to address 0x40 as default
 self_oft= EEPROM_Read(0x40);         // Self OFF time = 5sec
 }
 
//..............................................................................

}


while(1)
  {

                    if ((enter==0) && (reset==1) && (up==1) && (down==1))// (Button(&PORTD,0,ms,0))  //when Enter is pressed
                     {
                          Delay_ms(ms); // wait for switch debounce
                          itrue=1;
                          x=0;
                          Lcd_Cmd(_LCD_CLEAR);                    // Clear display
                          Lcd_Cmd(_LCD_CURSOR_OFF);
                          Lcd_Out(1,1,CopyConst2Ram(msg,ep));   //enter passward
                          delay_ms(t);
                          passward();
                          Delay_ms(1000);
                                   Lcd_Cmd(_LCD_CLEAR);                    // Clear display
                                   Lcd_Cmd(_LCD_CURSOR_OFF);
                                   Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
                                   Lcd_Out(1,1,CopyConst2Ram(msg,pw));   //please wait
                                   Delay_ms(1000);

                                   Lcd_Cmd(_LCD_CLEAR);
                                   Lcd_Out(1,1,CopyConst2Ram(msg,gwt));  // Generator warm up time

                                   inc=0;  //for selection of variable
                                   itrue=1;   // Entring and Exiting main menu
                                   opt=1;    // option b/w selection number or variable

                                             while(itrue==1)
                                             {
                                                  if ((enter==0) && (reset==1) && (up==1) && (down==1))//(Button(&PORTD,0,ms,0))  // pressing enter to enter time
                                                  {
                                                      Delay_ms(ms); // wait for switch debounce
                                                      opt=0;
                                                      Lcd_Out(2,1,CopyConst2Ram(msg,sp));
                                                  }

                                                      Delay_ms(200);

                                                  if ((enter==1) && (reset==0) && (up==1) && (down==1))//(Button(&PORTD,1,ms,0)) //press reset to exit
                                                  {
                                                     Delay_ms(ms); // wait for switch debounce
                                                     itrue=0;
                                                  }
                                                  
                                                      Delay_ms(200);
                                                  
                                                  if ((enter==1) && (reset==1) && (up==0) && (down==1))//(Button(&PORTD,2,ms,0))  //up
                                                  {
                                                      Delay_ms(ms); // wait for switch debounce
                                                      inc=scroll_up(opt,inc);
                                                  }

                                                       Delay_ms(200);

                                                  if ((enter==1) && (reset==1) && (up==1) && (down==0))//(Button(&PORTD,3,ms,0))   // down
                                                   {
                                                      Delay_ms(ms); // wait for switch debounce
                                                      inc=scroll_down(inc);
                                                   }
                                                   
                                                       Delay_ms(200);
                                             }

                                              x++;

                          Delay_ms(500);
                     }
and here is the scroll function that i.ve decleared before main() function.

[code]
// ----------------------- scroll up -------------------------------------------

scroll_up( int opt ,int inc )
{
int j=1;

if(opt==1)
{
inc++;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);

if(inc==0)
Lcd_Out(1,1,CopyConst2Ram(msg,gwt));

if(inc==1)
Lcd_Out(1,1,CopyConst2Ram(msg,sont));

if(inc==2)
{
Lcd_Out(1,1,CopyConst2Ram(msg,soft));
inc=-1;
}
} //end if opt = 1

if(opt==0)
{

if (inc < 0)
inc=2;
// Lcd_Cmd(_LCD_CLEAR); // Clear display
// Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);

//..................inc=0...gen_wt.................. .............
if(inc==0)
{
x=EEPROM_Read(0x30);
// x=gen_wt;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,CopyConst2Ram(msg,gwt));
IntToStr(x, string);
Lcd_Out(2,10,string);

do
{
if((enter==1) && (reset==1) && (up==0) && (down==1) && j==1)//(Button(&PORTD,2,ms,0)&&j) // up pressed
{ Delay_ms(ms); // wait for switch debounce
x++;
}

if((enter==1) && (reset==1) && (up==1) && (down==0) && j==1)//(Button(&PORTD,2,ms,0)&&j) // up pressed
{ Delay_ms(ms); // wait for switch debounce
x--;
}

IntToStr(x, string);
Lcd_Out(2,10,string);

Delay_ms(500);
// }// end if

if((enter==0) && (reset==1) && (up==1) && (down==1))//( Button(&PORTD,0,ms,0)) //Enter pressed to save
{ Delay_ms(ms); // wait for switch debounce
gen_wt=x;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Delay_ms(500);
Lcd_Out(1,1,CopyConst2Ram(msg,sav));
EEPROM_Write(0x30, x );
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,CopyConst2Ram(msg,gwt));
IntToStr(x, string);
Lcd_Out(2,10,string);
j=0; x=0; opt=1;
} // end saving

} while(j);
}// if inc=0
//.................... inc = 1 ...... self_ont ..............
if(inc==1)
{
x=EEPROM_Read(0x38);
// x=self_ont;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,CopyConst2Ram(msg,sont));
IntToStr(x, string);
Lcd_Out(2,10,string);

do
{
if((enter==1) && (reset==1) && (up==0) && (down==1) && j==1)//(Button(&PORTD,2,ms,0)&&j) // up pressed
{ Delay_ms(ms); // wait for switch debounce
x++;
}

if((enter==1) && (reset==1) && (up==1) && (down==0) && j==1)//(Button(&PORTD,2,ms,0)&&j) // down pressed
{ Delay_ms(ms); // wait for switch debounce
x--;
}
IntToStr(x, string);
Lcd_Out(2,10,string);

Delay_ms(500);
// }// end if

if((enter==0) && (reset==1) && (up==1) && (down==1))//( Button(&PORTD,0,ms,0)) //Enter pressed to save
{ Delay_ms(ms); // wait for switch debounce
self_ont=x;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Delay_ms(500);
Lcd_Out(1,1,CopyConst2Ram(msg,sav));
EEPROM_Write(0x38, x );
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,CopyConst2Ram(msg,sont));
IntToStr(x, string);
Lcd_Out(2,10,string);
j=0; x=0; opt=1;
} // end saving

} while(j);
}// if inc=1
//.....................inc=2................self_oft ..................................
if(inc==2)
{
x=EEPROM_Read(0x40);
// x=self_oft;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,CopyConst2Ram(msg,soft));
IntToStr(x, string);
Lcd_Out(2,10,string);

do
{
if((enter==1) && (reset==1) && (up==0) && (down==1) && j==1)//(Button(&PORTD,2,ms,0)&&j) // up pressed
{ Delay_ms(ms); // wait for switch debounce
x++;
}

if((enter==1) && (reset==1) && (up==1) && (down==0) && j==1)//(Button(&PORTD,2,ms,0)&&j) // up pressed
{ Delay_ms(ms); // wait for switch debounce
x--;
}
IntToStr(x, string);
Lcd_Out(2,10,string);
Delay_ms(500);
inc=-1;
// }// end if

if((enter==0) && (reset==1) && (up==1) && (down==1))//( Button(&PORTD,0,ms,0)) //Enter pressed to save
{ Delay_ms(ms); // wait for switch debounce
self_oft=x;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Delay_ms(500);
Lcd_Out(1,1,CopyConst2Ram(msg,sav));
EEPROM_Write(0x40, x );
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,CopyConst2Ram(msg,soft));
IntToStr(x, string);
Lcd_Out(2,10,string);
j=0; x=0; opt=1;
} // end saving

// inc=0;

} while(j);
}// if inc=2


} // if opt = 0

return (inc);

} // end scroll up

//-----------------------scroll Down ...........................................

scroll_down(int inc )
{
// int j=1;
inc--;

if (inc < 0)
inc=2;

if(opt==1)
{
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);

if(inc==0)
Lcd_Out(1,1,CopyConst2Ram(msg,gwt));

if(inc==1)
Lcd_Out(1,1,CopyConst2Ram(msg,sont));

if(inc==2)
{
Lcd_Out(1,1,CopyConst2Ram(msg,soft));
}
} //end if opt = 1
return (inc);
}