0
\$\begingroup\$

I am trying to start with PIC18 microcontrollers with a PIC18F14K50. I am using XC8 compiler and MPLABX IDE v1.2 and I have re-checked the selected device in the project configuration.

For now, I am trying to set the configuration words. I am aware of the file below which contains the information on the configuration words.

.../Microchip/xc8/v1.00/docs/pic18_chipinfo.html

When I set the MCLRE to OFF, thus trying to disable MCLR function and enable RA3 as digital input, it seems like it doesn't set it to OFF. It stays ON all the time.

I am testing this on "Labcenter Proteus ISIS v7.9 SP1" and "mikroProg Suite for PIC by mikroElektronika". Both say that MCLRE is ON, so I cannot change this bit. Also, I cannot change the HFOFST bit which is in the same register with MCLRE in CONFIG 3. However I can set up other configuration bits.

Below is my code. Can this be a bug?

#include <xc.h> // Include the header file needed by the compiler
// CONFIG 1
#pragma config CPUDIV = NOCLKDIV    // No CPU System Clock divide
#pragma config IESO = ON            // Oscillator Switchover mode enabled
#pragma config PLLEN = ON           // Oscillator multiplied by 4
#pragma config FOSC = HS            // HS oscillator
#pragma config FCMEN = ON           // Fail-Safe Clock Monitor enabled
#pragma config PCLKEN = ON          // Primary clock enabled
// CONFIG 2
#pragma config BOREN = ON           // Brown-out Reset enabled and controlled by software (SBOREN is enabled)
#pragma config BORV = 30            // Brown-out Reset Voltage set to 3.0 V nominal
#pragma config PWRTEN = ON          // Power-up Timer Enabled
#pragma config WDTPS = 1            // Watchdog Timer Postscale Select bits 1:1
#pragma config WDTEN = OFF          // WDT is controlled by SWDTEN bit of the WDTCON register
// CONFIG 3
#pragma config MCLRE = OFF          // RA3 input pin enabled; MCLR disabled
#pragma config HFOFST = OFF         // The system clock is held off until the HFINTOSC is stable.
// CONFIG 4
#pragma config DEBUG = OFF          // Background debugger disabled, RA0 and RA1 configured as general purpose I/O pins
#pragma config STVREN = ON          // Stack full/underflow will cause Reset
#pragma config XINST = OFF          // Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
#pragma config BBSIZ = OFF          // 1kW boot block size
#pragma config LVP = OFF            // Single-Supply ICSP disabled
// CONFIG 5
#pragma config CP0 = ON             // Block 0 code-protected
#pragma config CP1 = ON             // Block 1 code-protected
#pragma config CPD = OFF            // Data EEPROM not code-protected
#pragma config CPB = OFF            // Boot block not code-protected
// CONFIG 6
#pragma config WRT0 = OFF           // Block 0 not write-protected
#pragma config WRT1 = OFF           // Block 1 not write-protected
#pragma config WRTB = OFF           // Boot block not write-protected
#pragma config WRTC = OFF           // Configuration registers not write-protected
#pragma config WRTD = OFF           // Data EEPROM not write-protected
// CONFIG 7
#pragma config EBTR0 = OFF          // Block 0 not protected from table reads executed in other blocks
#pragma config EBTR1 = OFF          // Block 1 not protected from table reads executed in other blocks
#pragma config EBTRB = OFF          // Boot block not protected from table reads executed in other blocks

void main(void)
{
    TRISC = 0x20; // RC0: Out / RC1: Out / RC2: Out / RC3: Out / RC4: Out / RC5: In / RC6: Out / RC7: Out
    LATC = 0; // Clear PORTC output latch.
    ANSEL = 0; // All analog inputs are disabled and made digital.
    ANSELH = 0;

    while (1)
    {
    }
}
\$\endgroup\$
3
\$\begingroup\$

It is a bug in XC8.

As a workaround you can edit 18f14k50.cfgdata in C:\Program Files (x86)\Microchip\xc8\v1.01\dat\cfgdata\. Just above line with CWORD:300005:88:88:CONFIG3H add new line CWORD:300004:00:00:CONFIG3L.

Full post at http://www.jmedved.com/2012/08/elusive-config3h-setting/.

\$\endgroup\$
1
\$\begingroup\$

Check the binary config bits yourself without relying on someone else's interpretation of them to see if they are correct. If not, then you may have found a bug in a definitions file someplace.

However, it's more likely something else is going on, like you are in debug mode. The RealIce and other ICDs need to control MCLR, so you don't get to use it as a I/O pin when debugging that way. MPLAB usually overrides the necessary config bits for debugging when you select that kind of debugging.

 

\$\endgroup\$
  • \$\begingroup\$ I have selected the hardware tool as "Simulator". I cannot disable that selection. How do I check the binary config bits myself? Should I read the .hex file? \$\endgroup\$ – abdullah kahraman Jul 9 '12 at 12:45
  • \$\begingroup\$ Seems like I only have :020000040020DA and :020000040030CA in my hex file that starts with :02. \$\endgroup\$ – abdullah kahraman Jul 9 '12 at 12:51
  • \$\begingroup\$ @abdullah: I guess you mean you selected simulator as the debug tool. That should be fine in that it would not override any config bits with debug settings. However, to get anything other than logic low to drive the simulated MCLR pin, you have to use the stimulus feature of the simulator. To see the raw config bits, you should be able to examine the appropriate program memory in the simulator. \$\endgroup\$ – Olin Lathrop Jul 9 '12 at 15:51
  • \$\begingroup\$ "Configuration Words" view in MPLABX shows that MCLRE is ON. Apparently, it is not set correctly. I am really puzzled now. \$\endgroup\$ – abdullah kahraman Jul 9 '12 at 16:27
  • \$\begingroup\$ Also, the same window doesn't show CONFIG4H which includes DEBUG and STVREN. \$\endgroup\$ – abdullah kahraman Jul 9 '12 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.