Checking the input register and the If command question
JMLStamp2p
Posts: 259
Hello, I want to·monitor input register "A" and jump to Johns sub-routine when it has ack. a logical high or 3.6V on Pin "21". Could someone please look at my code in the CheckPin method below and make comments
on where I am·coding wrong.
...............................................................................................................................................
CON
· _CLKMODE····· = XTAL1 + PLL8X·······················
· _XINFREQ····· = 8_000_000
· dSlow········ = 50
· dFast········ = 20
·
OBJ
· OLED· : "uOLED-96-Prop_V4"
· DELAY : "Clock"
· DATA : "FullDuplexSerial"
VAR
· long Stack [noparse][[/noparse]9]
· byte Byte_Recieved
· byte Temp
·
PUB MAIN
· DELAY.Init(8_000_000)
· OLED.InitOLED
· OLED.CLS
· Transmit
··
PUB Transmit
· data.start(21,20,0,9600)····· 'Set up Serial Commands
· DELAY.PauseSec(7)············ 'Wait for OLED to stabalize
· data.tx($55)··················· · 'Send Auto Baud Command
· DELAY.PauseSec(3)············ 'Wait for at least 1 sec.after Auto Baud before sending Commands
· CheckPin·························· 'Goto the CheckPin method
PUB CheckPin
·
· Temp:= INA[noparse][[/noparse]21]··············· 'Wait for Pin "21" to go High
· If Temp == 1··················· 'If Pin 21 is High·goto Johns
··· Johns
· If Not CheckPin················ 'If not re-check Pin "21"
·
PUB Johns
· data.tx($40)················· 'Pic. Commands sent to the OLED-160
· data.tx($49)
· data.tx($00)
· data.tx($00)
· data.tx($80)
· data.tx($80)
· data.tx($10)
· data.tx($00)
· data.tx($10)·
· data.tx($00)
· data.tx($0B)
· data.tx($00)
· data.tx($00)
· data.tx($00)
· data.tx($00)
· waitAck······················ 'Wait 3 seconds for Ack. after Command sequence before continuing
··
·· DELAY.PauseSec(10)
·· OLED.CLS
··
PRI waitAck·······················
·· waitcnt(3_000_000+cnt)····················
on where I am·coding wrong.
...............................................................................................................................................
CON
· _CLKMODE····· = XTAL1 + PLL8X·······················
· _XINFREQ····· = 8_000_000
· dSlow········ = 50
· dFast········ = 20
·
OBJ
· OLED· : "uOLED-96-Prop_V4"
· DELAY : "Clock"
· DATA : "FullDuplexSerial"
VAR
· long Stack [noparse][[/noparse]9]
· byte Byte_Recieved
· byte Temp
·
PUB MAIN
· DELAY.Init(8_000_000)
· OLED.InitOLED
· OLED.CLS
· Transmit
··
PUB Transmit
· data.start(21,20,0,9600)····· 'Set up Serial Commands
· DELAY.PauseSec(7)············ 'Wait for OLED to stabalize
· data.tx($55)··················· · 'Send Auto Baud Command
· DELAY.PauseSec(3)············ 'Wait for at least 1 sec.after Auto Baud before sending Commands
· CheckPin·························· 'Goto the CheckPin method
PUB CheckPin
·
· Temp:= INA[noparse][[/noparse]21]··············· 'Wait for Pin "21" to go High
· If Temp == 1··················· 'If Pin 21 is High·goto Johns
··· Johns
· If Not CheckPin················ 'If not re-check Pin "21"
·
PUB Johns
· data.tx($40)················· 'Pic. Commands sent to the OLED-160
· data.tx($49)
· data.tx($00)
· data.tx($00)
· data.tx($80)
· data.tx($80)
· data.tx($10)
· data.tx($00)
· data.tx($10)·
· data.tx($00)
· data.tx($0B)
· data.tx($00)
· data.tx($00)
· data.tx($00)
· data.tx($00)
· waitAck······················ 'Wait 3 seconds for Ack. after Command sequence before continuing
··
·· DELAY.PauseSec(10)
·· OLED.CLS
··
PRI waitAck·······················
·· waitcnt(3_000_000+cnt)····················
Comments
if not temp == 1
you could also use
repeat while temp <> 1
dojohns (same indent as your repeat)
Rich
A nasty bit of recursion there, as well as probably not doing what's intended. Perhaps you mean ...
You have some misconceptions
- with the use of IF and ELSE
- with the use of routines
What you do is possible in some high end functional languages which recognize tail recursion and stepwise refinement resolution, but the garden variety of languages work differently. Check some other person's programs to get the idea.
Your program could read
Note that it is bad practice to use 3_000_000 (better: CLKFREQ*3/5), or mixing WAITCNT and DELAY...
Your program could also go:
JMLStamp2p