00001 /*************************************************************************** 00002 * Copyright (C) 30.4.2004 by * 00003 * Matthias Kranz (matthias.kranz@ifi.lmu.de) * 00004 * Paul Holleis (paul.holleis@ifi.lmu.de) * 00005 * * 00006 * header file for standard SmartITs definitions. * 00007 * * 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; either version 2 of the License, or * 00012 * (at your option) any later version. * 00013 * * 00014 * This program is distributed in the hope that it will be useful, * 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00017 * GNU General Public License for more details. * 00018 * * 00019 * You should have received a copy of the GNU General Public License * 00020 * along with this program; if not, write to the * 00021 * Free Software Foundation, Inc., * 00022 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00023 **************************************************************************/ 00024 #ifndef __I2C 00025 #include <i2c.h> 00026 #endif 00027 /****************************************************************************** 00028 * function signatures 00029 *****************************************************************************/ 00030 // I2C FUNCTIONS 00031 void init_ds1621(BYTE id); 00032 BYTE read_temp_ds1621(BYTE id); 00033 BYTE get_temperature(); 00034 00035 /****************************************************************************** 00036 * structs 00037 *****************************************************************************/ 00038 00039 /****************************************************************************** 00040 * global variables 00041 *****************************************************************************/ 00042 00043 00044 /****************************************************************************** 00045 * Code 00046 *****************************************************************************/ 00047 /* 00048 * Updates id function...(whatever that means) 00049 */ 00050 void init_ds1621(BYTE id) 00051 { 00052 id<<1; 00053 i2c_start(); 00054 i2c_write(0x90+(2*id)); 00055 i2c_write(0xac); 00056 i2c_write(9); 00057 i2c_stop(); 00058 //delay_ms(11); 00059 } 00060 00061 /* 00062 * Reads out temperature sensor. Make sure to initialize it first (using method init_ds1621(BYTE id)). 00063 * \returns temperature 00064 */ 00065 BYTE read_temp_ds1621(BYTE id) 00066 { 00067 BYTE datah,datal; 00068 00069 id<<1; 00070 i2c_start(); 00071 i2c_write(0x90+(2*id)); 00072 i2c_write(0xee); 00073 i2c_stop(); 00074 00075 delay_ms(1000);// 1 Sekunde 00076 //restart_wdt(); 00077 i2c_start(); 00078 i2c_write(0x90+(2*id)); 00079 i2c_write(0xaa); 00080 i2c_start(); 00081 i2c_write(0x91+(2*id)); 00082 datah=i2c_read(); 00083 datal=i2c_read(0); 00084 i2c_stop(); 00085 00086 return(datah); 00087 } 00088 /* 00089 * Reads out temperature sensor. Make sure to initialize it first (using method init_ds1621(BYTE id)). 00090 * Takes about 1 second ... 00091 * \returns temperature 00092 */ 00093 BYTE get_temperature() 00094 { 00095 BYTE tmp = 0; 00096 init_ds1621(6); 00097 delay_ms(10); 00098 tmp = read_temp_ds1621(6); 00099 return tmp; 00100 }
1.3.9.1