Raynerd.co.uk

Bi-colour LED Blinker – 12F675

A very simple project but it makes a nice introduction to coding! It is actually just two pins at logic 1 independently and then together so on the development board it is simply two leds flashing but if you put it with a bi-colour led (maplin sell these as tri-colour but they are actually only two colours R&G, true tri-colour is RGB) it looks quite nice.

I`m sure you`ll get the idea after a few seconds! 😆

Simple flashing:


#define red GPIO.b0
#define green GPIO.b1
int i=500;
char cnt;
void init()
{
ANSEL = 0; // Configure AN pins as digital
CMCON = 7; // Turn off the comparators
TRISIO = 0; // configure pins of GPIO as output
GPIO = 0x00;
}

void main()
{
init ();

while (1)
{
red = 1;
green=0;
delay_ms(200);
red = 0;
green = 1;
delay_ms(200);
red = 1;
delay_ms(200);
}
}

Alternative shown in the video with a nice looking delay that speeds up:


#define red GPIO.b0
#define green GPIO.b1
int i=500;
char cnt;
void init()
{
ANSEL = 0; // Configure AN pins as digital
CMCON = 7; // Turn off the comparators
TRISIO = 0; // configure pins of GPIO as output
GPIO = 0x00;
}

void main()
{
init ();

while (1)
{
i = i-40;
if (i <= 0) i = 500; else { red = 1; green=0; Vdelay_ms(i); red = 0; green = 1; Vdelay_ms(i); red = 1; Vdelay_ms(i); if (i <200) { red = 1; green=0; Vdelay_ms(i); red = 0; green = 1; Vdelay_ms(i); red = 1; Vdelay_ms(i); } if (i<100) { for (cnt=0; cnt<80; cnt++) { red = 1; green=0; Vdelay_ms(i); red = 0; green = 1; Vdelay_ms(i); red = 1; Vdelay_ms(i); } } } } }

RSS
YouTube
Twitter
Visit Us
Follow by Email922
Google+
Google+

Leave a Reply

Your email address will not be published.