View previous topic :: View next topic |
Author |
Message |
newpic
Joined: 09 Aug 2005 Posts: 32
|
Driver for TC72 Temperature Sensor |
Posted: Thu Aug 18, 2005 2:41 pm |
|
|
Anyone has a driver for the Microchip TC72 device?
Please help....
Thanks... |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
|
MikeValencia
Joined: 04 Aug 2004 Posts: 238 Location: Chicago
|
|
Posted: Thu Aug 18, 2005 3:41 pm |
|
|
Code: |
#include <16F876.h>
#device ADC=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000) /* one instruction=1us? */
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#use I2C(master, SCL=PIN_C3, SDA=PIN_C4)
void main(void)
{
int data;
int ack;
long int fahr;
printf ("\r\n\r\n\r\n");
printf ("T C 7 2 D E M O\r\n");
while (1)
{
i2c_start();
ack = i2c_write(0x9A);
ack = i2c_write(0x00);
/* send start again */
i2c_start();
ack = i2c_write(0x9b);
data = i2c_read();
i2c_stop();
fahr = (9 * (long)data);
fahr = fahr/5;
fahr = fahr + 32;
printf ("Temp: %ld\r\n", fahr);
delay_ms(200);
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
MikeValencia
Joined: 04 Aug 2004 Posts: 238 Location: Chicago
|
|
Posted: Thu Aug 18, 2005 4:09 pm |
|
|
oops. I cut and pasted code that i once wrote for the PICDEM. And i added some printf's in there. Looking at the schematic i realize now it is a TC74.
Why don't you just use a TC77 or a TC74. The code is here. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Thu Aug 18, 2005 4:13 pm |
|
|
Just think how much will be learned if they use the Microchip info and develops a driver instead of having someone else do all the work... I have been forced to write written custom drivers 10-12 times now and have gotten pretty good at it. Not so hard with a little practice... |
|
|
newpic
Joined: 09 Aug 2005 Posts: 32
|
TC72 Help |
Posted: Fri Aug 19, 2005 8:11 am |
|
|
Can any body look at my code, why it does not work. Do I need to have the driver or not?
Thanks in advanced.
Code: | #include <16F876A.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#define clk pin_c3 // set pin clock is using
#define din pin_c5 // set pin data in is using
#define cs pin_b2 // set pin load/cs is using
int16 temp1;
void main()
{
output_low(clk); // set clk line low
delay_us(1);
output_low(din); // set data line in low
delay_us(1);
output_low(cs); // set load/cs line high
delay_us(1);
setup_adc_ports(NO_ANALOGS);
// Configure TC72 temperature sensor
setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_XMIT_L_TO_H | SPI_CLK_DIV_16);
while(1)
{
output_high(cs); // set cs line high
delay_us(1);
spi_write(0x80); // Write Address
delay_us(1);
spi_write(0x00); // Continuous mode
delay_ms(150); // Delay 150ms to let it complete conversion
spi_write(0x02); // Point to MSB temp register
delay_us(1);
temp1=spi_read(0); // read temp
delay_us(1);
output_low(cs);
printf("Temperature is: %lu\n\r",temp1);
}
}
|
|
|
|
Guest
|
Re: TC72 Help |
Posted: Fri Aug 19, 2005 9:49 am |
|
|
newpic wrote: | Can any body look at my code, why it does not work. Do I need to have the driver or not? |
Actually, your spi_write() and read functions are the "driver". |
|
|
Guest
|
|
Posted: Fri Aug 19, 2005 9:52 am |
|
|
It always display
"Temperature is: 0 "
It does not get the right temperature data with the above code.
Did I do anything wrong in the code? |
|
|
Guest Guest
|
|
Posted: Fri Aug 19, 2005 11:15 am |
|
|
If you see icicles in the room, then I guess you did it right. |
|
|
|