Shop OBEX P1 Docs P2 Docs Learn Events
27113 IO card SHIFOUT — Parallax Forums

27113 IO card SHIFOUT

TexFlyTexFly Posts: 26
edited 2011-10-25 17:21 in Propeller 1
Hello,

I would like to use the serial feature of the 27113 IO card with the Propeller chip. How do I translate the Basic stamp code listed below?
' -----[ Program Code ]----------------------------------------------------

Main:
  DO
    GOSUB Out_595                       ' Update 74HC595
    DEBUG HOME, "       76543210", CR
    DEBUG "RELAYS:", BIN8 index, CR     ' Display Current Output States
    GOSUB In_165                        ' Read 74HC165
    DEBUG "INPUTS:", BIN8 optos         ' Display Current Input States
    index = index + 1                   ' Increment Counter
    PAUSE 500                           ' Small Delay (1/2 Second)
  LOOP
  STOP


' -----[ Subroutines ]-----------------------------------------------------

Out_595:
  SHIFTOUT DataIO, Clock, MSBFIRST, [index]
  PULSOUT HC595, 5                      ' Latch Outputs
  RETURN

In_165:
  PULSOUT HC165, 5                      ' Load Inputs
  SHIFTIN DataIO, Clock, MSBPRE, [optos]
  RETURN

Comments

  • JonnyMacJonnyMac Posts: 9,202
    edited 2011-07-31 19:29
    These should get you started (though you'll likely find full-fledge objects for each chip in ObEx). These methods work very much like your PBASIC code (that looks like something I wrote a long time ago...) in that you pass the pins you want to use. With 32-bit variables in Spin you can pass the number of bits to write or read; logically, the bits paramater should be 8, 16, 24, or 32, depending on the number of shift registers that are chained.
    pub out_595(dio, clock, latch, value, bits)
    
      dira[dio]   := 1                                              ' output
    
      outa[clock] := 0                                              ' output/low
      dira[clock] := 1
    
      outa[latch] := 0                                              ' output/low
      dira[latch] := 1
    
      value <<= (32-bits)                                           ' shift MSB to bit31
    
      repeat bits
        outa[dio]   := (value <-= 1) & %1                           ' get bit (from MSB)
        outa[clock] := 1                                            ' clock it
        outa[clock] := 0
        
      outa[latch] := 1                                              ' latch outputs
      outa[latch] := 0
    
    
    pub in_165(dio, clock, load, bits) | tmp165
    
      outa[load]  := 0                                              ' load inputs
      dira[load]  := 1
      outa[load]  := 1
    
      dira[dio]   := 0                                              ' input
    
      outa[clock] := 0                                              ' output/low
      dira[clock] := 1
    
      tmp165 := 0                                                   ' clear workspace
      repeat bits                                                   ' read n bits         
        tmp165 := (tmp165 << 1) | ina[dio]                          ' get new bit             
        outa[clock] := 1                                            ' blip clock              
        outa[clock] := 0  
    
      return tmp165
    
  • TexFlyTexFly Posts: 26
    edited 2011-08-08 03:07
    Thanks Jon. Almost done building the board. I will try the code very soon...
  • JeffaJeffa Posts: 80
    edited 2011-08-28 21:35
    Hi! Did you ever develop some .spin code for the 27113 digital i/o board? I'm just starting to research using it with .spin.
  • TexFlyTexFly Posts: 26
    edited 2011-10-25 17:21
    Hello,

    Got side tracked by other stuff. I'm just getting back to it. Have you made any progress?
Sign In or Register to comment.