Teething – PIC16F1827



If you have been keeping up to date on the new F1 devices, you may have been eagerly anticipating their delivery – mine stayed in their packaging for a while until now. These new devices have a great deal more to offer at a much lower cost, along with some interesting features. For example, some of these devices have a Digital To Analog converter on board – wow! Not sure yet how I will use that but it’s availability is very much intriguing.

So, I decided to pop one of these little guys into a development board just to see how they go. Some rules apply, read the data sheet, but other than that my Mikroe C Compiler 5.8 was quite capable of producing the simple HEX file required.

If you cast your memory a short while back, you may recall that when the PIC16F887 came onto the market, they introduced Analog Inputs located on PORT B. This is awesome since now we have so many more inputs, but it also means that a few of us were stumped for a while because 1) The PIC PORT always defaults to a feature other than the digital I/O. 2) To use the digital inputs, this requires that the ANSEL register be configured to switch the analog inputs be switched off.

With the PIC16F887 there were two registers ANSEL and ANSELH, these had to be set to 0. For the PIC16F1827, it’s far more intuitive and easier as ANSELB for PORTB, which also must simply be set to 0. Note that writing 0x00 to the register disables the analog inputs for the entire port.

If there were a combination of Analog Inputs and Digital inputs, the individual bits would need to be considered and configured to setup the device. Standard approach as per usual for a PIC.

The code sample is very simple and all it does is to configure the device and toggle the PINS on PORTB. The interest here is that unless ANSELB is cleared, PORTB is unusable for digital IO, and they won’t work until this is done.

Copyright (c)2012, ZarDynamix
PIC16F1827 - Simple Flashing LED demonstration

void main() {

TRISB = 0x0;                        // Configure TRISB for output
ANSELB  = 0;                        // Configure AN pins as digital I/O

C1ON_bit = 0;                      // Disable comparators
C2ON_bit = 0;

          PORTB = 0xff;            // All outputs on
          Delay_ms(500);           // wait 1/2 second 
          PORTB = 0x00;            // All outputs off
          Delay_ms(500);           // wait 1/2 second


The PIC16F1xx series of devices is the latest from Microchip and the family of devices is growing at quite a considerable rate. These devices would probably at some point be as popular as devices found in most on line projects.

The above code would be best run on a ProtoDev 18, which is PIN compatible with the PIC16F1827.