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.

The Code

/*
 * File:  555_monostable.c
 * Author: Jamie Starling - jamiestarling.com 
 *
 * 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

//Prototypes
void setup(void);




void main(void)
{
    setup();
    
    while(1)
    {
        if (PORTAbits.RA2 == 0)
        {
            LATAbits.LATA0 = 1;
            __delay_ms(PulseOut_Time);
            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 technology project in mind? Let’s talk!

I am currently available for hire

Need a custom technology solution for your business? Please send me an email (jamie@jamiestarling.com) to discuss your project needs.

I can help you get started on the road of building a simple and well-tested working solution, together, with your team.