PIC10F322 Configuration Bits for XC8

You've just written your first program for the and uploaded it to the chip, but nothing happens. The issue might be that you haven't set up the Device Configuration Bits correctly.

Proper configuration of these bits is essential for the microcontroller to function as intended.

Here is the configuration setup I typically use for the PIC10F322. Add this code at the top of your main.c file or include it in a header file, which you can then include in your main.c file. This will help you get your project up and running quickly.

Important Note on Processor Speed

Remember to set the _XTAL_FREQ macro to the speed of your processor. This is essential for the built-in delay macros to function correctly. For example, if your processor speed is 16MHz, you should define _XTAL_FREQ as follows: define _XTAL_FREQ 16000000

/*
 * File:  10F322_deviceconfig.h
 * Author: Jamie Starling - jamiestarling.com 
 *
 * Created on:  June 7, 2019, 9:45 PM
 * 
 * Copyright 2018 - 2019 Jamie Starling


THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED,INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

 * 
 * Purpose : Provides Standard Configuration for 10F32X devices
 * 
 */


#include 
#include 

#ifndef DEVICECONFIG_H
#define	DEVICECONFIG_H

#pragma config FOSC = INTOSC  // Oscillator Selection 
#pragma config BOREN = ON    // Brown-out Reset
#pragma config WDTE = OFF    // Watchdog Timer
#pragma config PWRTE = ON    // Power-up Timer
#pragma config MCLRE = OFF   // MCLR Pin Function Select bit->MCLR pin function is digital input, MCLR internally tied to VDD
#pragma config CP = OFF      // Code Protection 
#pragma config LVP = OFF     // Low-Voltage Programming 
#pragma config LPBOR = ON    // Brown-out Reset Selection bits
#pragma config BORV = LO    // Brown-out Reset Voltage Selection
#pragma config WRT = OFF    // Flash Memory Self-Write Protection


//Used to calculate the delay time - Change depending on processor Speed
#define _XTAL_FREQ 8000000  //8 MHz (default after Reset)


#endif	/* DEVICECONFIG_H */

By including this configuration at the beginning of your code, you ensure that the microcontroller is correctly set up, allowing your program to run as expected. Proper configuration of these bits is a fundamental step in PIC microcontroller , helping avoid common issues that can arise from incorrect settings.

Additional Tips and Best Practices

  • Configuration Bits Documentation: Always refer to the Microchip datasheet for the PIC10F322 to understand the function of each configuration bit in detail. This helps in customizing the settings to fit your specific application needs.
  • Consistency Across : If you are working on multiple projects or collaborating with others, maintaining a consistent configuration setup can help avoid confusion and errors.
  • Version Control: Keep a version-controlled repository of your configuration settings. This way, you can track changes and revert to previous settings if something goes wrong.
  • Testing Configurations: After setting up the configuration bits, test your microcontroller with a simple program to ensure everything is working as expected. This can save time and trouble when debugging more complex programs later.
  • Comment Your Code: Adding comments to your configuration bit settings can be extremely helpful, especially when revisiting the code after some time or when sharing it with colleagues.

Have a Project or Idea!?

Seeking Bespoke Technology Solutions?

jamie@jamiestarling.com


Pin It on Pinterest

Share This