TMP05/TMP06 Data Sheet
Rev. C | Page 22 of 28
#include <stdio.h>
#include <ADuC812.h> //ADuC812 SFR definitions
void delay(int);
sbit Daisy_Start_Pulse = 0xB7; //Daisy_Start_Pulse = P3.7
sbit P3_4 = 0xB4;
long temp_high0,temp_low0,temp_high1,temp_low1,temp_high2,th,tl; //Global variables to allow
//access during ISR.
//See
Figure 32.
int timer0_count=0,timer1_count=0,tempsegment=0;
void int0 () interrupt 0 //INT0 Interrupt Service Routine
{
if (TR1 == 1)
{
th = TH1;
tl = TL1;
th = TH1; //To avoid misreading timer
TL1 = 0;
TH1 = 0;
}
TR1=1; //Start timer1 running, if not running
Already
if (tempsegment == 1)
{
temp_high0 = (TH0*0x100+TL0)+(timer0_count*65536); //Convert to integer
TH0=0x00; //Reset count
TL0=0x00;
timer0_count=0;
}
if (tempsegment == 2)
{
temp_low0 = (th*0x100+tl)+(timer1_count*65536); //Convert to integer
temp_high1 = (TH0*0x100+TL0)+(timer0_count*65536); //Convert to integer
TH0=0x00; //Reset count
TL0=0x00;
timer0_count=0;
timer1_count=0;
}
if (tempsegment == 3)
{
temp_low1 = (th*0x100+tl)+(timer1_count*65536); //Convert to integer
temp_high2 = (TH0*0x100+TL0)+(timer0_count*65536);
TH0=0x00; //Reset count
TL0=0x00;
timer0_count=0;
timer1_count=0;
}
tempsegment++;
}
void timer0 () interrupt 1
{
timer0_count++; //Keep a record of timer0 overflows
}
void timer1 () interrupt 3
{
timer1_count++; //Keep a record of timer1 overflows
Data Sheet TMP05/TMP06
Rev. C | Page 23 of 28
}
void main(void)
{
double temp1=0,temp2=0;
double T1,T2,T3,T4,T5;
// Initialization
TMOD = 0x19; // Timer1 in 16-bit counter mode
// Timer0 in 16-bit counter mode
// with gate on INT0. Timer0 only counts when INTO pin // is high.
ET0 = 1; // Enable timer0 interrupts
ET1 = 1; // Enable timer1 interrupts
tempsegment = 1; // Initialize segment
Daisy_Start_Pulse = 0; // Pull P3.7 low
// Start Pulse
Daisy_Start_Pulse = 1;
Daisy_Start_Pulse = 0; //Toggle P3.7 to give start pulse
// Set T0 to count the high period
TR0 = 1; // Start timer0 running
IT0 = 1; // Interrupt0 edge triggered
EX0 = 1; // Enable interrupt
EA = 1; // Enable global interrupts
for(;;)
{
if (tempsegment == 4)
break;
}
//CONFIGURE UART
SCON = 0x52 ; // 8-bit, no parity, 1 stop bit
TMOD = 0x20 ; // Configure timer1..
TH1 = 0xFD ; // ..for 9600baud..
TR1 = 1; // ..(assuming 11.0592MHz crystal)
//Convert variables to floats for calculation
T1= temp_high0;
T2= temp_low0;
T3= temp_high1;
T4= temp_low1;
T5= temp_high2;
temp1=421-(751*(T1/(T2-T3)));
temp2=421-(751*(T3/(T4-T5)));
printf("Temp1 = %f\nTemp2 = %f\n",temp1,temp2); //Sends temperature result out UART
while (1); // END of program
}
// Delay routine
void delay(int length)
{
while (length >=0)
length--;
}
TMP05/TMP06 Data Sheet
Rev. C | Page 24 of 28
CONTINUOUSLY CONVERTING APPLICATION
This section provides an example of how to connect one
TMP05 in continuously converting mode to a microchip
PIC16F876 microcontroller. Figure 37 shows how to interface
to the PIC16F876.
The TMP05 Program Code Example 2 shows how to
communicate from the microchip device to the TMP05. This
code can also be used with other PICs by changing the include
file for the part.
3.3V
GNDFUNC
CONV/IN
OUT
TMP05
PIC16F876
V
DD
0.1µF
PA.0
FIRST TEMP
MEASUREMENT
T
0
TIME
SECOND TEMP
MEASUREMENT
03340-039
Figure 37. Typical Continuously Converting Application Circuit
TMP05 Program Code Example 2
//=============================================================================================
//
// Description : This program reads the temperature from a TMP05 part set up in continuously
// converting mode.
// This code was written for a PIC16F876, but can be easily configured to function with other
// PICs by simply changing the include file for the part.
//
// Fosc = 4MHz
// Compiled under CCS C compiler IDE version 3.4
// PWM output from TMP05 connected to PortA.0 of PIC16F876
//
//============================================================================================
#include <16F876.h> // Insert header file for the particular PIC being used
#device adc=8
#use delay(clock=4000000)
#fuses NOWDT,XT, PUT, NOPROTECT, BROWNOUT, LVP
//_______________________________Wait for high function_____________________________________
void wait_for_high() {
while(input(PIN_A0)) ; /* while high, wait for low */
while(!input(PIN_A0)); /* wait for high */
}
//______________________________Wait for low function_______________________________________
void wait_for_low() {
while(input(PIN_A0)); /* wait for high */
}
//_______________________________Main begins here____________________________________________
void main(){
long int high_time,low_time,temp;
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_2); //Sets up timer to overflow after 131.07ms

TMP05BKSZ-500RL7

Mfr. #:
Manufacturer:
Analog Devices Inc.
Description:
Board Mount Temperature Sensors IC +/-0.5 Deg/C Accurate PWM
Lifecycle:
New from this manufacturer.
Delivery:
DHL FedEx Ups TNT EMS
Payment:
T/T Paypal Visa MoneyGram Western Union