ADT7302_05 AD [Analog Devices], ADT7302_05 Datasheet - Page 13

no-image

ADT7302_05

Manufacturer Part Number
ADT7302_05
Description
Manufacturer
AD [Analog Devices]
Datasheet
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 PortA.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);
Output_High(CS);
ADC_Temp_Code = make16(MSByte,LSByte);
ADC_Temp_Code_dec = (float)ADC_Temp_Code;
if ((0x2000 & ADC_Temp_Code) == 0x2000)
else
}while(True);
LSByte = SPI_Read(0);
delay_us(10);
{
TempVal = (ADC_Temp_Code_dec - 16384)/32;
}
{
TempVal = (ADC_Temp_Code_dec/32);
}
Rev. 0 | Page 13 of 16
//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.
//Covert 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.
ADT7302

Related parts for ADT7302_05