Simplifying Your PIC10F322 Projects with a Standard Header File

To streamline your , it's helpful to define a standard header file. This file can be reused across multiple projects, saving time and ensuring consistency.

Creating the Header File

  1. Name the File:
    • Name the header file 10F322_deviceconfig.h.
    • Place this file in your project directory.
  2. Include the Header File in Your Project:
    • Add the header file to your XC8 project.
    • Include it in your source files with the following line:
#include "10F322_deviceconfig.h"

Contents of the Header File

The header file should contain the device configuration setup, standard headers, and other important definitions. Here's a sample content for 10F322_deviceconfig.h:

/*
 * 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 standard headers
#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


#define ON  1
#define OFF 0
#define TRUE 1
#define FALSE 0
#define HIGH 1
#define LOW 0


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


#endif	/* DEVICECONFIG_H */

Benefits of Using a Standard Header File

  • Consistency: Ensures consistent configuration across all your projects.
  • Efficiency: Saves time by avoiding repetitive setup for each new project.
  • Maintainability: Easier to update configuration settings or constants in one place.

How to Use the Header File in Your Project

Include the Header File: Add the following line to the top of your main source file:

    #include "10F322_deviceconfig.h"

    Use the Defined Constants and Configurations: Now, you can use the defined constants and configuration settings in your code. For example, you can directly use _XTAL_FREQ, TRUE, FALSE, ON, and OFF in your program logic.

      Example Usage in a Source File

      Here's an example of a simple program using the standard header file:

      #include "10F322_deviceconfig.h"
      
      void main(void) {
          // Initialize Port A
          ANSELA = 0x00;  // Disable analog function on all pins
          TRISA = 0x00;   // Set all Port A pins as outputs
      
          while(1) {
              LATAbits.LATA0 = ON;  // Set RA0 high
              __delay_ms(500);      // Delay 500 ms
              LATAbits.LATA0 = OFF; // Set RA0 low
              __delay_ms(500);      // Delay 500 ms
          }
      }
      

      By following these steps and using a standard header file, you can make your PIC10F322 projects more efficient, consistent, and easier to manage.


      Have a Project or Idea!?

      Seeking Bespoke Technology Solutions?

      jamie@jamiestarling.com


      Pin It on Pinterest

      Share This