kranenborg
Senior Member
[size=+2]Converting 18X output pins to logical inputs[/size]
The following code shows how on the highly configurable PICAXE-18X any of the output pins can be converted to input pins, by poking the "shadow TRISB" register with 1 bits on appropriate locations. Note that the credits for this extension and several others are for hippy.
The possibility to make inputs on PORTB opens a large number of possibilities due to the flexibility of this port, as shown by posts in this thread
The example code shows how Output 6 and Output 7 are converted to logical inputs, and subsequently their state is read continuously from the PORTB data register
The following code shows how on the highly configurable PICAXE-18X any of the output pins can be converted to input pins, by poking the "shadow TRISB" register with 1 bits on appropriate locations. Note that the credits for this extension and several others are for hippy.
The possibility to make inputs on PORTB opens a large number of possibilities due to the flexibility of this port, as shown by posts in this thread
The example code shows how Output 6 and Output 7 are converted to logical inputs, and subsequently their state is read continuously from the PORTB data register
Code:
REM Example program
REM Shows how OUT6 and OUT7 on a PICAXE 18X are converted into inputs
REM (any output can be made input).
SYMBOL IO_Direction = b0
SYMBOL Shadow_TRISB = $AE
SYMBOL PORT_B = $06
REM First convert OUT6 and OUT7 into inputs (and leave the state of the others as they were)
REM using hippy's "shadow" TRISB register
PEEK Shadow_TRISB,IO_Direction
LET IO_Direction = IO_Direction OR %11000000 REM Set appropriate bits
POKE Shadow_TRISB,IO_Direction
DO
PEEK PORT_B,b0 REM Read inputs from PORTB data register
REM Show PORTB register contents
SERTXD("PORTB register contents: ", #b0,13,10)
PAUSE 1000
LOOP
Last edited: