Advertisement
Guest User

Untitled

a guest
Apr 17th, 2015
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. #define WSH() PORTB |= (1 << PB2)
  2. #define WSL() PORTB &= ~(1 << PB2)
  3. #define BCKH() PORTB |= (1 << PB1)
  4. #define BCKL() PORTB &= ~(1 << PB1)
  5. #define DATH() PORTB |= (1 << PB0)
  6. #define DATL() PORTB &= ~(1 << PB0)
  7.  
  8. inline void i2s_send_bit(uint16_t n, uint8_t pos)
  9. {
  10.   if ( n & (1 << pos) ) DATH(); else DATL();
  11.   NOP(); NOP();
  12.   BCKH();
  13.   NOP(); NOP();
  14.   BCKL();
  15. }
  16.  
  17. void i2s_send(const uint16_t data) {
  18.   WSL();
  19.   _delay_us(2);
  20.  
  21.   uint8_t i = 15;
  22.   for(; i; i--) {
  23.     i2s_send_bit(data, i);
  24.   }
  25.   WSH();
  26.   i2s_send_bit (data, 0);
  27.  
  28.   for(i = 15; i; i--) {
  29.     i2s_send_bit(data, i);
  30.   }
  31.   WSL();
  32.   i2s_send_bit (data, 0);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement