Advertisement
Guest User

Untitled

a guest
Nov 9th, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. *   DEKLARACE GLOBAL PROMENNYCH
  3. */
  4.  
  5. uint64_t ROM_NO = 0;
  6.  
  7. /*
  8. *   FUNKCE
  9. */
  10.  
  11. void first (void)
  12. {
  13.     uint8_t id_bit_number = 0;
  14.     uint8_t id_bit = 0;
  15.     uint8_t cmp_id_bit = 0;
  16.     uint8_t LastDiscrepancy = 0;
  17.     uint8_t LastDeviceFlag = 0;
  18.     uint8_t last_zero = 0;
  19.    
  20.     uint8_t search_direction;
  21.        
  22.     if(therm_reset())
  23.     {
  24.         id_bit_number = 1;
  25.         LastDiscrepancy = 0;
  26.         last_zero = 0;
  27.        
  28.         therm_write_byte(THERM_CMD_SEARCHROM);
  29.            
  30.         for(uint8_t i=0; i<64; i++ )
  31.         {
  32.             id_bit = therm_read_bit();
  33.                    
  34.             if(therm_read_bit())
  35.             {
  36.                 if(id_bit) return;          // Error no device on bus
  37.                 else search_direction = 0;      // 01
  38.                
  39.             }
  40.             else                       
  41.             {
  42.                 if(id_bit)search_direction = 1;     // 10              
  43.                 else                    // Discrepancy
  44.                 {
  45.                     if(id_bit_number > LastDiscrepancy) {last_zero = id_bit_number; search_direction = 0;}
  46.                     else if (id_bit_number == LastDiscrepancy) search_direction = 1;
  47.                     else search_direction = ROM_NO & ((uint64_t)1 << id_bit_number);
  48.                 }
  49.                
  50.             }//konec if(therm_read_bit())
  51.  
  52.             if(search_direction) ROM_NO |= ((uint64_t)1 << i);
  53.             else ROM_NO &= ~((uint64_t)1 << i);
  54.            
  55.             therm_write_bit(search_direction);
  56.             id_bit_number++;
  57.                    
  58.         }//konec foru
  59.         LastDiscrepancy = last_zero;
  60.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement