Last active
February 5, 2022 09:13
-
-
Save mattrude/04ffd79fb0075ff4b8b04520cc4d07b6 to your computer and use it in GitHub Desktop.
PIC16F15214 - A simple program that simulates a standard traffic stop light with 3 LEDs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* File: PIC16F15214-stoplight.c | |
* Hardware: PIC16F15214 | |
* Build software: MPLAB X IDE v6.00 & XC8 v2.32 | |
* Author: Matt Rude <[email protected]> | |
* Created on February 3, 2022, 1:11 AM | |
* | |
* ---------------------------------------------------------------------------- | |
* Description: | |
* | |
* A simple program that simulates a standard traffic stop light with 6 LEDs. | |
* | |
* ---------------------------------------------------------------------------- | |
* PIC16F15214 pin-out: | |
* | |
* ______ | |
* GND - VDD - |° | - VSS - 5v+ | |
* (B) Green LED - RA5 - | | - RA0 - (A) Green LED | |
* (B) Yellow LED - RA4 - | | - RA1 - (A) Yellow LED | |
* (B) Red LED - RA3 - |______| - RA2 - (A) Red LED | |
* | |
* (Note: the dot next to the VDD pin represents the dot on the chip.) | |
* | |
* ---------------------------------------------------------------------------- | |
* MIT License: | |
* | |
* Copyright (c) 2022 Matt Rude <[email protected]> | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to | |
* deal in the Software without restriction, including without limitation the | |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | |
* sell copies of the Software, and to permit persons to whom the Software is | |
* furnished to do so, subject to the following conditions: | |
* | |
* The above copyright notice and this permission notice shall be included in | |
* all copies or substantial portions of the Software. | |
* | |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
* IN THE SOFTWARE. | |
*/ | |
#define _XTAL_FREQ 1000000 // Set CPU to 1Mhz | |
// PIC16F15214 Configuration Bit Settings | |
#pragma config FEXTOSC = OFF | |
#pragma config RSTOSC = HFINTOSC_1MHZ | |
#pragma config CLKOUTEN = OFF | |
#pragma config WDTE = OFF | |
#include <xc.h> | |
// Define the pins used and how they are used | |
#define AredLed LATAbits.LATA2 // Set pin 0 as the Red LED | |
#define AyellowLed LATAbits.LATA1 // Set pin 1 as the Yellow LED | |
#define AgreenLed LATAbits.LATA0 // Set pin 2 as the Green LED | |
#define BredLed LATAbits.LATA5 // Set pin 5 as the Red LED | |
#define ByellowLed LATAbits.LATA4 // Set pin 4 as the Yellow LED | |
#define BgreenLed LATAbits.LATA3 // Set pin 3 as the Green LED | |
int main() | |
{ | |
TRISA = 0x0; // Set all pins as output | |
AredLed = 1; // Start with everything off but the | |
AyellowLed = 0; // - red LEDs for 5 seconds. | |
AgreenLed = 0; | |
BredLed = 1; | |
ByellowLed = 0; | |
BgreenLed = 0; | |
__delay_ms(5000); // Wait 5 seconds with all directions red | |
while (1) | |
{ | |
// Direction A "Green" | |
AredLed = 0; | |
AgreenLed = 1; | |
__delay_ms(9500); // 9.5 Seconds Delay | |
// Direction A "Yellow" | |
AgreenLed = 0; | |
AyellowLed = 1; | |
__delay_ms(5000); // 5 Seconds Delay | |
// Direction A "Red" | |
AyellowLed = 0; | |
AredLed = 1; | |
__delay_ms(500); // half a second Delay | |
/*********************************************************************/ | |
// Direction B "Green" | |
BredLed = 0; | |
BgreenLed = 1; | |
__delay_ms(9500); // 9.5 Seconds Delay | |
// Direction B "Yellow" | |
BgreenLed = 0; | |
ByellowLed = 1; | |
__delay_ms(5000); // 5 Seconds Delay | |
// Direction B "Red" | |
ByellowLed = 0; | |
BredLed = 1; | |
__delay_ms(500); // half a second Delay | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment