Advertisement
Ocelot

test

Oct 17th, 2011
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. void onewire_tx (uint8_t data)
  2. {
  3.     register uint8_t i=8;
  4.     do
  5.     {
  6.         if (data & 0x80)
  7.         {       // one
  8.             DDRB  |= (1 << _DATAPIN);   // _DATAPIN - pull down
  9.             _delay_us (6);
  10.             DDRB  &= ~(1 << _DATAPIN);  // _DATAPIN - tri-state
  11.             _delay_us (64);
  12.         }
  13.         else
  14.         {       // zero
  15.             DDRB  |= (1 << _DATAPIN);   // _DATAPIN - pull down
  16.             _delay_us (60);
  17.             DDRB  &= ~(1 << _DATAPIN);  // _DATAPIN - tri-state
  18.             _delay_us (10);
  19.         }
  20.         data <<= 1;
  21.     }
  22.     while (--i);
  23. }
  24.  
  25. /*
  26. uint8_t onewire_rx (void)
  27. {
  28.     uint8_t result = 0x00;
  29.     register uint8_t i=8;
  30.     do
  31.     {
  32.         result <<= 1;
  33.         DDRB  |= (1 << _DATAPIN);   // _DATAPIN - pull down
  34.         _delay_us (6);
  35.         DDRB  &= ~(1 << _DATAPIN);  // _DATAPIN - tri-state
  36.         _delay_us (9);
  37.         if (PINB & (1 << _DATAPIN))
  38.         {
  39.             result |= 0x01;
  40.         }
  41.         _delay_us (55);
  42.     }
  43.     while (--i);
  44.     return result;
  45. }
  46. */
  47.  
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement