View Full Version : From 4021 to 4094? - Solved

03-25-2009, 03:39 AM
OK so I dealt with the changing pinstate based on individual bits in a variable by bitwise shifting by (1*whatever bit# I wanted to know about in the variable), then seeing if the result was >=128 and making my decision based on that.



I've made progress with the 4094 output function, I found this PBASIC code for the 4094 and it helped me understand the order in which the clock/strobe/data etc gets pulsed:

SYMBOL Strobe = 0
SYMBOL Data = Pin1
SYMBOL Clock = 2
SYMBOL outByte = B0
SYMBOL outbit = Bit7 ' high bit of outByte
SYMBOL shift = B2
' other code here...
FOR shift = 1 TO 8
Data = outBit ' make bit available
PULSOUT Clock, 1 ' clock the bit
OutByte = outByte * 2 ' shift bits left
NEXT shift
PULSOUT Strobe, 1 ' data -> outputs


And so now I have some code that sends info to the 4094 accurately, I'm just not sure how to make the pin High or Low via a variable:

outa[DATA]~~ = High on DATA pin
outa[DATA]~ = Low on DATA pin

But where is the DataPinState := LSB[MyVar]??

Do I have to use IF statements?

I appreciate peoples help,



I'm working on a project that needs more inputs/outputs than the prop has.
I'm using 4021s for inputs and 4094s for outputs..well almost.

I modified the NES object in the obex since it made use of 4021s, its working great.

I'm not sure how to flip this around for a 4094 for my outputs, any help would be appreciated.

long latch, data, clk, type, bits
PUB Init(l, d, c) | tmp
{{ Initializes pin assignments and sets intial directions and pin values
l -- latch pin, orange wire
d -- data pin, red wire
c -- clock pin, yellow wire
latch := l
data := d
clk := c
bits := 16 ' get all bits for init
dira[LATCH]~~ ' LATCH to output
dira[CLK]~~ ' CLK to output
dira[DATA]~ ' Data to input
outa[LATCH]~~ ' high LATCH
tmp := inputs
PUB inputs : btns | InBit

outa[LATCH]~ ' low LATCH
outa[CLK]~ ' Set clock low
REPEAT bits ' for number of bits
InBit:= ina[DATA] ' get bit value
btns := (btns >> 1) + (InBit << (bits-1)) ' Add to value shifted by position
!outa[CLK] ' cycle clock
waitcnt(500 + cnt) ' time delay
outa[LATCH]~~ ' high LATCH



Post Edited (CassLan) : 3/24/2009 11:04:07 PM GMT