Isolating Two Circuit Functions That Use The Same Output Pin

Thread Starter

threesheetsal

Joined Jul 19, 2019
3
I'm using a PIC MCU that, among other things, will be used to drive 2 LEDS through an 8-pin header. However, at certain times, I'd like the option to use the same 2 pins as serial I/O paths.

I'm looking for some guidance as to how one can isolate the LED and Serial signals so that they do not interfere with the other when one is in use.

More specifically, in the image I've attached, I want to connect the Serial I/Os (PIN 9 and 10 from PIC) to Pins 2 and 4 of J2. Outputs OZONE and AIRFLOW (PIN 6 and 7 from PIC) are also connected to Pins 2 and 4 of J2 to drive two LEDs under normal conditions. Through circuitry not shown, when I change the mode of the PIC for Serial I/O functionality, I want Pins 2 and 4 of J2 to ONLY exchange data to and from the Serial pins of the PIC. Otherwise, Pins 2 and 4 of J2 ONLY receive the signal from Pin 6 and 7 of PIC to drive the LEDsPIC_ckt.PNG
 

Picbuster

Joined Dec 2, 2013
1,047
Do you want to use pic'c serial pins for digital input or output and at an other moment for serial communication?
If so no problem.
you may change the tris register on the fly however you have to make sure that your software does the selection.

Hardware need a extra pin allowing to disable serial driver and enable digital i/o. ( assuming that you do not swap the digital inputs to outputs and one pin is always input when selected)

Picbuster
 

t1d

Joined Aug 17, 2019
8
Hi, Picbuster,
I have researched changing pin functions on the fly on PIC MCUs and I only found information that said it could not be done... 12F and 18F series... If you know how to do it, please provide a link to the instructions. Thanks. t1d
 

jpanhalt

Joined Jan 18, 2008
11,087
@t1d
Welcome to AAC

Changing TRIS from input (high impedance) to output (low impedance) most certainly can be done on those chips. There are some precautions to observe, and even though they are not always followed, the program may still work.

Please give a link to where you learned that TRIS cannot be changed "on the fly." It is like any other R/W register. Here's an example for TRISA on a 16F1829:
upload_2019-8-18_5-30-0.png
TRISA3 = MCLR and is input only.
 

t1d

Joined Aug 17, 2019
8
It has been over a year since I looked for that. I would have very likely asked at the Microchip forum and EEVBlog. I don't even remember what the project was, but I couldn't get that trick to work. I didn't keep any links. Maybe it is only available in some series?
 

jpanhalt

Joined Jan 18, 2008
11,087
I have seen both good and bad advice regarding PIC's on EEVBlog. I think you need to rely on Microchip as members of those forums (including occasionally Microchip techs) will chime in if things get really off kilter. There have also been discussions here:
https://forum.allaboutcircuits.com/threads/pic16f877a.96179/


For chips with which I am familiar (10F thru 16F), one problem with manipulating TRIS during fast changes is that it is, like ports, susceptible to RMW error. That issue is addressed in most of the datasheets.

There are many discussions of that on Microchip's forum too. Here is just one example: https://www.microchip.com/forums/m1064930.aspx
 

t1d

Joined Aug 17, 2019
8
This is a 2018 post where I wanted to get a PIC12F683 to change the MCLR pin to GPIO.
https://www.microchip.com/forums/m1046265.aspx
qyb @ Post #2
"No can do.
The config setting cannot be changed on the fly."

I don't take everything said on the web as gospel, so I did research this out further. AIR, I found lots of information about it not working. And, where it was said to work, no code was given.

I have not read your suggested links, yet, because today has its health challenges. I will get to it, when my mental facilities improve.

I sure would appreciate you writing a bit of C code that will do this on a PIC12F683. I am very much a C code novice. Not all the configuration settings, of course... just the toggle code... Well, I guess some configs will be needed, even for this limited test... Maybe something I could breadboard, like blinking LEDs.

Thanks for your help. This subject is very interesting!
 

jpanhalt

Joined Jan 18, 2008
11,087
t1d said:
This is a 2018 post where I wanted to get a PIC12F683 to change the MCLR pin to GPIO.
You don't need to read any links. C code won't help you. Please re-read post #4. MCLR is input only. Therefore, TRIS for that pin is not writeable. You may try to write to it, but there will be no change. TRUST THE DATASHEET.
 

t1d

Joined Aug 17, 2019
8
You don't need to read any links. C code won't help you. Please re-read post #4. MCLR is input only. Therefore, TRIS for that pin is not writeable. You may try to write to it, but there will be no change. TRUST THE DATASHEET.
At the time, I had studied the DS rather well, IMHO. I was/am aware that the MCLR cannot be written to.

This will show my lack of understanding, I guess/hope... Are you saying that the GPIO function that is on the MCLR pin cannot be written to, as well as the MCLR function cannot be written to? In other words this particular GPxx pin is GPI only? I will give the DS another look, given this new (for me) consideration.

I note your use of bold letters. If I have irked you, somehow, please forgive me. I am not arguing your position, I'm just trying to understand. I do appreciate your help.
 

jpanhalt

Joined Jan 18, 2008
11,087
The TS has not been back in awhile. This tangent about changing TRIS began at post #3, and I believe the confusion between changing TRIS for an input only pin (e.g., MCLR pin) versus an I/O pin has been resolved.

@t1d
If you have specific questions about how to use an input pin for input, perhaps a new thread should be started. In the instance of your 12F683, you need to declare that MCLR will be used as an input, not as a reset. That is, set MCLR off in the configuration word (i.e., bit5 = 0). That setting does not prevent it from being used to program the chip. If you do not inactivate the MCLR/Reset function, a logical low input will cause a reset.

MCLR's function is described and footnoted at many places throughout the datasheet. For the 12F683, I suggest you go to Register 12-1 in Section 12.0:

upload_2019-8-19_5-26-49.png
 
Top