Shop OBEX P1 Docs P2 Docs Learn Events
can anyone help me understand — Parallax Forums

can anyone help me understand

NR1XNR1X Posts: 111
edited 2008-08-08 03:19 in BASIC Stamp
this bit of code is making me nuts!!! the "var T" is a 4 bit binary number between 0 and 16..
i get the idea of "lookup" but this one is over my head right now!! i want to understand how this works!!! the first
"T" = 1011

LOOKUP T,[noparse][[/noparse]"0234567800019000"],J
· J=J-48
· IF J=0 THEN Init
· IF C=1 AND J=1 THEN Key
· IF C=2 AND J=2 THEN Key
· IF C=3 AND J=3 THEN Key
· IF C=4 AND J=4 THEN Key
· IF C=5 AND J=5 THEN Key
· IF C=6 AND J=6 THEN Key
· IF C=7 AND J=7 THEN Key
· IF C=8 AND J=8 THEN Key
· IF C=9 AND J=9 THEN Key
· GOTO Listen

this is part of· program that uses this to increment a counter· when all 3 counters = 9 it goes on with program..
it works· but i want to know how so that i can apply it to other projects········

Comments

  • FranklinFranklin Posts: 4,747
    edited 2008-08-08 01:21
    You need to attach the entire program so we can understand how this part relates to the rest. It would be helpful if you explained what the code was supposed to do and how the input is arrived at.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • NR1XNR1X Posts: 111
    edited 2008-08-08 01:40
    this part of the code gets "T" witch is a 4 bit binary between 0 and 15 .. it uses the lookup table to define "J" , then it subtracts 48 from "J".. j must = 1 to go on then j=2 to go on ...... up to 9 . after each lookup counter "G" is incrimeted +1... when "J","G" and"C" all = 9 then the program triggers the ce pin of a voice record/playback chip... dont want to post the entire code as it is not my own.. its part of a radio voicemail box in a book called "Stamp 2 Communications and Control projects...
  • FranklinFranklin Posts: 4,747
    edited 2008-08-08 02:05
    OK, well I can't help you, I don't understand the code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • NR1XNR1X Posts: 111
    edited 2008-08-08 02:32
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    'RADIOMAIL.BS2
    T······· VAR···· Byte································ ' Received DTMF digit
    df······ VAR···· Bit································· ' DTMF-received flag
    ds······ VAR···· INL.BIT2···························· ' DTMF-detected status bit
    C······· VAR···· Word································ ' Tones rcvd counter variable
    G······· VAR···· Byte································ ' Sequence counter variable
    J······· VAR···· Byte································ ' Table counter variable
    PD······ CON···· 8
    P_R····· CON···· 9
    · OUTL = %01111111··························· ' pin 7 low, pins 0-6 high
    · DIRL = %11111111··························· ' set up write to 8880 (out)
    · OUTL = %00011000··························· ' set up CRA; write to CRB
    · HIGH 6····································· ' low 6 to high 6 = "write"
    · OUTL = %00010000··························· ' clear CRB; rdy/snd DTMF
    · HIGH 6··················································· ' low 6 to high 6 = "write"
    · DIRL = %11110000··························· ' set 4-bit bus to input
    · HIGH 5··················································· ' set R/W to "read"
    · OUTH = %00000011
    · DIRH = %00000011
    Init:················································ ' init routine
    · HIGH 7
    · PAUSE 50
    · LOW PD
    · HIGH P_R··········································· ' turn off output device
    Begin:··············································· ' Reset routine
    · C=0 : G=0 : J=0···································· ' clear all variables to zero
    Listen:·············································· ' listen for DTMF
    · HIGH 4············································· ' read status register
    · LOW 6·············································· ' activate chip-select pin
    · df = ds············································ ' store DTMF-det bit in flag
    · HIGH 6············································· ' de-activate chip-select pin
    · IF df = 1 THEN Lock································ ' if tone, then continue
    · GOTO Listen········································ ' listen again
    Lock:················································ ' Tone detected, test code
    · LOW 4·············································· ' get DTMF data (low rs pin)
    · LOW 6·············································· ' activate chip-select pin
    · T = INL & %00001111································ ' remove upper bits using AND
    · HIGH 6············································· ' de-activate chip-select pin
    · C=C+1·············································· ' increment tone counter
    · IF C>2000 THEN Begin······························· ' resets >2000 wrong entries
    · LOOKUP T,[noparse][[/noparse]"0234567800019000"],J···················· ' convert tone to string
    · J=J-48············································· ' convert string to value
    · IF J=0 THEN Init··································· ' wrong digit "reset"
    · IF C=1 AND J=1 THEN Key···························· '· IF all digits are in the
    · IF C=2 AND J=2 THEN Key···························· '· correct order, AND after
    · IF C=3 AND J=3 THEN Key···························· '· only one attempt, THEN
    · IF C=4 AND J=4 THEN Key···························· '· increment the sequence
    · IF C=5 AND J=5 THEN Key···························· '· counter variable : "G" ...
    · IF C=6 AND J=6 THEN Key
    · IF C=7 AND J=7 THEN Key
    · IF C=8 AND J=8 THEN Key
    · IF C=9 AND J=9 THEN Key
    · GOTO Listen········································ ' listen again
    Key:················································· ' Sequence counter
    · G=G+1·············································· ' increment
    · IF C=9 AND J=9 AND G=9 THEN Relay·················· ' activate output device
    · GOTO Listen········································ ' listen again
    Relay:
    · PAUSE 100
    · 'LOW P_R············································ ' Relay output routine
    · 'PAUSE 800·········································· ' wait time delay
    ·' LOW 7·············································· ' turn on output device
    · 'PAUSE 200
    · DEBUG " it works"·········································· ' wait time delay
    · GOTO Begin········································· ' begin again

    ·
  • metron9metron9 Posts: 1,100
    edited 2008-08-08 03:01
    LOOKUP T,[noparse][[/noparse]"0234567800019000"],J if T=%1011 = 11 then J would found at the 11th spot (counting from 0) and equal "1" or ascii code 49
    J=J-48 subtract 48 and j=1
    IF J=0 THEN Init
    IF C=1 AND J=1 THEN Key so the first time T is checked it must be 11
    IF C=2 AND J=2 THEN Key then T must = %0001 so the lookup finds "2" and that is ascii code value 50, subtract 48 and j=2
    IF C=3 AND J=3 THEN Key and so on...
    IF C=4 AND J=4 THEN Key
    IF C=5 AND J=5 THEN Key
    IF C=6 AND J=6 THEN Key
    IF C=7 AND J=7 THEN Key
    IF C=8 AND J=8 THEN Key
    IF C=9 AND J=9 THEN Key

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • NR1XNR1X Posts: 111
    edited 2008-08-08 03:19
    thanx mentron9, i would have never in 100 years figured out that it was in ascii code!! not to much of a computer background here.. been playin with stamp for only less than ayear. mostly a ham/geek that likes to tinker... anyways thanx again this will be very usefull....
Sign In or Register to comment.