English
Language : 

ADT7302_15 Datasheet, PDF (13/16 Pages) Analog Devices – 2C Accurate, Micropower Digital Temperature Sensor
The following software program shows how to program a
PIC16F873 to communicate with the ADT7302. The
PIC16F873 is configured as an SPI master with the Port A.1
pin used as CS. Any microchip microcontroller can use this
program by simply exchanging the include file for the device
that is being used.
#include <16F873.h>
#device adc=8
#use delay(clock=4000000)
#fuses NOWDT,XT, PUT, NOPROTECT, BROWNOUT, LVP
#BIT CKP = 0x14.4
#define CS PIN_A1
void main(){
int MSByte,LSByte;
long int ADC_Temp_Code;
float TempVal,ADC_Temp_Code_dec;
setup_spi(spi_master);
CKP = 1;
do{
delay_ms(10);
Output_low(CS);
delay_us(10);
MSByte = SPI_Read(0);
LSByte = SPI_Read(0);
delay_us(10);
Output_High(CS);
ADC_Temp_Code = make16(MSByte,LSByte);
ADC_Temp_Code_dec = (float)ADC_Temp_Code;
if ((0x2000 & ADC_Temp_Code) == 0x2000)
{
TempVal = (ADC_Temp_Code_dec - 16384)/32;
}
else
{
TempVal = (ADC_Temp_Code_dec/32);
}
}while(True);
}
ADT7302
//Pic is set up as Master device.
//Idle state of clock is high.
//Allow time for conversions.
//Pull CS low.
//CS to SCLK setup time.
//The first byte is clocked in.
//The second byte is clocked in.
//SCLK to CS setup time.
//Bring CS high.
//16bit ADC code is stored ADC_Temp_Code.
//Convert to float for division.
//Check sign bit for negative value.
//Conversion formula if negative temperature.
//Conversion formula if positive temperature.
//Temperature value stored in TempVal.
Rev. B | Page 13 of 16