Ok i know your saying to yourself “theres already tons of these” but i looked at them and they are long. Anyway i made this to test my ports. Very simple a led connected to port “B” and port “D” on a 877. I know there are better ways to make a led chaser using less pins but im testing my ports (new board) so i need to have a light on each pin to see if it works correctly, im making like a prototyping board and i want to know that all the connections/pins are solid before i make anything out of it.
The best part about this is “bit shifting”, no case/switches or any of that crap. This is the while loop just put it in your main and modify it for your application. It speeds up and slows down, thats what the delay increment is for. before you get into the while loop. If for some reason your using a port that has more than 8 pins you wont be able to store the “bit” variable in a int, try like a int16 etc.
int i =0;
int bit = 0;
int delay = 0;
while(1)
{
if (delay > 50){delay = 0;} // if the delay is getting big make it small again so it goes fast
bit = 1; // set the bit to the rightmost position (pin 1)
for(i=0;i<8;i++)
{
output_d(bit << i); // shift bit to the left "i" times
output_b(bit << i);
delay_ms(delay);
}
bit = 0b10000000; // put the bit on the far left (pin
for(i=0;i<8;i++)
{
output_d(bit >> i); // shift the bit to the right "i" times
output_b(bit >> i);
delay_ms(delay);
}
delay++; // increment the delay so it goes slower
}

Categories
Tag Cloud
Blog RSS
Comments RSS

Void « Default
Life
Earth
Wind
Water
Fire
Light 
Thanks for article. Everytime like to read you.
Thank you
Elcoj
I don’t know If I said it already but …Hey good stuff…keep up the good work!
I read a lot of blogs on a daily basis and for the most part, people lack substance but, I just wanted to make a quick comment to say I’m glad I found your blog. Thanks,)
A definite great read..Jim Bean
Led lights are great because they are long lasting and consumes less electricity.;.*