Advertisement
Guest User

Untitled

a guest
May 26th, 2014
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. void shiftOut(uint16_t val)
  2. {
  3.       uint16_t i;
  4.  
  5.       for (i = 0; i < 16; i++)  {
  6.             if (!!(val & (1 << i)) PORTB |=  (1 << SHIFT_DATA_PIN); //only pull the data pin high for.. 0's?  1's?  whatever.
  7.                  
  8.             PORTB |=  (1 << SHIFT_CLK_PIN);  // pulse the clock pin on
  9.             PORTB &= ~(1 << SHIFT_CLK_PIN);  // ... and off again
  10.             PORTB &= ~(1 << SHIFT_DATA_PIN); // then set data pin back to low
  11.       }
  12. }
  13.  
  14. uint16_t convertforshiftout(uint8_t val)
  15. {
  16.     uint16_t output = 0;  // set output to all 000's
  17.     output = ~output; // invert to all 111's
  18.     uint8_t convertedvalue = val / 16;  // turn our input into a value 0-15
  19.    
  20.       for (i = 0; i <= convertedvalue; i++)  {
  21.           output <<= 1; // shift to the left by one, adds a zero on the end
  22.       }
  23.     output = ~output; // invert output again, so we get 1111111111111111 for a very high value and 0000000011111111 for a halfway value and etc
  24.     return output;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement