Shop OBEX P1 Docs P2 Docs Learn Events
Help for a beginner — Parallax Forums

Help for a beginner

SSkalkoSSkalko Posts: 9
edited 2010-10-11 13:23 in Propeller 1
I am working on my first Propeller project working out how to write the code for individual compenents as a way to learn Spin. Right now, I am working with a 4 bit serial to parallel static shift register. I need a way to read and write individual bits of a byte size variable. I am using 3 pin on the Prop to do this. One is for a dedicate clock for the shift register at 1 kHz using this code.
OUTPUT is a byte size variable to start the sequence. Each Method would be running on a seperate cog.
Pub CLOCK
   
   dira[CLKPIN] := 1

   repeat
       IF OUTPUT == 1
           OUTPUT := 0
           repeat 4
               outa[CLKPIN] := 1
               waitcnt(clkfreq/1000 + cnt)
               outa[CLKPIN] := 0
               waitcnt(clkfreq/1000 + cnt)

The trouble I am having is find the right code to read and write individual bits of a byte size variable.
PUB SHIFT

    dira[SHFTPIN] := 1

    repeat
        waitpeq(CLKPIN, 1)
        outa[SHFTPIN] := {first bit to be shifted in}
        waitpeq(CLKPIN, 0)
        waitpeq(CLKPIN, 1)
        outa[SHFTPIN] := {second bit to be shifted in}
        waitpeq(CLKPIN, 0)
        waitpeq(CLKPIN, 1)
        outa[SHFTPIN] := {third bit to be shifted in}
        waitpeq(CLKPIN, 0)
        waitpeq(CLKPIN, 1)
        outa[SHFTPIN] := {fourth bit to be shifted in}
        waitpeq(CLKPIN, 0)
        outa[SHFTPIN] := 0

Any help pointing me at the right code would be appreciated or if I am going about this all wrong knowing that would help too. The shift register I am using is [URL] http://www.nxp.com/documents/data_sheet/HEF4015B.pdf [/url]

Comments

  • CannibalRoboticsCannibalRobotics Posts: 535
    edited 2010-10-11 13:08
    Look at my object "74hc597 driver" in the obex (obex.parallax.com)
    It's a pretty good example of a set up for a clock and data shift sequence in SPIN.
    If you run a part number search for your interface chip - chances are not too bad someone has already written an object to run it. What is the chip?
    Welcome to Propellor World!
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-10-11 13:23
    The 4015 is a serial-to-parallel device so the waitpxx instructions will not help you -- the 4015 is a slave to you. This code will setup the pins you want and output the lower four bits of the value you pass:
    pub out4015(cpin, dpin, value)
    
      outa[cpin] := 0                                       ' make output low
      dira[cpin] := 1
      
      dira[dpin] := 1                                       ' make output
    
      repeat 4
        outa[dpin] := value & %1                            ' output lsb
        outa[cpin] := 1                                     ' clock the bit
        outa[cpin] := 0
        value >>= 1                                         ' get next bit
    
Sign In or Register to comment.