Change an I/O from in to out to in on the fly

Tyro

Member
I am trying to change an IO port from an input to an output and back again while running some code. I am obviously stupid because no matter what I try, I fail. How is it done?
 

jrlc

New Member
Like this?

Code:
main:
input B.1 ; make pin input
reverse B.1 ; make pin output
reverse B.1 ; make pin input
output B.1 ; make pin output
Example manual 2 page 142
 

westaust55

Moderator
Which Picaxe chip are you using

Can be done with most pins on 08M, the M2 and the X2 parts
Can be done with a few pins on the 14M
Cannot be done on other chips
 

inglewoodpete

Senior Member
Which Picaxe chip are you using

Can be done with most pins on 08M, the M2 and the X2 parts
Can be done with a few pins on the 14M
Cannot be done on other chips(?)
Don't forget that the 28X, 40X, 28X1 and 40X1 have bothway operation available on Port C.

Peter (back home from the cold)
 

westaust55

Moderator
Ah true Peter. :eek:

By way of further explanation for Tyro and other newcomers,
note that PortC on 28X/X1 pin chips is also the “normal” input pins upon which commands such as SERIN, READTEMP, etc will also function.

However, notwithstandaing some special functions such as i2c communications and PWM, using the PortC pins as outputs on 28 and 40 pin X and X1 chips, is limited to:
HIGH PortC <pin#>, and
LOW PortC <pin#>

As inputs on the 40X/X1 chips, the inputs are limited to testing in IF…THEN commands
IF PortC <pin#> ?? variable/constant THEN
where ?? is the basic tests (< = > etc)


Still that does not preclude careful bidirectional bit-bang type comms on those pins
 

retepsnikrep

Senior Member
I tried this with a bare 12F683 pic on which 08M is based and have it working driving a serial lcd display and acquiring adc keypad button data on the same pin ;)

A few things to bear in mind.

The 8N1 lcd serial output idles high so, you have to adjust your button potential divider so that the lowest voltage that it outputs is above the logic high level of around 4v or so and that it idles high with a pull up resistor of at least 100K on the buttons for when none are pressed. This limits the adc resolution but still works with 5 buttons for me. Also the impedance of your buttons must be at least 10k so that when it is being driven by the serial lcd data it doesnt affect it. You can't use an 0.1uf cap on the adc input as you would normally.

You have to switch the pin back and forth between input and output. In my program I only changed the pin to an output and disabled adc just before I sent serial data. I changed back again immediately afterwards to give time for it to settle before the next adc acquisition occured in my program.

Seems to work well. So I'm sure to can probably be done with an 08M ;)
 
Last edited:
Top