Help for a beginner
SSkalko
Posts: 9
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.
The trouble I am having is find the right code to read and write individual bits of a byte size variable.
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]
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
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!