Elusive "Lookup"


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2013
    Location
    Benoni, South Africa
    Posts
    2

    Smile Elusive "Lookup"

    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

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,625


    Did you find this post helpful? Yes | No

    Default Re: Elusive "Lookup"

    I can't see anything wrong with LOOKUP2 by reviewing manual (experts might see something there though).

    Code:
    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:

    Code:
    If decsec > temp THEN Storecalc = 0
    Robert

  3. #3
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    948


    Did you find this post helpful? Yes | No

    Default Re: Elusive "Lookup"

    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.

  4. #4
    Join Date
    Jun 2013
    Location
    Benoni, South Africa
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: Elusive "Lookup"

    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

Similar Threads

  1. Replies: 3
    Last Post: - 15th October 2012, 08:06
  2. Replies: 12
    Last Post: - 21st July 2012, 20:27
  3. Replies: 1
    Last Post: - 27th August 2009, 02:42
  4. Kind of "customisable" LOOKUP(2), possible?
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 5th May 2009, 19:45
  5. Replies: 1
    Last Post: - 16th February 2005, 20:05

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts