PinRead() question for lcd busy flag routine
Capt. Quirk
Posts: 872
Pinwrite, pinh, pinl automatically handle the DIRx register,
but does PinRead() automatically switch an output pin into
an Input pin, and back to an Output pin?
For example, how does Spin2 handle reading a busy flag for
an HD44780 LCD?
BIll M.
but does PinRead() automatically switch an output pin into
an Input pin, and back to an Output pin?
For example, how does Spin2 handle reading a busy flag for
an HD44780 LCD?
BIll M.
check_busy_flag_v01.spin2 Snipet from Chris Gadds "Parallel LCD driver, 4-bit mode"
'' ========================= P1 to P2 conversion ======================================
PRI check_busy_flag() | busy
'' Partial completed P2 snipet
'' Pinwrite, pinh, pinl automatically handle the DIRx register,
'' but does PinRead() automatically switch an output pin into
'' an Input pin, and back to an Output pin?
'' For example, how does Spin2 handle reading a busy flag for
'' an HD44780 LCD?
'' ================== Partial completed P2 snipet ======================================
busy := 1
dira[D7]~
pinlow(rs) ' outa[RS]~
pinhigh(rw) ' outa[RW]~~
repeat while busy
pinhigh(e) ' outa[E]~~
busy := pinread(d7)'???? ' ina[D7] ' Check busy flag while E is high
pinlow(e) ' outa[E]~
clock()
dira[D7]~~
pinlow(rw) ' outa[RW]~
'' ========================= Original P1 snipet ======================================
PRI check_busy_flag | busy
busy := 1
dira[D7]~
outa[RS]~
outa[RW]~~
repeat while busy
outa[E]~~
busy := ina[D7] ' Check busy flag while E is high
outa[E]~
clock
dira[D7]~~
outa[RW]~


Comments
If you have downloaded PNut you can find the source code for the Spin2 interpreter in the examples. Here's is the code for pinread() -- you can see that it does not make any changes to the dirx register.
' PINR(pins) (7 longs) ' pinr_ testb x,#5 wc 'read ina or inb if_nc mov y,ina if_c mov y,inb ror y,x 'lsb-justify shr x,#6 'trim zerox y,x _ret_ mov x,y 'result in stack topNot that you asked, but here's how I would translate your check_busy_flag() routine.
pri check_busy_flag() | busy busy := 1 pinfloat(D7) pinlow(RS) pinhigh(RW) repeat while (busy) pinhigh(E) busy := pinread(D7) pinlow(E) clock() pinlow(RW) pinlow(D7)JonnyMac's Rule: NEVER user inx, outx, or dirx registers in Spin2 -- this creates portability problems even when the syntax is corrected from the P1.If that is true, why add pinfloat()?
Isn't this enough?
Bill M.
'' Revised Ck BF busy := 1 pinlow(rs) pinhigh(rw) repeat while busy pinhigh(e) busy := pinread(D7) pinlow(e) clock() pinlow(rw)Looking through my library I found that I had written an LCD object that could read from the display. I translated it to P2. Want to give it a try?
Changing the pin direction would disable these pullups/downs giving unpredicatble input states.
Another reason to keep the direction bit high is to maintain smartpin mode for status updates.