PDA

View Full Version : PortA Doesn't Work


Melanie
- 15th July 2004, 12:55
PortA Doesn't Work
Parts of PortE do not work
I can't transfer my program from a PICF84 to a PICF628


PortA Doesn't Work

Oh yes it does. It might need to be switched ON for Digital use though.

Whilst you weren't looking, Microchip have been busy stuffing the PICs full of goodies. Some of these goodies are ANALOG interface parts. A/D Convertors (eg 16F876) or Comparators (eg 16F628), or even BOTH (eg 16F877A and 12F675). Mostly (but not always), the Analog hardware is multiplexed with PortA (and PortE).

By default, on many PICs which have these Analog parts, when the PIC powers up, it defaults into Analog mode (the controlling Registers are usually set to zero) – which is why you can't do Digital I/O until you set that port into Digital mode.


If your PIC has Comparators…

Then the Comparators are most likely controlled by the CMCON Register. This is most common thing that is overlooked by people transferring programs over from one PIC to another (for example from a 16F84 to a 16F628).

CMCON=%00000111

Will normally switch the Analogue Comparator pins to Digital I/O mode. (CMCON=$07 or CMCON=7 will do the same thing). Go check with your PICs Datasheet to see what setting the CMCON Register to this value does.


If your PIC has A/D Convertors then…

The A/D Convertors are controlled usually by the ADCON1 Register (again check with your PICs datasheet – eg it’s ANSEL with the 12F series).

ADCON1=%00000111

Will normally switch the Analogue A/D pins to Digital I/O mode. (ADCON1=$07 or ADCON1=7 will do the same thing). Go check with your PICs Datasheet to see what setting the ADCON1 Register to this value does.


If your PIC has BOTH A/D Convertors and Comparators…

The you’ll need to set both ADCON1 and CMCON appropriately.

Example 1 - if you have a 12F like a 12F675, then

ANSEL=%00000000
CMCON=%00000111

Is the sequence for you.

Example 2 - if you have a 16F628 then all you need is...

CMCON=%00000111

Example 3 - if you have a 16F876 or 16F877 then this one is for you...

ADCON1=%00000111


ALWAYS check the correct Register settings for your own needs, by looking in the Comparator Section, and/or the A/D Converter Section in your PICs Datasheet.

Melanie

mister_e
- 12th April 2008, 21:25
Maybe some may also download the following PDF and keep it handy somewhere in their PC.

Common 8-Bit PIC® Microcontroller I/O Pin Issues (TB3009)
http://ww1.microchip.com/downloads/en/AppNotes/93009A.pdf

RussMartin
- 17th April 2008, 18:03
Maybe some may also download the following PDF and keep it handy somewhere in their PC.

Common 8-Bit PIC® Microcontroller I/O Pin Issues (TB3009)
http://ww1.microchip.com/downloads/en/AppNotes/93009A.pdf

I've not only downloaded and printed TB3009, I've attached Melanie's post to it!

Thanks to both of you!

bluestar84
- 29th January 2010, 13:29
and for 18f4620 it`s ADCON=00001111 isnt it? do you do that right after tris initialsation or after?

mackrackit
- 29th January 2010, 13:39
I do not have the data sheet with me but if you have the correct register and all it should be
ADCON=%00001111

rmteo
- 29th January 2010, 16:31
and for 18f4620 it`s ADCON=00001111 isnt it? do you do that right after tris initialsation or after?

From the data sheet:
19.0 10-BIT ANALOG-TO-DIGITAL CONVERTER (A/D) MODULE

The Analog-to-Digital (A/D) converter module has
10 inputs for the 28-pin devices and 13 for the 40/44-pin
devices. This module allows conversion of an analog
input signal to a corresponding 10-bit digital number.
The module has five registers:
• A/D Result High Register (ADRESH)
• A/D Result Low Register (ADRESL)
• A/D Control Register 0 (ADCON0)
• A/D Control Register 1 (ADCON1)
• A/D Control Register 2 (ADCON2)