Hi Sayzer,

Thanks for your explanation about the For-Next loop, I think I can grasp the concept of the Index For-Next loop now but what I don't understand is how do I write the values to the different eeprom locations. I added some push buttons to your code to try and increase and decrease the OnTime & OffTime variables and the Hour variable in an attempt to flash an Led but can't get it to work. Could you please help me to understand how to write to the different eeprom locations?

Thanks
jessey


Code:
'Pic18f452-20/P

Increase_OnTime_Push_Button VAR PORTD.2    '(pin 21)  2nd  
Decrease_OnTime_Push_Button var PORTB.0    '(pin 33)  3rd  
Increase_OffTime_Push_Button var PORTB.1   '(pin 34)  4th                 
Decrease_OffTime_Push_Button var PORTB.2   '(pin 20)  5th  
Change_On_Off_Time_Push_Button VAR PORTD.1 '(pin 35)  6th  
Led VAR PORTA.1                            '(pin 3)
Buzzer VAR PORTC.2                         '(pin 17)

OnTime  var byte
OffTime var byte
Index   var byte
Hour    var byte
HOUR = 0

Is_Pressed con 0
Is_Not_Pressed con 1      

EEPROM 1,[1,2,3,4,5,6,7,8,9,10,101,102,103,104,105,106,107,108,109,110]

GOTO MainLoop

Change_On_Off_Time:
    PWM Buzzer,250,1
    WHILE Change_On_Off_Time_Push_Button = Is_Pressed : PAUSE 100 : WEND
Loop:
    IF Increase_OnTime_Push_Button = Is_Pressed THEN 
       OnTime = OnTime + 1 : PWM Buzzer,250,1 
       WRITE 1, OnTime
    ENDIF

    IF Decrease_OnTime_Push_Button = Is_Pressed THEN
       OnTime = OnTime - 1 : PWM Buzzer,250,1 
       WRITE 1, OnTime
    ENDIF
                                   
    IF Increase_OffTime_Push_Button = Is_Pressed THEN
       OffTime = OffTime + 1 : PWM Buzzer,250,1 
       WRITE 101, OffTime
    ENDIF

    IF Decrease_OffTime_Push_Button = Is_Pressed THEN
       OffTime = OffTime - 1 : PWM Buzzer,250,1 
       WRITE 101, OffTime
    ENDIF

    IF Change_On_Off_Time_Push_Button = Is_Pressed THEN
      PWM Buzzer,250,1
      WHILE Change_On_Off_Time_Push_Button = Is_Pressed : PAUSE 100 : WEND
      RETURN
    ENDIF

       LCDOUT $fe,1,"OnTime  = ",dec Ontime
    LCDOUT $fe, $c0,"OffTime = ",dec OffTime 
    PAUSE 100
goto Loop


MainLoop:
    IF Change_On_Off_Time_Push_Button = Is_Pressed THEN GOSUB Change_On_Off_Time

   'Hour variable gets its value here......
    IF Increase_OnTime_Push_Button = Is_Pressed THEN 
       Hour = Hour + 1 : PWM Buzzer,250,1 
    ENDIF

   'Hour variable gets its value here......
    IF Decrease_OnTime_Push_Button = Is_Pressed THEN
       Hour = Hour - 1 : PWM Buzzer,250,1 
    ENDIF

       LCDOUT $fe,1,"Hr=",dec Hour," OnTime=",dec Ontime
    LCDOUT $fe, $c0,"OffTime = ",dec OffTime

    PAUSE 100

    FOR Index = 1 to 10
        READ Index , OnTime            ' Read stored ON  time.
        READ Index +100, OffTime       ' Read stored OFF time.
        IF Hour = Ontime  THEN Led = 1 ' If yes, turn ON the relay.
        IF Hour = Offtime THEN Led = 0 ' If yes, turn OFF the relay.
    NEXT Index 
GOTO MainLoop
END