Reading a port
Curtis Brooks
Posts: 38
Is there a way to read the current state of an entire port?
For instance, if I have some of the port pins high and some low is there a way to read the state of the port into a variable?
For instance, if I have some of the port pins high and some low is there a way to read the state of the port into a variable?
Comments
first check port direction from DIRx (x is port name) and seperated case by
if DIRx = 0, current port is defined as input, check input on INx
if DIRx = 1, current port is defined as ouput, check current output state on OUTx
setportA VAR OUTA
setportB VAR OUTB
setportA = %1111
setportB = %0000
DEBUG setportA
DEBUG setportB
END
Will debug display the current state of the port this way?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
setportA VAR OUTA
setportB VAR OUTB
setportA = %1111
setportB = %0000
' I'd added modifier to show on debug term as two lines 4 binary digits format.
DEBUG BIN4 setportA,CR
DEBUG BIN4 setportB
END
To READ the state of a port, you have to set the port as an INPUT (PIC and BS2 gotcha).
So:
ReadPortA VAR INA ' Create alias
ReadPortB VAR INB ' Create another alias
MyVal VAR BYTE
INPUT PORTA ' Set PortA bits as INPUT. See also the 'DIRA' variable.
MAIN:
MyVal = ReadPortA
DEBUG BIN8 MyVal, CR
PAUSE (100) ' 100 mSec, so we're not FLOODED with data...
GOTO MAIN