PDA

View Full Version : Elusive "Lookup"



Darrell
- 22nd June 2013, 20:24
Hi all

Thanx for all the usefull info over the years. Much apreciated.

Can someone please point me in the right direction.

I'm building a temp. logger using 16PIC877a - DS1307 - 24LC256, PBP 2.60C, MPLAB8.87 & ICD2/PicKit2
I come up with various errors listed below?????

Have I interpreted the Lookup command wrongly?

My code snip:- LOOKUP replace CASE SELECT

Read from RTC is converted from BCD to decimal beforehand
With the SELECT CASE - no errors

1107 ThirtyMinRec:

1108 LED1=0:LED2=1:LED3=1:LED4=0 ;Status LEDS
1109 ;Select Case DecMin
1110 ; Case 0 :00/60 Min check
1111 ; Gosub PromWrite ;Write to Ext EEPROM
1112 ; If DecMin > 0 Then ;Prevent writing to EEPROM for 1 Min
1113 ; StoreCalc = 0 ;reset bit to prevent above
1114 ; EndIf
1115 ; Return
1116 ; Case 30 ;30 min Check
1117 ; Gosub PromWrite ;Write to Ext EEPROM
1118 ; If DecMin > 30 Then ;Prevent writing to EEPROM for 1 Min
1119 ; StoreCalc = 0 ;reset bit to prevent above
1120 ; EndIf
1121 ; Return
1122 ; End Select
1123 ;StoreCalc = 0 ;Restet bit if something goes wrong
1124 ;Return

1125 Lookup2 decsec,[0,30],temp ;Replacement code for above
1126 If decsec > temp ;Temp var word
1127 Storecalc = 0 ;Reset bit
1128 return
1129 Endif

ERRORS

Executing: "C:\PBP\PBPMPLAB.BAT" -ampasmwin -k# -p16F877A "PIC877 Temp DataLogV1.bas"
Executing: "C:\PBP\PBPW.EXE" -ampasmwin -k# -p16F877A "PIC877 Temp DataLogV1.bas"
PICBASIC PRO(TM) Compiler 2.60C, (c) 1998, 2011 microEngineering Labs, Inc.
All Rights Reserved.
C:\16F877 TEMP CONTROL\PIC877 TEMP CONTROL\PIC877 TEMP DATALOGV1\PIC877 TEMP DATALOGV1.BAS ERROR Line 746: ID SixtyMinRec is not a LABEL.
C:\16F877 TEMP CONTROL\PIC877 TEMP CONTROL\PIC877 TEMP DATALOGV1\PIC877 TEMP DATALOGV1.BAS ERROR Line 1125: Expected ']'.
C:\16F877 TEMP CONTROL\PIC877 TEMP CONTROL\PIC877 TEMP DATALOGV1\PIC877 TEMP DATALOGV1.BAS ERROR Line 1154: Syntax error.
C:\16F877 TEMP CONTROL\PIC877 TEMP CONTROL\PIC877 TEMP DATALOGV1\PIC877 TEMP DATALOGV1.BAS ERROR Line 1162: ENDIF without a matching IF..THEN.
C:\16F877 TEMP CONTROL\PIC877 TEMP CONTROL\PIC877 TEMP DATALOGV1\PIC877 TEMP DATALOGV1.BAS ERROR Line 1163: ENDIF without a matching IF..THEN.1125: Syntax error
1125: Syntax error
Halting build on first failure as requested.
BUILD FAILED: Sat Jun 22 19:40:26 2013

Demon
- 23rd June 2013, 05:27
I can't see anything wrong with LOOKUP2 by reviewing manual (experts might see something there though).


1126 If decsec > temp ;Temp var word
1127 Storecalc = 0 ;Reset bit
1128 return
1129 Endif


1. Missing THEN at end of IF statement

2. Why RETURN?

3. You can insert single commands directly in IF statement, like this:


If decsec > temp THEN Storecalc = 0

Robert

Jerson
- 23rd June 2013, 13:56
The LOOKUP2 statement can be used to retrieve entries from a table of
Values. If Index is zero, Var is set to the first Value. If Index is one,
Var is set to the second Value. And so on. If Index is greater than or
equal to the number of entries in the list, and Var remains unchanged.

The variable decsec should contain either 0 or 1 since your table is just 2 entries long.

Darrell
- 24th June 2013, 09:55
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