Thanks for the replies

1. Missing THEN at end of IF statement

I made 2 mistakes
I didn't put in the "THEN" and didn't declare the variable, hense the Errors
Sometimes the most obvious gives the most problems


2. Why RETURN?

It is part of a GOSUB - Below is a snippet

What I'm trying to do is rewriting the code (optimization)- the SELECT CASE for the TwoMinRecord: is 190 lines
Also see if I can gain more code space to ad more recording times

MENUITEM3:

TimeOut=0 ; Zero the Time-Out counter
GOSUB ReadA2D ; Read ADC1 & 2, oversample and average
GOSUB StoreProm ; Read RTC, time correct, store to Ext EEPROM
LCDOut $FE,1,"Storage Interval"
LCDOut $FE,$C0,"Minutes = "
Pause Time1

SetupStorageLoop: '
If CounterTime=0 then
LCDOut $FE,$CA," 1"
CounterTime1=1
endif
If CounterTime=1 then
LCDOut $FE,$CA," 2"
CounterTime1=2
endif
If CounterTime=2 then
LCDOut $FE,$CA," 5"
CounterTime1=5
endif
If CounterTime=3 then
LCDOut $FE,$CA,"10"
CounterTime1=10
endif
If CounterTime=4 then
LCDOut $FE,$CA,"20"
CounterTime1=20
endif
If CounterTime=5 then
LCDOut $FE,$CA,"30"
CounterTime1=30
endif
If CounterTime=6 then
LCDOut $FE,$CA,"60"
CounterTime1=60
endif

StorePROM:
I2CRead SDA,SCL,I2CRTC,RTCAddr,[RTCSec,RTCMin,RTCHour,RTCWDay,RTCDay,RTCMonth,RTCY ear]
Pause 20

;====CONVERT BCD TO DECIMAL====
ConvertBCD1:
DecDay=((RTCDay>>4)&$0F)*10+(RTCDay&$0F)
DecMonth=((RTCMonth>>4)&$0F)*10+(RTCMonth&$0F)
DecYear=((RTCYear>>4)&$0F)*10+(RTCYear&$0F)
DecHour=((RTCHour>>4)&$0F)*10+(RTCHour&$0F)
DecMin=((RTCMin>>4)&$0F)*10+(RTCMin&$0F)
DecSec=((RTCSec>>4)&$0F)*10+(RTCSec&$0F)

;====SELECT RECORD PERIOD====
Select Case CounterTime1
case 1
gosub OneMinRec

case 2
gosub TwoMinRec

case 5
gosub FiveMinRec

case 10
gosub TenMinRec

case 20
gosub TwentyMinRec

case 30
gosub ThirtyMinRec

case 60
gosub SixtyMinRec

end select
Return

ThirtyMinRec:

LED1=0:LED2=1:LED3=1:LED4=0 ;Status LEDS
Select Case DecMin
Case 0 ;00/60 Min check
Gosub PromWrite ;Write to Ext EEPROM
If DecMin > 0 Then ;Prevent writing to EEPROM for 1 Min
StoreCalc = 0 ;reset bit to prevent above
EndIf
Return
Case 30 ;30 min Check
Gosub PromWrite ;Write to Ext EEPROM
If DecMin > 30 Then ;Prevent writing to EEPROM for 1 Min
StoreCalc = 0 ;reset bit to prevent above
EndIf
Return
End Select
StoreCalc = 0 ;Restet bit if something goes wrong
Return

I'm trying to rewrite the ThirtyMinRec: routine with this section below

Now looking at it with better understanding, The "If decsec > temp then" will not do what I thought.


; Lookup2 DecMin,[0,30],temp ;Replacement code for above
; If DecMin > temp ;Temp var word
; Storecalc = 0 ;Reset bit
; return
; Endif

PROMWRITE:
If StoreCalc = 0 then
I2CWRITE SDA,SCL,I2CProm,MEMPOS,[ADC1,ADC2,DecMin,DecHour,DecDay,DecMonth,DecYear,i ,i] ; Write temp1 to the location that is store in the int eeprom "memory position"
Pause 2
MEMPOS = MEMPOS + 16 ; Incrument the memory position
WRITE 0,MEMPOS.Highbyte ; Write new Memory position to int EEPROM
WRITE 1,MEMPOS.Lowbyte
StoreCalc = StoreCalc + 1
If MEMPOS > $7FFE then ; Max number of positions a 24LC256 can take
LCDOUT $FE,1,"Memory is full" ; if the ext EEPROM is full, display message
LCDOUT $FE,$C0,"Download to PC"
MEMPOS = $0
LED6 = 1
EndIf
EndIf
RETURN