#define THERM_DECIMAL_STEPS_12BIT 625 //.0625 #define THERM_CMD_CONVERTTEMP 0x44 #define THERM_CMD_RSCRATCHPAD 0xbe #define THERM_CMD_WSCRATCHPAD 0x4e #define THERM_CMD_CPYSCRATCHPAD 0x48 #define THERM_CMD_RECEEPROM 0xb8 #define THERM_CMD_RPWRSUPPLY 0xb4 #define THERM_CMD_SEARCHROM 0xf0 #define THERM_CMD_READROM 0x33 #define THERM_CMD_MATCHROM 0x55 #define THERM_CMD_SKIPROM 0xcc #define THERM_CMD_ALARMSEARCH 0xec #define THERM_PORT PORTC #define THERM_DDR DDRC #define THERM_PIN PINC #define THERM_DQ PC5//PD7 #define THERM_INPUT_MODE() THERM_DDR&=~(1< //knižnica pre oneskorenia #include uint8_t therm_reset(void){ uint8_t i; //Pull line low and wait for 480uS THERM_LOW(); THERM_OUTPUT_MODE(); _delay_us(490); //Release line and wait for 60uS THERM_INPUT_MODE(); _delay_us(60); //Store line value and wait until the completion of 480uS period i=(THERM_PIN & (1<>=1; n|=(therm_read_bit()<<7); } return n; } void therm_write_byte(uint8_t byte){ uint8_t i=8; while(i--){ //Write actual bit and shift one position right to make the next bit ready therm_write_bit(byte&1); byte>>=1; } } //*************************************************************** void cidlo1 (void) { therm_write_byte(0x10); therm_write_byte(0xfe); therm_write_byte(0x4d); therm_write_byte(0x7b); therm_write_byte(0x01); therm_write_byte(0x08); therm_write_byte(0x00); therm_write_byte(0x7e); } void cidlo2 (void) { therm_write_byte(0x10); therm_write_byte(0x72); therm_write_byte(0x61); therm_write_byte(0x7b); therm_write_byte(0x01); therm_write_byte(0x08); therm_write_byte(0x00); therm_write_byte(0x30); } void startprevodu(unsigned char adresa) { //Reset, skip ROM and start temperature conversion therm_reset(); //therm_write_byte(THERM_CMD_SKIPROM); therm_write_byte(THERM_CMD_MATCHROM); if (adresa==1) cidlo1(); if (adresa==2) cidlo2(); therm_write_byte(THERM_CMD_CONVERTTEMP); } unsigned char vysledokprevodu(unsigned char adresa){ // Buffer length must be at least 12bytes long! ["+XXX.XXXX C"] uint8_t temperature[2]; unsigned char tep; //Wait until conversion is complete while(!therm_read_bit()); //Reset, skip ROM and send command to read Scratchpad therm_reset(); //therm_write_byte(THERM_CMD_SKIPROM); therm_write_byte(THERM_CMD_MATCHROM); if (adresa==1) cidlo1(); if (adresa==2) cidlo2(); therm_write_byte(THERM_CMD_RSCRATCHPAD); //Read Scratchpad (only 2 first bytes) temperature[0]=therm_read_byte(); temperature[1]=therm_read_byte(); therm_reset(); //Store temperature integer digits and decimal digits //tv=temperature[0]>>1; tep=temperature[0]; //if (adresa==1) tv=temperature[0]; //if (adresa==2) ti=temperature[0]; return tep; }