Control of Trisate pins on a 14M

Andrew Cowan

Senior Member
I'm trying to bit-bang I2C on a 14M (with much help from hippy).

His code (designed for the 08M) uses plenty of 'Input pin' commands to set the pin to high impedance.

However, I'm using the 14M, which doesn't support the Input command. Is there anyway of controlling the state of one pin, rather than using Dirsc to do the whole portc bank? At times I don't know what the state of other pins will be, ie I need let Dirsc = %xxxx0xxx where x is don't care.

Thanks,

Andrew
 

Andrew Cowan

Senior Member
Looking at the PIC684 register, it looks like I need to control register 4-7, but only changing one bit at a time. As far as I know, poking only affects bytes, which would indicate this isn't possible...

Andrew
 

BeanieBots

Moderator
If you can access the register with poke, then surely you can peek as well?
In which case, peek, mask then poke should do the job.
 

hippy

Technical Support
Staff member
There's no way I know except using 'dirsC=".

What you can do, rather than soft-drive SDA and SCL, is to hard-drive them so they are always set high or low and use a bit of trickery to allow a fixed output and a separate input for SDA out and in. This is how bit-banged I2C is usually implemented on PICAXE with non bi-directional I/O. Uses an extra I/O pin but is easiest -

SCL output pin : Output to diode cathode, anode to SCL line, pull-up
SDA output pin : Output to diode cathode, anode to SDA line, pull-up
SDA input pin : Input straight from the SDA line

It is often possible to wire SCL output straight to SCL line and lose the pull-up. Depends what I2C devices you connect to.

To change the code "LOW <pin>" stays the same, "INPUT <pin>" becomes "HIGH <pin>". When reading I2C SDA line in, keep the SDA output pin high.

Added : The peek / poke probably won't work as the firmware will likely update the TRIS registers. Could give it a try though.
 
Last edited:
Top