Showing posts with label chaser lights. Show all posts
Showing posts with label chaser lights. Show all posts

Tuesday, April 26, 2016

Chaser lights

This simple routine creates chaser lights using a PIC12f683 microcontroller.

/*
 * File:   ChaserMain.c
 * Author: hmikelson
 *
 * Created on April 26, 2016, 12:49 PM
 * Chaser Lights ON GPIO 0,1,2,4,5
 */
#if defined(__XC)
    #include         /* XC8 General Include File */
#elif defined(HI_TECH_C)
    #include        /* HiTech General Include File */
#endif
#include        /* For uint8_t definition */
#include       /* For true/false definition */
#pragma config MCLRE=OFF,CP=OFF,WDTE=OFF,FOSC=INTOSCIO
#define _XTAL_FREQ 8000000
void init()
{
    //Configure GPIO Port
    ANSEL =  0b00000000;  //Configure all GPIO pins as digital
    TRISIO = 0b110001000;  //Set GP# 1=inputs and 0=outputs
    OPTION_REGbits.nGPPU = 0;
    WPU = 0b00000000;     //Enable weak pullups=1
    //Configuer AD Convertor
    ADCON0 = 0x00;        //AD disabled
    ADRESH = 0x00;        //Init the AD Register
    //Configure Comparator
    CMCON0 = 0xFF;   // Comparator is turned off
    CMCON1 = 0x00;   // Comparator is turned off
    //Interrupt configuration
    INTCON = 0x00;   //Disable all interrupts
}
void main()
{
 init();
 GPIO = 0b00000000;
 while(1)
  {
   //Chaser Lights
     GPIO = 0b00000001;
     __delay_ms(100);
     GPIO = 0b00000010;
     __delay_ms(100);
     GPIO = 0b00000100;
     __delay_ms(100);
     GPIO = 0b00010000;
     __delay_ms(100);
     GPIO = 0b00100000;
     __delay_ms(100);
 }
}