Shop OBEX P1 Docs P2 Docs Learn Events
Checking the input register and the If command question — Parallax Forums

Checking the input register and the If command question

JMLStamp2pJMLStamp2p Posts: 259
edited 2007-12-10 18:37 in Propeller 1
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)····················

Comments

  • rjo_rjo_ Posts: 1,825
    edited 2007-12-09 06:32
    You should explicitly set dira to zero before your ina.
    if not temp == 1

    you could also use

    repeat while temp <> 1
    dojohns (same indent as your repeat)

    Rich
  • rjo_rjo_ Posts: 1,825
    edited 2007-12-09 06:34
    can't post edit yet...in the last line above I renamed your "Johns"... a little tired. Sorry.
  • hippyhippy Posts: 1,981
    edited 2007-12-09 10:56
    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"
    
    
    



    A nasty bit of recursion there, as well as probably not doing what's intended. Perhaps you mean ...

    PUB CheckPin
      repeat until INA[noparse][[/noparse]21] <> 0
      Johns
    
    
    
  • deSilvadeSilva Posts: 2,967
    edited 2007-12-09 13:53
    @JMLStamp2p
    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
      _CLKMODE      = XTAL1 + PLL8X                        
      _XINFREQ      = 8_000_000
    
    
    OBJ
      OLED  : "uOLED-96-Prop_V4"
      DELAY : "Clock"
      DATA : "FullDuplexSerial
      
    [b]PUB main[/b]
     
      DELAY.Init(8_000_000)
      OLED.InitOLED
      OLED.CLS
    
      ' 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
     
    
      UNTIL INA[noparse][[/noparse]21]                   'Wait for Pin "21" to go High 
      ' no loop body for simple wait loop
      ' WAITPEQ(|<21, |<21) would do the same
    
    
      data.tx($40)                  'Pic. Commands sent to the OLED-160
      data.tx($49)
    .....
      data.tx($00)
      waitAck                       'Wait 3 seconds for Ack. after Command sequence before continuing
       
      DELAY.PauseSec(10)
      OLED.CLS 
     
    'end of main; COG stops here
    
      
    [b]PRI waitAck[/b]                        
       waitcnt(3_000_000+cnt)
    



    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:
      _CLKMODE      = XTAL1 + PLL8X                       
      _XINFREQ      = 8_000_000
     
    OBJ
      OLED  : "uOLED-96-Prop_V4"
      DELAY : "Clock"
      DATA : "FullDuplexSerial"
    
    PUB main
     
      DELAY.Init(8_000_000)
      OLED.InitOLED
      OLED.CLS
      Transmit
      DELAY.PauseSec(3)             'Wait for at least 1 sec.after Auto Baud before sending Commands
      CheckPin                           'Goto the CheckPin method
      Johns
    
    
    
    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
    
     
    PUB CheckPin 
      UNTIL INA[noparse][[/noparse]21]                  'Wait for Pin "21" to go High
     
    PUB Johns
      data.tx($40)                  'Pic. Commands sent to the OLED-160
    
    ....
      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)
    
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2007-12-10 18:37
    Thanks guys for the help, it is greatly appreciated.
    JMLStamp2p
Sign In or Register to comment.