reading output pins

rjandsam

Member
i need advidice on how i would go about reading a snapshot of a picaxe 28x2 output pins status and then decoding that information into a readable format to output on an lcd for eg: output 1 is on or output 1 and 7 is on and output 0 2 3 4 5 6 are off how difficult would this be? and do you have any examples of code.
Thanks in advance.
Rich.
 

MartinM57

Moderator
Seeing that your program is in control of the output pins, why would you want to read them?

Anyway, this simulates just fine
Code:
#picaxe 28x2
dirsB = 0xFF

outpinsB = 0xAA

b1=outpinsB ;b1 now contains 0xAA

Do : Loop
Do you know how to write things to a LCD in general. If so, you can (just!) write the b1 value from above to the LCD as text 1's and 0's depending on the bits set in b1
e.g. b1 contains 0xAB, display would show "10101011"
 

Janne

Senior Member
You can use the "OUTPINS" to get the status of the outputs. That way you can save using one register, as you don't need to store the state of the outputs.

Knowing the status of the outputs is useful, for example if you need to bitwise OR a couple of outputs on at the same time. Those programming in C are propably all to familiar with OR:ing on the bits on a port.

To display the the status on the LCD, assuming you want to display it in "binary", as in one marker for each output.. You need to make a (for) loop that processes each bit individually, and then sends the corresponding on / off character to the LCD display as required.
 

hippy

Ex-Staff (retired)
A very handy trick for displaying a binary byte value is ...

b0 = ?
SerTxd( #bit7, #bit6, #bit5, #bit4, #bit3, #bit2, #bit1, #bit0 )

With b1 and bit15-bit8 it's easy to get at a 16-bit MSB value ( and b3/b2, bit31-bit16 can handle 32-bits on later PICAXE ), and of course one can move any other byte variable into b0 etc.
 

westaust55

Moderator
From manual 2 (V7.1) page which covers the READOUTPUTS command:

This command (READOUTPUTS) is not normally used with M2, X1 or X2 parts as the outputs can be read directly with ‘let var = outpinsX’

While not related tot he original question which is for the 28X2,
I believe that with some earlier PIC/PICAXE chips there can be a problem reading the outputs by using outpins on the right side as the registers may not always be updated hence use the READOUTPUTS is likely still the preferred way for non X1/X2/M2 parts
 

rjandsam

Member
Thanks for all of the great advice guys, i now have it doing what i set out to do. the reason i needed to know the output states is that it is controlling lighting and without me having to go and see if the lights are physically on i can simply press a button downstairs that uses another picaxe over serial to get the values and then show me on an lcd which lights are on. this then allows me to turn them off if i know that nobody is up there.

Once again Thanks

Rich
 
Top