PIC10F322 XC8 Code – how to get a clock reference output on Port.A2
Reference Clock Output allows you to, basically turn the Port.A2 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 frequencies .
The output is based on the system clock (internal oscillator) divided by 4.
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
31 kHz (LFINTOSC)
Take those, divide by 4 and you get the reference output.
Below is a screen shot from the reference showing the wave form on Port.A2 running at 16Mhz – thus a 4Mhz 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 //16 MHz
//Prototypes
void setup (void);
void main(void)
{
setup();
while(1)
{
}
}
void setup (void)
{
OSCCONbits.IRCF = 0b111; //Set System Clock to 16Mhz FOSC 4Mhz
CLKRCONbits.CLKROE = 1; //Enable Clock Reference out on RA2
}
Have a Project or Idea!?
I am Available for Freelance Projects
My skills are always primed and ready for new opportunities to be put to work, and I am ever on the lookout to connect with individuals who share a similar mindset.
If you’re intrigued and wish to collaborate, connect, or simply indulge in a stimulating conversation, don’t hesitate! Drop me an email and let’s begin our journey. I eagerly anticipate our interaction!