PIC10F322 XC8 Code – to get a clock reference output on PortA.2

Reference Clock Output allows you to, basically turn the PortA.2 pin into a clock out device that you can use to drive other devices that require a clock input (think Z80 Clock input)

What is nice you can program different clock freqs.

The internal OSC can be set to the following frequencies.

16 MHz
8 MHz (default power on value)
4 MHz
2 MHz
1 MHz
500 kHz
250 kHz

Take those, divide by 4  and you get the reference output.

Below is a screen shot from the reference showing the wave form on PortA.2 running at 16Mhz – thus a 4Mhz output.

PIC10F322 XC8 Code - Clock Reference Output


#include <xc.h>
#include <stdint.h>

//Device Configuration
#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 16000000  //8 MHz (default after Reset)

void setup (void);

void main(void)

void setup (void)
    OSCCONbits.IRCF = 0b111;  //Set System Clock to 16Mhz FOSC 4Mhz
    CLKRCONbits.CLKROE = 1; //Enable Clock Reference out on RA.2

Something You Might Be Intrested In


10F32X Rapid Prototype Board

Make The PIC10F322 and other PIC10F Processors Breadboard Friendly for Quick and Easy Prototyping.

{Click to learn more}

PIC10F322 XC8 Code - Clock Reference Output