Elusive CONFIG3H Setting

For toy project of mine I wanted to test PIC18F13K50. Nice fast PIC, lot of RAM, some ROM and USB connectivity. All that while working on good old 5V.

First order of business was to set configuration bits. Code should be familiar to anyone who used XC8:
[c]
#pragma config HFOFST = OFF
#pragma config MCLRE = OFF
[/c]

Unfortunately that did not work. I could set all bits other than those in CONFIG3H. And thus I could not make MCLR pin behave as normal input. Since PCB was already done, I could not just opt to use other pin. I had to have it my way.

I also tried to use:
[c]
__CONFIG(_CONFIG3H, HFOFST_OFF & MCLRE_OFF);
[/c]

Hell, I even tried
[c]
__PROG_CONFIG(3, 0x00);
[/c]

Nothing worked.

And than I noticed a curious thing. This PIC has CONFIG2H register followed by CONFIG3H. There is no CONFIG3L. Could that be an issue?

On a hunch I went to edit 18f13k50.cfgdata (in C:\Program Files\Microchip\xc8\v1.01\dat\). There I added single line (highlighted) just before CONFIG3H declaration:

CWORD:300004:00:00:CONFIG3L
CWORD:300005:88:88:CONFIG3H
CSETTING:8:HFOFST:HFINTOSC Fast Start-up bit
CVALUE:8:ON:HFINTOSC starts clocking the CPU without waiting for the oscillator to stablize.
CVALUE:0:OFF:The system clock is held off until the HFINTOSC is stable.
CSETTING:80:MCLRE:MCLR Pin Enable bit
CVALUE:80:ON:MCLR pin enabled; RA3 input pin disabled
CVALUE:0:OFF:RA3 input pin enabled; MCLR disabled

With that simple change all was well and configuration bits were set.

And it works!

P.S. This workaround is valid for all other 18F family PICs that have CONFIG3L missing (e.g. PIC18F1220, PIC18F14K50...).

P.P.S. This should be solved in XC 1.10. Let's hope. :)

[2012-08-11: As of XC8 1.10 this issue is fixed.]

Leave a Reply

Your email address will not be published. Required fields are marked *