-1

How to configure the analog port of PIC18F452 to read analog values? They need to change their status while running the program.

Anindo Ghosh
  • 50,188
  • 8
  • 103
  • 200
Codenamed SC
  • 471
  • 3
  • 6
  • 12
  • 1
    Related question: http://electronics.stackexchange.com/questions/31221/pic18f4520-adc-conversion-in-mc18 – m.Alin Jul 24 '12 at 10:44
  • 2
    Is it a **must** that I should change the ADCON registers every time I'm going to use PORTA?? (even as digital pins). Because I found weird things happen otherwise. (not sure this is the exact reason..) – Codenamed SC Sep 11 '12 at 04:03
  • 1
    @CodenamedSC Nope. You have to configure only if you are hoping to use it as analog.. – Anubis Sep 11 '12 at 04:05
  • 1
    @CodenamedSC you should have included the above comment in the post itself. Then you won't get down voted.. – Anubis Sep 12 '12 at 14:22
  • 1
    @Anubis thanks for the tip. I'm new to the forum. Don't know traditions.. :D – Codenamed SC Sep 12 '12 at 14:24

2 Answers2

1

The PCFG bits of ADCON1 control the mode of the I/O lines. You can change these at any time.

enter image description here

You also need to keep track of your LATA and TRISA registers (I would make sure TRISA isn't an output if you want analog input...)

enter image description here

Adam Lawrence
  • 32,921
  • 3
  • 58
  • 110
0

Check the PIC18F452 datasheet (google it). It will say how to set ADCON0 and ADCON1 registers in order to set portA pins to work as either digital or analog..

Anubis
  • 1,490
  • 3
  • 20
  • 32
  • 1
    More of a comment than an answer, however true. – kenny Jul 24 '12 at 11:06
  • 4
    ADCON0 has nothing to do with configuring ports as analog versus digital, and ADCON1 is only part of the answer. I'd elaborate, but the OP has already jumped on this first (and incorrect) answer, so my time is better spent elsewhere. – Olin Lathrop Jul 24 '12 at 13:05
  • 2
    @OlinLathrop if you can provide a better answer, please post. I'll accept it..That is something allowed, isn't it? – Codenamed SC Sep 11 '12 at 04:20
  • 1
    @OlinLathrop of course. No worries.. – Anubis Sep 11 '12 at 04:23
  • 2
    @CodenamedSC: If you agree with Olin Lathrop that the answer is not correct you can unaccept it. This may invite others to post an answer (like Olin). – Johan.A Aug 12 '13 at 09:18