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