PIC 18 IO Lighting LEDs In a Row!
Nice Special Effect — Debut pic — Episode#04
Hi, this code makes the LED’s lighting in a nice sequence o/
All we need is a single button! ❤ git
Here is the code:
Tips n Tricks
Just create a method (increment), a counter variable and a switch like this:
unsigned char myCounter = 0;void increment (unsigned char counter)
{
switch (counter)
{
case 1:{PORTD.RD0 = 1; break;}
case 2:{PORTD.RD1 = 1; break;}
case 3:{PORTD.RD2 = 1; break;}
case 4:{PORTD.RD3 = 1; break;}
case 5:{PORTD.RD4 = 1; break;}
case 6:{PORTD.RD5 = 1; break;}
case 7:{PORTD.RD6 = 1; break;}
case 8:{PORTD.RD7 = 1; break;}
default: {PORTD = 0; MyCounter = 0; break;}
}
}
Yeah! Easy, right?
Now, modifying the same previous code call the method increment instead of LAT:
//PORTD.RD0 = ~ LATD.RD0;
increment(++myCounter);
And that’s all!
In the next lesson let’s make a CHASING LEDS :)
And that’s it
Thanks a lot! See you in the next episode.
Bye!
Related posts:
1º Episode — IO: Debut pic — Pic 18 Hello World \o/ — Just initiating a magic journey throughout Microchip’s best seller pastille
2º Episode — IO: Debut pic — Pic 18 Push & Blink an LED — Let’s Unveil IO’s PIC18 Capabilities
3º Episode — IO: Debut pic — PIC 18 Push & Debounce! — Treating buttons’ Debounce
4º Episode — IO: Debut pic — PIC 18 Lighting LEDs In a Row! — Nice Special Effect
5º Episode — IO: Debut pic — PIC 18 Chasing LEDs — The net result is that LEDs seem to be chasing each other
6º Episode — IO: Debut pic — PIC 18 Double Chasing — The LEDs chase each other in both directions
7º Episode — IO: Debut pic — PIC 18 Ambulance Light — Algorithm for ambulance-flashing-light
8º Episode — IO: Debut pic — PIC 18 Random Flashing — Generating a random number
9º Episode — IO: Debut pic — PIC 18 internal weak pull-ups — How to programming WPUR
10º Episode — IO: Debut pic — Button Library — How to use mikroC PRO for PIC library
11º Episode — IO: Debut pic — Up Down Counter — How to use mikroC PRO for PIC library
References & Credits
GitHub: pic18f