I am new to Microcontroller programming and I thought maybe I should try blinking around 24 LEDs as a self project using PIC18F4550. I searched for a simple 1 LED blinking source code on net and what I am unable to understand are the following lines which are at the top of the code:-

#pragma config PLLDIV = 5 , CPUDIV = OSC1_PLL2 , USBDIV = 2    // You can write this way
// OR
#pragma config FOSC = INTOSCIO_EC
#pragma config FCMEN = OFF                                 // OR this way
#pragma config BORV = 3
#pragma config WDT = OFF
#pragma config CPB = OFF
#pragma config CPD = OFF

After this the author has used simple LAT statements which I am able to understand.

Can someone please explain the above codes and what each of them are doing or can point to some tutorial which explains (briefly) the use of following codes?

Note:- Just out of curiosity, these #pragma codes were used for 1 LED blinking, do I need to change them when using more than 1 LED?

Thank you.


Microchip PICs requires certain configuration settings to be defined before the microcontroller powers up. For example, the oscillator selection and whether code protection is enabled. These configuration settings are stored in a special place in memory and can only be altered during a programming sequence. Not during normal operation of the PIC.

Since these configuration settings are dealt with in a special way in memory, each compiler has it's own way of handling them. It is not standard C, so there is no universal syntax. It differs from compiler to compiler, but every compiler designed for PIC microcontrollers will provide some way to program the configuration settings. The only way to get the definitive syntax is to read the compiler's user's manual.

You can find all if the configuration settings for the specific PIC you're working on in the "Special Features" section of the datasheet. Every family of PICs have different settings, so the #pragma (or whatever your compiler uses) values are not usually portable from one PIC to another, even with the same compiler.

So in summary, you must first learn the proper syntax for your specific compiler to define configuration settings. And then you must read the Special Features section of the datasheet of the specific PIC you're using to find out which configuration settings are applicable.


'#pragma's are really not part of C (or C++) but rather extensions added by the compiler supplier, usually for some options or actions not covered by the language itself.

Your particular pragmas seem to originate with Microchip and they have a pdf on the net defining them for your circuit

Microchip defining pragma configuration settings

  • 1
    \$\begingroup\$ The link you provided is specific to C18, which I don't believe Microchip supports anymore. They now only support XC8 for 8bit devices. The information in that link may not be accurate if the OP is not using C18. \$\endgroup\$ – Dan Laks Mar 10 '15 at 8:57
  • \$\begingroup\$ Speaking of the older compilers, is it possible to find and use C32 instead of the newer XC32 compiler? I can't seem to find the download of the older C32 compiler anywhere on the Microchip website, but I have some older code I need to revamp. \$\endgroup\$ – Gabriel Staples Sep 20 '17 at 14:16
  • \$\begingroup\$ I found it! microchip.com/development-tools/downloads-archive. Search for the section called "MPLAB C Compiler for PIC32," then download the version you want--ex: "v2.02a upgrade". I don't know why it's called "upgrade," as it does contain the full version of the C32 compiler, but whatever. \$\endgroup\$ – Gabriel Staples Sep 20 '17 at 20:43

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.