PIC 18 IO Double Chasing
The LEDs chase each other in both directions — Debut pic — Episode#06
Hi, this project aimed at the joy of coding o/. The Joy of coding is all about the love for programming ❤ git
There is no special application for this algorithm but fun.
Anyway here goes the code:
The important discovery is bitwise.
Bitwise is bit operations. It allows us to manipulate a single bit within a word. They allow us to move, set and clear single bits in registers or numbers that we specify.
for(;;) // Endless loop
{
PORTB = (j|l);
j>>=1; // Cycle right j bits
l<<=1; // Cycle left l bits
if(j==0) j = 0b10000000; // Reset j if zero
if(l==0) l = 0b00000001; // Reset l if zero Delay_ms(100); // Delay .1 s
}
Here we just make, after declare and initialize two variables in the extremes, is make an AND with two unsigned char variables, then bitwise them in opposite ways. All that rest is to wait for the overflow of both bytes and reset them again. Simple like this!
The result you can view in the gift above.
In the next lesson let’s make a Complex Lighting 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