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.
Dependencies: ADT7410 AQM0802 LPS331 M24LC64 PCF8591 mbed
main.cpp
00001 //********************** 00002 // Barometer and Temperature for mbed 00003 // 00004 // LPC1768 flash=512KB 00005 // LPC11U35 flash=64KB 00006 // 00007 // (C)Copyright 2014 All rights reserved by Y.Onodera 00008 // http://einstlab.web.fc2.com 00009 //********************** 00010 #include "mbed.h" 00011 #include "AQM0802.h" 00012 #include "ADT7410.h" 00013 #include "LPS331.h" 00014 #include "M24LC64.h" 00015 #include "PCF8591.h" 00016 00017 //#pragma O0 00018 //#pragma O1 00019 //#pragma O2 00020 //#pragma O3 00021 //#pragma Otime 00022 //#pragma Ospace 00023 00024 // To select functions 00025 //#define EEPROM 00026 //#define ADCON 00027 #define TEMP 00028 #define BAR 00029 00030 #if defined(TARGET_LPC1768) 00031 DigitalOut led1(LED1); 00032 DigitalOut led2(LED2); 00033 I2C i2c(p28,p27); 00034 #endif 00035 // for TG-LPC11U35-501 00036 #if defined (TARGET_LPC11U35_501) 00037 DigitalOut led1(P0_20); 00038 DigitalOut led2(P0_21); 00039 I2C i2c(P0_5,P0_4); 00040 #endif 00041 // for Nucleo 00042 #if defined (TARGET_NUCLEO_F401RE) 00043 DigitalOut led1(D13); 00044 I2C i2c(D14,D15); 00045 #endif 00046 00047 AQM0802 lcd(i2c); 00048 #ifdef TEMP 00049 ADT7410 temperature(i2c); 00050 #endif 00051 #ifdef BAR 00052 LPS331 barometer(i2c); 00053 #endif 00054 #ifdef EEPROM 00055 M24LC64 eeprom(i2c); 00056 #endif 00057 #ifdef ADCON 00058 PCF8591 adc(i2c); 00059 #endif 00060 00061 int main() { 00062 00063 char msg[10]; 00064 #ifdef TEMP 00065 int temp; 00066 #endif 00067 #ifdef BAR 00068 long press; 00069 #endif 00070 #ifdef EEPROM 00071 int l; 00072 unsigned char eep; 00073 #endif 00074 #ifdef ADCON 00075 unsigned char d; 00076 #endif 00077 00078 // i2c.frequency(100000); // default 100Kbps 00079 sprintf(msg, "%d", SystemCoreClock ); 00080 lcd.locate(0,0); 00081 lcd.print(msg); 00082 wait_ms(1000); 00083 00084 while(1) { 00085 00086 #ifdef EEPROM 00087 // EEPROM 0x0002=0x5A 00088 eeprom.put(0x0002, 0x5A); 00089 00090 for(l=0;l<0x1FFF;l++){ 00091 // EEPROM for 24LC64 00092 eep=eeprom.get(l); 00093 sprintf(msg,"ADR=%4d",l); 00094 lcd.locate(0,0); 00095 lcd.print(msg); 00096 sprintf(msg,"DAT=%2X ",eep); 00097 lcd.locate(0,1); 00098 lcd.print(msg); 00099 wait_ms(1000); 00100 } 00101 #endif 00102 00103 #ifdef ADCON 00104 // A/D for PCF8591 00105 d=adc.get(0x40); // ch0 with D/A enable 00106 // d=adc.get(0x01); // ch1 00107 // d=adc.get(0x02); // ch2 00108 // d=adc.getI2C(0x03); // ch3 00109 sprintf(msg,"A/D=%3d ",d); 00110 lcd.locate(0,0); 00111 lcd.print(msg); 00112 // D/A for PCF8591 00113 adc.put(0x40, d); 00114 wait_ms(1000); 00115 // wait(1.0); bug for Nucleo 00116 00117 #endif 00118 00119 #ifdef TEMP 00120 // Temperature 00121 temp=temperature.value(); 00122 // temp/=128; // for C 00123 temp/=13; 00124 sprintf(msg,"%2d.%1dC ",temp/10,temp%10); 00125 lcd.locate(0,0); 00126 lcd.print(msg); 00127 00128 led1 = 1; // off 00129 // led2 = 1; 00130 wait_ms(500); 00131 #endif 00132 00133 #ifdef BAR 00134 // Barometer 00135 press=barometer.value(); 00136 // press/=4096; // for hPa 00137 press/=41; 00138 sprintf(msg,"%dPa ",press); 00139 lcd.locate(0,1); 00140 lcd.print(msg); 00141 00142 led1 = 0; // on 00143 // led2 = 0; 00144 wait_ms(500); 00145 #endif 00146 } 00147 00148 } 00149
Generated on Tue Jul 12 2022 23:00:46 by
1.7.2