Pic12F1840 how to change settings durin it run

An area to discuss 8-bit PIC specific problems and examples

Moderator: Benj

Post Reply
castabob
Posts: 25
Joined: Sun May 20, 2018 10:41 pm
Has thanked: 3 times
Been thanked: 1 time
Contact:

Pic12F1840 how to change settings durin it run

Post 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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Pic12F1840 how to change settings durin it run

Post 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.

castabob
Posts: 25
Joined: Sun May 20, 2018 10:41 pm
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: Pic12F1840 how to change settings durin it run

Post 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
Attachments
Error.pdf
(47.85 KiB) Downloaded 147 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Pic12F1840 how to change settings durin it run

Post 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.
Martin

castabob
Posts: 25
Joined: Sun May 20, 2018 10:41 pm
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: Pic12F1840 how to change settings durin it run

Post 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

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Pic12F1840 how to change settings durin it run

Post 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.
Martin

Post Reply