Guest User

Untitled

a guest
May 20th, 2013
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. void setup() {
  2.   DDRC |= _BV(0) | _BV(1) | _BV(3);
  3.   PORTC=0x00;
  4. }
  5. void loop()
  6. {
  7.   long a;
  8.   for(a = 0; a < 128; a+= 1)
  9.   {
  10.  
  11.     PORTC &= ~( _BV(3));
  12.     shiftOut(a);
  13.     PORTC |= ( _BV(3));
  14.   }
  15.   for(a = 128; a > 0 ; a-= 1)
  16.   {
  17.     PORTC &= ~( _BV(3));
  18.     shiftOut(a);
  19.     PORTC |= ( _BV(3));
  20.   }
  21. }
  22.  
  23.  
  24.  
  25.  
  26. void shiftOut(long myDataOut)
  27. {
  28.   int pinState;
  29.   PORTC &= ~( _BV(0));
  30.   PORTC &= ~( _BV(1));
  31.   int outPut;
  32.   for (outPut=0; outPut < 24; outPut++)  //24 different outputs
  33.   {
  34.     for(int val = 11; val >= 0; val--)    //12 bit number
  35.     {
  36.       PORTC &= ~( _BV(1));
  37.       if ( myDataOut & (1<<val) )
  38.       {
  39.         pinState = 1;
  40.         PORTC |= ( _BV(0));
  41.       }
  42.       else
  43.       {
  44.         pinState= 0;
  45.         PORTC &= ~( _BV(0));
  46.       }
  47.  
  48.       PORTC |= ( _BV(1));
  49.       PORTC &= ~( _BV(0));
  50.     }
  51.   }
  52.   PORTC &= ~( _BV(1));
  53. }
Advertisement
Add Comment
Please, Sign In to add comment