PIC10F322 Applications – Cascaded Timer

If you haven’t noticed I have been going though a copy of The Engineer’s Mini-Notebook – 555 Timer IC Circuits (Radio Shack) for some of these projects.

The Cascaded Timer – when input on PORTA.2 goes low – PORTA.0 will go high, for 1 second, then LOW, Then PORTA.1 will go high, for one second, then LOW.  The on time can be changed by adjusting the PulseOut_Time.

#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

//Prototypes
void setup(void);
void cascade(void);

 

void main(void)
{
setup();

while(1)
{
if (PORTAbits.RA2 == 0)
{
cascade();
}

}
}

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

//Disable analog for A.1, set as Output, Set to Low
ANSELAbits.ANSA1 = 0;
TRISAbits.TRISA1 = 0; //A.1 Output
LATAbits.LATA1 = 0; //Put A.1 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

}

/*reads the input on A.2 to see if it is low – we have a pullup here
*so a low input would indicate that the switch that is tied to ground is being pressed
*If low – we wait 50ms and read the status again
*If low after 50ms, we return 1 to be true the switch is being pressed, otherwise 0 is returned.
*You also can adjust the value of the delay and do something like 1 second, which would require
*the switch to be held for 1 second before something happens. */
uint8_t input_debounce_A2(void)
{
if (PORTAbits.RA2 == 0)
{
__delay_ms(50);

if (PORTAbits.RA2 == 0)
{
return 1;
}

return 0;
}

return 0;
}

void cascade(void)
{
LATAbits.LATA0 = 1; //A.0 on
LATAbits.LATA1 = 0; //A.1 off

__delay_ms(PulseOut_Time);

LATAbits.LATA0 = 0; //A.0 off
LATAbits.LATA1 = 1; //A.1 on

__delay_ms(PulseOut_Time);

LATAbits.LATA0 = 0; //A.0 off
LATAbits.LATA1 = 1; //A.1 on

}

/*
 * File:   cascaded_timer.c
 * Author: Jamie
 *
 * Created on August 16, 2020, 8:56 PM
 */


#include "includes/10F322_deviceconfig.h"
#include "includes/gpio.h"
#include "includes/wpua.h"

#define ON_Value 1000  //On Time in MS

void main(void) {
    
    pinMode(0,OUTPUT);
    pinMode(1,OUTPUT);
    pinMode(2,INPUT);
    enableWPUA(2);
    
    digitalWrite(0,OFF);
    digitalWrite(1,OFF);

    
    
    while(1)
    {
        if (!digitalRead(2))
        {
            digitalWrite(0,ON);
            __delay_ms(ON_Value);
            digitalWrite(0,OFF);
            digitalWrite(1,ON);
            __delay_ms(ON_Value);
            digitalWrite(1,OFF);
        }
    }
}

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 - Cascaded Timer