Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /********************************* 00002 **Read DS1624 Temperature Sensor** 00003 ******Made by Stijn Sontrop******* 00004 **********22 Dec 2010************* 00005 **********************************/ 00006 00007 #include "mbed.h" 00008 #include <TextLCD.h> //Include the TextLCD lib (add this one to your project) 00009 00010 00011 //Address of DS1642: 1001 A2 A1 A0 R/W' 00012 //Example: 0x92 = Sensor with address 1 00013 //Make R/W' 0 00014 #define DS1642WRITEADDR 0x92 00015 //Make R/W' 1 00016 #define DS1642READADDR 0x93 00017 00018 TextLCD lcd(p15, p16, p17, p18, p19, p20); //LCD Config rs, e, d4-d7 00019 00020 I2C i2c(p9, p10); //SDA & SCL from I2C 00021 typedef struct { //Struct that contains the MSB en LSB value 00022 char msb; 00023 char lsb; 00024 } temperature; 00025 00026 //Function that reads the temperature 00027 temperature readDS1624(void) { 00028 temperature readval; 00029 i2c.start(); 00030 i2c.write(DS1642WRITEADDR); //address 00031 i2c.write(0xEE); //start conv T 00032 i2c.stop(); 00033 wait_ms(2); 00034 00035 i2c.start(); 00036 i2c.write(DS1642WRITEADDR); //Address 00037 i2c.write(0xAA); //read temp command 00038 i2c.stop(); 00039 wait_ms(1); 00040 00041 i2c.start(); 00042 i2c.write(DS1642READADDR); //Write Address 00043 readval.msb = i2c.read(1); //Read MSB + ACK 00044 readval.lsb = i2c.read(0); //Read LSB + No ACK 00045 i2c.stop(); 00046 readval.msb = readval.msb - 2; //Apparently you need to do -2 to get the right value 00047 return readval; //Return value 00048 } 00049 00050 int main() { 00051 temperature readval; 00052 i2c.start(); 00053 i2c.write(DS1642WRITEADDR); //b1001 A2 A1 A0 R/W' 00054 i2c.write(0xAC); //access config 00055 i2c.write(0x00); //continuous conversion 00056 i2c.stop(); 00057 00058 while (1) { 00059 readval = readDS1624(); //Call the readDS162 function 00060 lcd.cls(); //Clear LCD 00061 lcd.printf("Temp: %d\n%d", readval.msb, readval.lsb); //Print values to LCD 00062 wait(0.3); 00063 } 00064 }
Generated on Thu Jul 14 2022 02:37:33 by
1.7.2