uint16_t read_meas(void) { uint8_t id[8], diff; //uint8_t s[30]; uint8_t i; uint16_t temp = 0; for( diff = SEARCH_FIRST; diff != LAST_DEVICE; ){ diff = w1_rom_search( diff, id ); if( diff == PRESENCE_ERR ){ //uputsnl( "No Sensor found" ); break; } if( diff == DATA_ERR ){ //uputsnl( "Bus Error" ); break; } if( id[0] == 0x28 || id[0] == 0x10 ){ // temperature sensor //uputs( "ID: " ); for( i = 0; i < 8; i++ ){ //sprintf( s, "%02X ", id[i] ); //uputs( s ); } w1_byte_wr( READ ); // read command temp = w1_byte_rd(); // low byte temp |= (uint16_t)w1_byte_rd() << 8; // high byte if( id[0] == 0x10 ) // 9 -> 12 bit temp <<= 3; //sprintf( s, " T: %04X = ", temp ); // hex value //uputs( s ); //sprintf( s, "%4d.%01d¯C", temp >> 4, (temp << 12) / 6553 ); // 0.1¯C //uputsnl( s ); } } //uputsnl( "" ); return (temp >> 4) * 100 + ((temp << 12) / 6553) * 10; //return temp >> 4; }
void read_meas( void ) { uchar id[8], diff; uchar s[30]; uchar i; uint temp; for( diff = SEARCH_FIRST; diff != LAST_DEVICE; ) { diff = w1_rom_search( diff, id ); if( diff == PRESENCE_ERR ) { uputsnl( "No Sensor found" ); break; } if( diff == DATA_ERR ) { uputsnl( "Bus Error" ); break; } if( id[0] == 0x28 || id[0] == 0x10 ) // temperature sensor { uputs( "ID: " ); for( i = 0; i < 8; i++ ){ sprintf( s, "%02X ", id[i] ); uputs( s ); } w1_byte_wr( READ ); // read command temp = w1_byte_rd(); // low byte temp |= (uint)w1_byte_rd() << 8; // high byte if( id[0] == 0x10 ) // 9 -> 12 bit temp <<= 3; sprintf( s, " T: %04X = ", temp ); // hex value uputs( s ); sprintf( s, "%4d.%01d�C", temp >> 4, (temp << 12) / 6553 ); // 0.1�C uputsnl( s ); } }
uint read_meas( void ) { uchar id[8], diff; uchar i; uint temp; for( diff = SEARCH_FIRST; diff != LAST_DEVICE; ) { diff = w1_rom_search( diff, id ); if( diff == PRESENCE_ERR ) { //printf( "No Sensor found" ); break; } if( diff == DATA_ERR ) { //printf( "Bus Error" ); break; } if( id[0] == 0x28 || id[0] == 0x10 ) { // temperature sensor //LCD_setpos(0,0); for( i = 0; i < 8; i++ ) { // printf("%02X", id[i] ); ID } w1_byte_wr( READ ); // read command temp = w1_byte_rd(); // low byte temp |= (uint)w1_byte_rd() << 8; // high byte if( id[0] == 0x10 ) // 9 -> 12 bit temp <<= 3; //LCD_setpos(1,0); return temp; } } return 0; }