Page 1 of 1

Pic12F1840 how to change settings durin it run

Posted: Fri Jun 05, 2020 10:55 am
by castabob
Hello Martin,
I ask you for help with an operation that I don't know how to perform.
I am using the PIC12f1840 because I need few I / O and a serial line. The program starts with an initial setting of pins 6 and 7 such as RX and TX and after acquiring some data from a PC (via rs232) I need to set (at this point in the program) these 2 ports as analog inputs (the hardware is ready to do so).
To set the various functions of the chip I use the "2D: Dashboard Panel" and I don't think I can set the functions of pins 7 and 8 both for the rs232 and as analog inputs whose functions I would then call in the program after having finished the work with the rs232.
I would be very grateful if you could give me a suggestion (assuming that what I need it can be done)

Regards
castabob

Re: Pic12F1840 how to change settings durin it run

Posted: Fri Jun 05, 2020 3:36 pm
by Benj
Hello,

If you call the following code in a C icon after you are finished with the UART then this should disable the UART and put the pins back into the standard IO mode where you can use them as ADC inputs or general purpose IO.

Code: Select all

TXSTA = 0;
RCSTA = 0;
If you want the UART functionality again after this simply call the initialise function again.

Re: Pic12F1840 how to change settings durin it run

Posted: Thu Jun 11, 2020 11:46 am
by castabob
Hi,
sorry if I haven't answered before but I had to fix other little things to run the program correctly. After the indication you gave me, everything is working properly now.
I have another problem where the compiler gives me an error (attached file) . Where am I wrong? How can I solve it?
Yours sincerely
castabob

Re: Pic12F1840 how to change settings durin it run

Posted: Thu Jun 11, 2020 4:48 pm
by medelec35
Hi Bob,
Can you try

Code: Select all

TRISAbits.TRISA5 = 0;
Alternatively you can just have an output and set it to 1 or 0 at the required time.

Re: Pic12F1840 how to change settings durin it run

Posted: Thu Jun 11, 2020 5:27 pm
by castabob
Hi,

as you suggest to me "TRISAbits.TRISA5 = 0;" the compilation do not give error.
Before I had tried only writting the instruction: "TRISA5 = 0;" and even so it didn't give me an error ... is it correct even just so?


thank you very much
Regards
bob

Re: Pic12F1840 how to change settings durin it run

Posted: Thu Jun 11, 2020 6:05 pm
by medelec35
Hi Bob,
your're welcome.
castabob wrote:Before I had tried only writting the instruction: "TRISA5 = 0;" and even so it didn't give me an error ... is it correct even just so?
That should work equally well.
what I would do is after

Code: Select all

TRISA5 = 0;
, is just confirm by connecting a 1Kto 10K resistor from the A5 pin to VDD.
If voltage is 0V then it's worked.
If around VDD, then has not worked.
I believe it will work and should not be an issue.