'---------------------------------------------------------------------------------------- ' Name: I2CL_TCN75_DEMO_002.TIG ' Type: Tiger-BASIC(tm) Source Code ' Purpose: This is an example program used for demonstration how to read out data ' from a TCN75 temperature sensor (I2C), using the I2C low lovel functions ' ' (C) - Copyright 2002 Wilke Technology, P.O.Box 1727, D-52018 Aachen, Germany '---------------------------------------------------------------------------------------- ' ' Thank you for using BASIC Tigers in your products. If you have questions, ideas ' or special needs, please contact your next distributor or the Tiger support team ' and visit our web site: ' ' Wilke Technology GmbH ' The Tiger Support Team ' P.O.Box 1727, D-52018 Aachen, Germany ' Krefelder Str. 147, D-52070 Aachen, Germany ' ' email: support@wilke-technology.com (english) ' email: support@wilke.de (german) ' Phone: +49 (241) 918 900 Mo to Fr, 7:00 to 16:00 (GMT) ' Fax: +49 (241) 918 9068 ' ' New information, new drivers and free downloads see: ' ' www.wilke-technology.com (english) ' www.wilke.de (german) ' ' Sincerely, ' ' Your Tiger Support Team ' '---------------------------------------------------------------------------------------- ' ' This demo was compiled with Tiger-BASIC V5.01n and TAC files 1.13g or later to run ' on a Plug & Play Lab with a BASIC-Tiger AXI-4/4. ' ' This program reads out the temperature of a TCN75 temperature sensor connected to the ' I2C bus in an endless loop appr. twice per second and displays the result on the LCD. ' ' Connect the clock line of the TCN75 to pin L80 and the data line to pin L81 of the ' Plug & Play Lab and connect also a pull-up resistor to each line. ' ' ' !----------+-------- Vcc = +5V ' ! ! ' ! ! ' !---! !---! ' ! ! ! ! ' !------------------! ! R ! ! R ! ' ! BASIC-Tiger ! ! ! ! ! ' ! TINY-Tiger ! !---! !---! ' ! ECONO-Tiger ! ! ! ' ! ! ! ! ' ! SCL = CLOCK !-------+-------------------- I2C-Bus ' ! (L80) ! ! ' ! ! ! ' ! ! ! ' ! SDA = DATA !------------------+--------- I2C-Bus ' ! (L81) ! ' ! ! ' ! ! ' !------------------! ' ' ' For more information about the new I2CL functions please look at the file ' I2CL_DEMO_001. All functions and parameters are described in detail there. ' '---------------------------------------------------------------------------------------- USER_VAR_STRICT ' Variables must be declared #DEFINE LCD 1 ' Device no of driver LONG EVER, FLG ' Global variables STRING A$ REAL Temp TASK MAIN ' Begin task MAIN USING "NF<3><1> <1> 0.0.0.0.0.0.3.3.1.0.0.0.0.0.0.0" ' Format string for temperature output INSTALL_DEVICE #LCD, "LCD1.TDD" ' Install LCD driver: BASIC Tiger ' INSTALL DEVICE #LCD, "LCD1.TDD", 0,0,0,0,0,0,80h,8 ' Install LCD driver: TINY Tiger ' (Port, Clock_Pin, Data_Pin, Speed_Reduction: 1=no ... 20=slower) I2CL_SETUP (8, 0, 1, 1) ' Setup I2C pins FOR EVER = 0 TO 0 STEP 0 ' <------------- endless loop -------------- I2CL_START (0) ' Set START condition on bus FLG = I2CL_WRITE ("90 00"%) ' Write 10011110b to bus for write operation I2CL_STOP (0) ' Set STOP condition on bus WAIT_DURATION 100 ' Wait 100 ms I2CL_START (0) ' Set START condition on bus FLG = I2CL_WRITE ("91"%) ' Write 10011111b to bus for read operation A$ = I2CL_READ$ (2) ' READ 2 bytes from I2C-Bus I2CL_STOP (0) ' Set STOP condition on bus Temp = ASC(LEFT$(A$,1)) + ASC(RIGHT$(A$,1)) / 256 ' Calculate the temperature from read value Temp = INT(2 * Temp) / 2.0 ' Round to 0.5 degrees PRINT_USING #1, "<2>"; Temp ' Output temperature value WAIT_DURATION 400 ' Wait 400 ms NEXT ' -------------- endless loop -------------> END ' End of task MAIN