PIC10F322 Applications – Basic Monostable Circuit

A PIC10F322 as a 555 timer replacement – why not. I always pulled my hair out when working with most 555 timer circuits.  Resistors, capacitors figuring out the values you need, etc, can be time consuming – why not just program it to do what you need.

This is some basic monstable circuit code – when a low pulse comes in on PORTA.2 – PORTA.0 will go high for a determined amount of time.  You can adjust the time PORTA.0 is on by changing the value of PulseOut_Time.  This value is in Milliseconds.  Thus 1000 = 1 second.


#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  //16Mhz

#define PulseOut_Time 1000

void setup(void);

void main(void)
        if (PORTAbits.RA2 == 0)
            LATAbits.LATA0 = 1;
            LATAbits.LATA0 = 0;            

void setup(void)
    //Disable analog for A.0, set as Output, Set to Low
    ANSELAbits.ANSA0 = 0;
    TRISAbits.TRISA0 = 0; //A.0 Output
    LATAbits.LATA0 = 0;  //Put A.0 low
      //Setup A.2 as input with WPU
    ANSELAbits.ANSA2 = 0;
    TRISAbits.TRISA2 = 1;
    WPUAbits.WPUA2 = 1; //Enable Weakpull up on A.2   
    OPTION_REGbits.nWPUEN = 0; //Requires being enabled in option reg as well
    //Set the System Clock - You can change this to match the setting you are looking for
    OSCCONbits.IRCF = 0b111;  //Set System Clock to 16Mhz FOSC/4 = 4Mhz


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 Applications - Basic Monostable Circuit