can anyone help me understand
NR1X
Posts: 111
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········
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
' {$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
·
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!