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);
 }
}

Monday, January 4, 2016

Introductory Electronics: An LED Tester


This blog will cover introductory electronics.  Beginning with simple circuits and working how to make and build your own circuits from scratch.  I began playing with electronics as a kid and still enjoy playing with them.  Most of my projects will involve sound and or light since those are the things I like to work with.
Electricity is part of everything.  When you "touch" something you are actually feeling the force of electrons in your fingers repelling the electrons in the thing you are touching.  Like charges repel each other just like the like poles of a magnet.
Usually electricity has to flow from one place to another to get it to do something useful.  When charges move it is called electric current.  Resistance keeps current from moving too fast.
The first project is going to be an LED tester.  For this you will need the following components:

  • LED
  • 3V button or coin cell battery
Take the ends of the LED and hold the longer lead from the LED against the positive side of the coin cell (labelled with a + symbol) and the shorter lead from the LED against the negative side of the coin cell.  The LED should light up.
Usually attaching an LED directly to a battery without a resistor in series would burn out the LED but these button cell batteries do not produce enough current to damage the LED.