Setting SpecIal Function Registers in PIC18F26K20 and XC8 C

Find out how to setup your programmer's software and how to solve many common problems.

Moderator: phalanx

Post Reply
Posts: 161
Joined: Sat Dec 27, 2008 8:39 am

Setting SpecIal Function Registers in PIC18F26K20 and XC8 C

Post by treez » Wed Jun 14, 2017 1:30 pm

We are using a PIC18F26K20 in our simple DALI dimmable lamp.
Our software engineer used XC8 C in MPLAB X IDE.

His code does not have any mention of the ANSEL, ANSELH, INTCON or INTCON3 registers.
Is this allright?
We want RA1 and RA2 as analog inputs (ADC ). All the other pins we want as Digital I/O.
He also said he didn’t need to set the INTCON or INTCON3 registers because he wasn’t using them. (I thought you haD to disable interrupts in the INTCON register if you are not using them?…GIE=0;)

One of the PCBs is working and some work intermittently, most don’t work.

PIC18F26K20 Datasheet:- ... 41303G.pdf

User avatar
Non-SFE Guru
Posts: 1991
Joined: Sun Nov 30, 2003 8:57 am
Location: Candia, NH

Re: Setting SpecIal Function Registers in PIC18F26K20 and XC

Post by phalanx » Mon Jun 19, 2017 7:20 pm

ANSEL and ANSELH default to "1" on power-up which sets their associated pins as analog. You need to clear the ANSEL and ANSELH bits for the pins you want to be digital. To make that a touch more complicated, the configuration bit PBADEN in CONFIG3H can be used to make ANSELH default to either analog or digital. Make sure you are using it correctly.

INTCON, INTCON2, and INTCON3 by default are set to interrupts DISABLED so you do not need to modify their contents for regular operation.

As a note, the datasheet tells you the default register values after a power-up. Look at page 136 of the datasheet for ANSEL. The first table layout shows all the bits (ANS0 through ANS7) as being "R/W-1" The "R" means the bit is readable, the "W" means the bit is writable, and the "-1" means the bit is a "1" at power-up reset.


Post Reply