Shop OBEX P1 Docs P2 Docs Learn Events
Output on a bit condition — Parallax Forums

Output on a bit condition

AlessandroAlessandro Posts: 26
edited 2008-09-22 10:59 in General Discussion
Hi again!

I'm making a sort of polling and i have to make a pin high if a bit of a variable is 1 or i have to make the same pin low if the bit of a varialbe is 0.

bytetest····· var byte
dataout······ var rb.0

.....
dataout=bytetest.7· (the MSB of bytetest)


but it seems to not work...

i have also use "IF"·
If bytetest.7=1 then high dataout··· (it doesn't work the same)

it is a stupid .... but i'm going crazy.

Can anybody help me?
Alessandro (italy)

Comments

  • JonnyMacJonnyMac Posts: 9,214
    edited 2008-09-19 16:51
    You should use the PIN definition for your output -- like this:

    DataOut         PIN     RB.0 OUTPUT
    


    ... then it will follow the selected bit of your test byte. You didn't post the whole program so I'm guessing that RB.0 was not made an output hence you were not able to see anything (externally) that was written to the RB.0 output register.
  • AlessandroAlessandro Posts: 26
    edited 2008-09-19 21:33
    On monday i will try your guess....

    i was able to see if i wrote "high DataOut" with this i read a 1 on my oscilloscope.

    Thanks....
    you are GREAT!

    Alessandro
  • JonnyMacJonnyMac Posts: 9,214
    edited 2008-09-19 22:43
    It's not a guess, it actually works! tongue.gif Here you can see it in use in one of my programs that writes a byte to an ISD17xx chip while reading a byte back.

    ' Use: bResult = SHIFT_IO aByte
    ' -- sends 'aByte' on MOSI
    ' -- receives 'bResult' on MISO
    
    FUNC SHIFT_IO
      tmpB1 = __PARAM1                              ' capture MOSI byte
      tmpB2 = 0                                     ' clear MISO byte
    
      FOR tmpB3 = 0 TO 7
        SClk = 0                                    ' SClk: 1 -> 0
        MoSi = tmpB1.0                              ' setup MOSI bit
        tmpB1 = tmpB1 >> 1                          ' prep for next bit
        DELAY_US 1
        tmpB2 = tmpB2 >> 1                          ' prep for new bit
        tmpB2.7 = MiSo                              ' get it
        SClk = 1                                    ' SClk: 0 -> 1
        DELAY_US 1
      NEXT
      RETURN tmpB2
      ENDFUNC
    
  • AlessandroAlessandro Posts: 26
    edited 2008-09-22 09:48
    This is my code... but it is not working....

    I'm doing a polling on a bit and when i read an external clock i have to make an output...

    the comments are in italian, but if you need i can traslate.



    it is not the complete program but i have to debug in small piece...



    ' =========================================================================
    '
    '·· File...... TEMPLATE.SXB
    '·· Purpose... SX/B Programming Template
    '·· Author....·
    '·· E-mail....·
    '·· Started...
    '·· Updated...
    '
    ' =========================================================================


    '
    ' Program Description
    '


    '
    ' Device Settings
    '

    DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
    FREQ··········· 4_000_000


    '
    ' IO Pins
    '
    '
    waitbit··var ·rc.0
    ackbit··var·rc.1
    data_inout·pin·rc.6
    clock_in·pin·rc.7

    Rx1byte··var ·byte

    ' =========================================================================
    · PROGRAM Start
    ' =========================================================================

    Start:


    Rx1byte=%10000000

    watch Rx1byte
    Main:
    · high waitbit·'dico alla Bs2 che i dati sono pronti
    pauseus 100
    ·low waitbit
    attesa_invio1_clk_alto:
    if ackbit=0 then goto attesa_invio1_clk_alto·'aspetto il bit di conferma di inizio ricezione

    attesa_invio1_clk_alto7:
    if clock_in=0 then goto attesa_invio1_clk_alto7


    'high data_inout···· <
    this instead works fine... but i don't need a static output
    data_inout=Rx1byte.7 <
    it in particolar doesn't work even with "pin" definition

    attesa_invio1_clk_basso7:
    if clock_in=1 then goto attesa_invio1_clk_basso7
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    attesa_invio1_clk_alto6:
    if clock_in=0 then goto attesa_invio1_clk_alto6
    data_inout=1

    attesa_invio1_clk_basso6:
    if clock_in=1 then goto attesa_invio1_clk_basso6
    break


    Thanks
    Alessandro (italy)
  • JonnyMacJonnyMac Posts: 9,214
    edited 2008-09-22 10:59
    I don't know what you're doing but your program compiles fine for me using the PIN definition as you should (with the OUTPUT option -- refer to my earlier response). Are you using version 1.51.03 of the compiler?
Sign In or Register to comment.