Elusive "Lookup"


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    966


    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.

  2. #2
    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 : 1

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