Hello friends, Here's a code to implement the read of the thermal sensor (TC74A0 of microchip) via I2C.
This sensor hvae an especial adress to init and to place in stand by mode, The adress deppend on the last word. i.e. with my sensor is A0 in the Datasheet you can view others available adress for other codes (A1,A5 etc.)
well to put in normal mode you have to make this:
I2cwrite sda,sclK,$90,[$00] 'where $90 is the adress to write an $00 indicates the normal operation
to read:
i2cread sda,sclK,$91,[tempT] 'where $91 is the adress to read the register of temp.
here is a little program to Read the Temp with hyperterminal or the serial comunicator from MCSP
The description of the program is:Code:'**************************************************************** '* Name : TERMO con TC74.pbp * '* Author : Max E. Reyes Vera Juárez * '* Notice : * '* : All Rights Reserved GPL * '* Date : 23/10/2006 * '* Version : 1.0 * '* Notes : * '* : * '**************************************************************** @ DEVICE XT_OSC, PROTECT_OFF, WDT_OFF include "modedefs.bas" SCLK VAR PORTB.0 SDA VAR PORTB.1 TEMPT VAR BYTE TEMPP VAR BYTE i var byte X VAR BYTE INIT: I2cwrite sda,sclK,$90,[$00] 'CONFIGUARNDO MODO DE OPERACION NORMAL PAUSE 1000 GOTO P P: SERIN PORTA.1,T9600,X IF X="M" THEN GOSUB SENSA ENDIF GOTO P SENSA: FOR I=0 TO 4 i2cread sda,sclK,$91,[tempT] 'LEE LA TEMPERATURA TEMPP=TEMPP+TEMPT PAUSE 250 NEXT I TEMPT=TEMPP/5 PAUSE 1000 serout2 portb.3,84,["temperatura: ",DEC tempT,"°C"," BIN: ",BIN8 TEMPT,13] TEMPP=0 RETURN END
The program Wait the caracter "M" to read the register, when "M" is present the program read the register 5 times and get the average of the temp, then send serially at 9600 to the PC.
Grettings from Mexico
PS. sorry for my english




Bookmarks