Select Page

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, then not having the values.. etc. Can be time consuming – why not just program a PIC10F322 it to do what you need?

About The Code

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

About The Circuit

For the demo circuit we are using a switch on A2 – and a LED connected to A0.

555 PIC monostable

The Code

 * File:  555_monostable.c
 * Author: Jamie Starling - 
 * Created on:  September 7, 2021, 7:45 PM
 * Code/Circuit provided as-is.

#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 8000000  //8Mhz

#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 A0, set as Output, Set to Low
    ANSELAbits.ANSA0 = 0;
    TRISAbits.TRISA0 = 0; //A0 Output
    LATAbits.LATA0 = 0;  //Put A0 low
      //Setup A2 as input with WPU
    ANSELAbits.ANSA2 = 0;
    TRISAbits.TRISA2 = 1;
    WPUAbits.WPUA2 = 1; //Enable Weakpull up on A2   
    OPTION_REGbits.nWPUEN = 0; //Requires being enabled in option reg as well   

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!

Pin It on Pinterest

Share This