XC8 Code for PIC10F322 – Trigger Activated Dual Alternating Flasher – Model Train Level Crossing Lights

I am also in the process of releasing a new PIC10F322 Board, designed for people who want a platform to explore LED effects with the PIC10F322.  More to come on that later.

For the trigger Activated Dual Alternating Flasher – Model Train Level Crossing Lights circuit –  LEDs are connected for PORTA.0 and PORTA.1 – with PORTA.2 set as input.  When PORTA.2 is brought LOW, the LEDs will alternate.  When PORTA.2 goes back HIGH, the LEDS will turn off.

The PIC10F322 debounce function (debounce.c and debounce.h) can be found here  GitHub – https://github.com/JamieStarling/MCU_FUN/tree/master/Microchip/PIC10F322/ traincrossing_trigger.c

 

Here is the XC8 code for the Trigger Activated Dual Alternating Flasher – Model Train Level Crossing Lights

 

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


void main ()
{
  
    
    pinMode(0,OUTPUT);
    pinMode(1,OUTPUT);
    
    digitalWrite(0,LOW);
    digitalWrite(1,LOW);    
    
    pinMode(2,INPUT);
    enableWPUA(2);
    
    //The Forever Loop
    while (1)
    {
        
       if(inputDebounce(2,LOW)) //Check the input if high turn off the LED
       {
          
            //Set PortA.0 High (turn on LED)
            digitalWrite(0,ON);   
             digitalWrite(1,OFF); 
        
            //Wait 1 second
            __delay_ms(1000);
        
             //Set PortA.0 Low  (turn off LED)
             digitalWrite(0,OFF);
             digitalWrite(1,ON);
        
            //Wait 1 second
            __delay_ms(1000);
        
         //End of Loop
       }
        
       //Turn off the LEDS
        digitalWrite(0,LOW);
        digitalWrite(1,LOW); 
       
    }
}