13 Jan 2009 @ 6:03 PM 

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 8)       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

   }
Posted By: Michael
Last Edit: 13 Jan 2009 @ 06:03 PM

EmailPermalink
Tags
Categories: Uncategorized


 

Responses to this post » (3 Total)

 
  1. Elcoj says:

    Thanks for article. Everytime like to read you.
    Thank you
    Elcoj

  2. JimmyBean says:

    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

  3. Camila Perry says:

    Led lights are great because they are long lasting and consumes less electricity.;.*

Post a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Change Theme...
  • Users » 5
  • Posts/Pages » 71
  • Comments » 62
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

Contact Me



    No Child Pages.

Front



    No Child Pages.