This post will provide a tutorial of how to set configuration bits in code for PIC16F877 an 8 bit microcontroller from microchip. Configuration bits are special features registers in CPU described in section “14 named Special features of the CPU” in datasheet of PIC16F877. This method also works for all PICs. Code is written in C language and I used the latest compiler XC8 with MPLABX IDE.
In this post I assumed that you must know following if not then please read them before proceeding further "How to use MPLAB X IDE".
You may download code, schematic and Proteus simulation from the download section at the bottom of this page. I am using MPLAB X IDE, XC8 Compiler.
Setting configuration bits allows you to start microcontroller from very basic level. So here is a shortcut. But you must know what these register means by reading the section 14 of datasheet. When you done with the code use following to set configuration bits easily. Go to windows->PIC memory Views->Configurations Bits. As shown in figure 1.
|Figure 1. Windows|
Click on it a new tab will open in this window named Configuration Bits. As shown in figure 2. Now this tab will help you to graphical configure the Configuration bits for PIC microcontroller. Configure crystal for external. Watch dog OFF. Because you have to clear it in you while loop if you set in ON otherwise controller will reset after some time depending on how much time you set. Brown out reset ON. Power up timer OFF.
Now once you set all the configuration bits by using datasheet also click on the Generate Source Code to Output. Remember using this doesn’t means you have done all configuration bits setting. You must have to code these bits in code.
|Figure 2. Configuration bits|
Now a new Output tab is opened. As shown in figure 3. You have all the code for setting configuration bits just copy them and paste it below the #includes and above your main code. As shown in figure 5.
|Figure 3. Output.|
I used PIC16F877 with PIN RA0 connected to LED. MCLR is connected to 5VDC which means it is in working state. Proteus simulation shows that LED is toggling after some time. Which is general delay between setting and clearing the PIN. I used XC8 the latest compiler form microchip you may download it from Microchip site. Figure 1 shows an animation of how this LED is toggling. Means configuration bits are set for the normal use. (for beginners )
|Figure 4. Simulation.|
This is main code file showing the configuration bits area and the main function in which I toggle PIN RA0 after some general time delay. As shown in figure 5.
|Figure 5. Code.|
|Figure 6. Complete Circuit.|
You can download Code which is written in C language. Using MPLAB X IDE and compiler xc8 for 8 bit Microcontrollers.
- Over Voltage Protection
- Step by step home made PCB tutorial
- How to measure Negative and Positivetemperature using LM35
- AC Voltmeter RMS + Peak voltage
For all topics Click here
All the text and graphics contained on this page belongs to owner except otherwise mentioned. Other parties' trademarks and service marks that may be referred to herein are the property of their respective owners. Reproducing or distributing text and graphics on your own site is strictly not allowed without proper linking to original content and before publishing that you should ask for permission.
© Copyright 2014 IbrahimLabs. All rights reserved.