Hi Thank you for reading...

Using a 16f627

All I want to do is turn a light on at a time and turn it off a time later.... What am I doing wrong here.

Turns on OK but sees to add 4mins to the turn off time... Also randomly turns on !

Help please... Thank you for reading !

Code:
' Alias pins
            SDA Var PORTB.1
            SCL Var PORTB.2
            Light var PORTB.6 
        
' Allocate variables
            RTCYear  Var Byte
            RTCMonth Var Byte
            RTCDate  Var Byte
            RTCDay   Var Byte
            RTCHour  Var Byte
            RTCMin   Var Byte
            RTCSec   Var Byte
            RTCCtrl  Var Byte
        
'Set initial time 
            RTCYear = $18
            RTCMonth = $09
            RTCDate = $18
            RTCDay = $03
            RTCHour = $00
            RTCMin = $00
            RTCSec = 0
            RTCCtrl = 0
            Gosub settime        ' Set the time
            Goto mainloop        ' Skip over subroutines

' Subroutine to write time to RTC

settime:I2CWrite SDA, SCL, $D0, $00, [RTCSec, RTCMin, RTCHour, RTCDay, RTCDate, RTCMonth, RTCYear, RTCCtrl]
        Return

' Subroutine to read time from RTC
        
gettime:    I2CRead SDA, SCL, $D0, $00, [RTCSec, RTCMin, RTCHour, RTCDay, RTCDate, RTCMonth, RTCYear, RTCCtrl]
            Return

' Main program loop 
        
mainloop:   Gosub gettime        ' Read the time from the RTC
            IF (RTCHour=$00) and (RTCMin=$01) Then Light_On ' Light on
            IF (RTCHour=$00) and (RTCMin=$02) Then Light_Off ' Light off
            Pause 500            ' Do it about 2 times a min
            Goto mainloop        ' Do it forever and ever and ever
        
        
        
Light_On:   high Light
            return 
            
Light_Off:  Low light
            return             
            
        
       
   End