How to Set Configuration Bits easily in 16bit PIC Microcontroller.
Configurations bits are special bits to customize certain aspects of device you are using, based on application requirements. When microcontroller powers up these bits determines the modes that device uses. I have seen that many students face problems to deal with configurations bits so this article helps you to solve this critical issue. You should consider these bits, as a good microcontroller programming practice. I tried to solve this problem for PIC24 but same procedure is used for other PIC microcontrollers as well. I used MPLAB X IDE and C30 compiler. Let’s start with the smarter way to deal configuration bits in PIC24, DSPIC30 and DSPIC33. Following are the steps.
Now add a main file into this project and include the header file for the desired controller I am using PIC24F04KA201 I this case. Now right click on header file -> Navigate -> go to declaration or simple click on header file and use short key Ctrl + B.
A header file will open don’t make changes in this file. In this file you will find all registers for every peripheral that is present in this controller. To find configuration Bits you have to Scroll down now here you will find something interesting. How to write configuration bits on top of the source file syntax is also explained. I strongly recommend to read carefully about these bits by searching them in device datasheet before writing these in code this is shortcut method but once you read these you will quickly learn how much important they are.
Now let’s consider the first one I have to write in my code. As written that this is for “General Segment Code Flash Write Protection bit”. I don’t need code protection so I am selection this
_FGS(GWRP_OFF & GCP_OFF)
Now scroll down and find next. Now this is very important “Oscillator Select” this bit is used to select which clock is master clock for controller I used primary oscillator which is crystal so I go for
_FOSCSEL(FNOSC_PRI & IESO_OFF)
Likewise so on I go with this and finally I have these configuration bits written on top of my source file outside any function.
Now to check whether this setting is working or not. I have written a code for toggling PIN 0 of PortA.
and finally I have Proteus simulation.
Code download links will be provided soon !!!
that's all with a hope that this will help you.