PIC18F45K22

Device Proliferation

3v3The PIC16F887A we surpassed by the PIC18F887, and these two devices were similar so code changes for compatibility were not so much of a problem. If you are a Mikroe User you may have noticed that when you open the examples folder, you would have noticed that the PIC16F887 was replaced by the PIC18F45K22. This device is pin out compatible, however when using the device I noticed there is a slight change when initialising the ports.

When using the PIC16F887, the following code would have been necessary to disable the PIC analogues so that PORTB could be used for digital.


ANSEL = 0x0;

ANSELH = 0x0;

PICs have this interesting habit that on reset, the PORTS default to a function other than digital. For example, on PORT A when the PORT is reset the ANALOG inputs are active and therefore digital inputs non –  functional. The result of this is that you would run into situations where if the alternate function is not disabled then the digital does not function.

Basically it’s the old adage of read the manual or datasheet in this case. If it’s not something you are expecting however, it can be quite frustrating and hair pulling since it’s not always obvious.

Bringing that back to the PIC18F45K22, the slight change is that to disable the analogue inputs your code would look like this

ANSELA = 0x0;

ANSELB = 0x0;

ANSELC = 0x0;

Yes, you called it the PIC18F45K22 has analogue inputs on PORTC as if there were not enough of them already.

Once the above change is made and the register configuration set then your device should work as expected i.e. the digital ports will be active.

For more information: www.microchip.com

[E]