#include #include #define SensorIn PINC #define SensorOut PORTC #define SensorPin PC0 #define SensorRegister DDRC #define F_CPU 1000000 char c,f; int reset(void) { int i; SensorRegister |= (1<>=1; } } int readByte(void) { int i; uint8_t result = 0; //result is an 8 bit variable for(i=0;i<8;i++) { result >>= 1; //Shift right if(readBit()) //If readBit returns 1 { result|= 0x80; //Write a 1 to msb } } return result; } int getTemp(char tempScale) { int type; type = 0; char get[10]; char temp_lsb,temp_msb; int k; char temp_f,temp_c; reset(); writeByte(0xCC); writeByte(0x44); _delay_us(150); reset(); writeByte(0xCC); writeByte(0xBE); for(k=0;k<9;k++) { get[k]=readByte(); } temp_msb = get[1]; temp_lsb = get[0]; if(temp_msb<=0x80){temp_lsb = (temp_lsb/2);} temp_msb = temp_msb & 0x80; if(temp_msb>=0x80) { temp_lsb =(~temp_lsb)+1; temp_lsb =(temp_lsb/2); temp_lsb =((-1)*temp_lsb); } temp_c=temp_lsb; if (tempScale == 'c') { /* This can be used to test your temperature sensor if you cannot print to a computer/LCD DDRC |= (1 << PC3); //Set as output if (temp_c > 20 && temp_c < 27) //if the temperature is greater than 20 and less that 27 degrees celcius { PORTC |= (1 << PC3); //Set high } else { PORTC &= ~(1<< PC3); //Set low } */ type = temp_c; } if (tempScale == 'f') { temp_f = 1.8*(temp_c) + 32; //convert celcius to fahrenheit /* This can be used to test your temperature sensor if you cannot print to a computer/LCD DDRC |= (1 << PC3); //Set as output if (temp_f > 65 && temp_f < 82) //if the temperature is greater than 65 and less that 82 degrees fahrenheit { PORTC |= (1 << PC3); //Set high } else { PORTC &= ~(1<< PC3); //Set low } */ type = temp_f; } return type; }