![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Demo for TG-LPC11U35-501
Dependencies: ADT7410 AQM0802 LPS331 M24LC64 PCF8591 mbed
Demo for TG-LPC11U35501. AQM0802, ADT7410, LPS331, 24LC64 and PCF8591
main.cpp@0:9f16c9de320a, 2014-10-04 (annotated)
- Committer:
- yasuyuki
- Date:
- Sat Oct 04 12:09:04 2014 +0000
- Revision:
- 0:9f16c9de320a
first release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yasuyuki | 0:9f16c9de320a | 1 | //********************** |
yasuyuki | 0:9f16c9de320a | 2 | // Barometer and Temperature for mbed |
yasuyuki | 0:9f16c9de320a | 3 | // |
yasuyuki | 0:9f16c9de320a | 4 | // LPC1768 flash=512KB |
yasuyuki | 0:9f16c9de320a | 5 | // LPC11U35 flash=64KB |
yasuyuki | 0:9f16c9de320a | 6 | // |
yasuyuki | 0:9f16c9de320a | 7 | // (C)Copyright 2014 All rights reserved by Y.Onodera |
yasuyuki | 0:9f16c9de320a | 8 | // http://einstlab.web.fc2.com |
yasuyuki | 0:9f16c9de320a | 9 | //********************** |
yasuyuki | 0:9f16c9de320a | 10 | #include "mbed.h" |
yasuyuki | 0:9f16c9de320a | 11 | #include "AQM0802.h" |
yasuyuki | 0:9f16c9de320a | 12 | #include "ADT7410.h" |
yasuyuki | 0:9f16c9de320a | 13 | #include "LPS331.h" |
yasuyuki | 0:9f16c9de320a | 14 | #include "M24LC64.h" |
yasuyuki | 0:9f16c9de320a | 15 | #include "PCF8591.h" |
yasuyuki | 0:9f16c9de320a | 16 | |
yasuyuki | 0:9f16c9de320a | 17 | //#pragma O0 |
yasuyuki | 0:9f16c9de320a | 18 | //#pragma O1 |
yasuyuki | 0:9f16c9de320a | 19 | //#pragma O2 |
yasuyuki | 0:9f16c9de320a | 20 | //#pragma O3 |
yasuyuki | 0:9f16c9de320a | 21 | //#pragma Otime |
yasuyuki | 0:9f16c9de320a | 22 | //#pragma Ospace |
yasuyuki | 0:9f16c9de320a | 23 | |
yasuyuki | 0:9f16c9de320a | 24 | // To select functions |
yasuyuki | 0:9f16c9de320a | 25 | //#define EEPROM |
yasuyuki | 0:9f16c9de320a | 26 | //#define ADCON |
yasuyuki | 0:9f16c9de320a | 27 | #define TEMP |
yasuyuki | 0:9f16c9de320a | 28 | #define BAR |
yasuyuki | 0:9f16c9de320a | 29 | |
yasuyuki | 0:9f16c9de320a | 30 | #if defined(TARGET_LPC1768) |
yasuyuki | 0:9f16c9de320a | 31 | DigitalOut led1(LED1); |
yasuyuki | 0:9f16c9de320a | 32 | DigitalOut led2(LED2); |
yasuyuki | 0:9f16c9de320a | 33 | I2C i2c(p28,p27); |
yasuyuki | 0:9f16c9de320a | 34 | #endif |
yasuyuki | 0:9f16c9de320a | 35 | // for TG-LPC11U35-501 |
yasuyuki | 0:9f16c9de320a | 36 | #if defined (TARGET_LPC11U35_501) |
yasuyuki | 0:9f16c9de320a | 37 | DigitalOut led1(P0_20); |
yasuyuki | 0:9f16c9de320a | 38 | DigitalOut led2(P0_21); |
yasuyuki | 0:9f16c9de320a | 39 | I2C i2c(P0_5,P0_4); |
yasuyuki | 0:9f16c9de320a | 40 | #endif |
yasuyuki | 0:9f16c9de320a | 41 | // for Nucleo |
yasuyuki | 0:9f16c9de320a | 42 | #if defined (TARGET_NUCLEO_F401RE) |
yasuyuki | 0:9f16c9de320a | 43 | DigitalOut led1(D13); |
yasuyuki | 0:9f16c9de320a | 44 | I2C i2c(D14,D15); |
yasuyuki | 0:9f16c9de320a | 45 | #endif |
yasuyuki | 0:9f16c9de320a | 46 | |
yasuyuki | 0:9f16c9de320a | 47 | AQM0802 lcd(i2c); |
yasuyuki | 0:9f16c9de320a | 48 | #ifdef TEMP |
yasuyuki | 0:9f16c9de320a | 49 | ADT7410 temperature(i2c); |
yasuyuki | 0:9f16c9de320a | 50 | #endif |
yasuyuki | 0:9f16c9de320a | 51 | #ifdef BAR |
yasuyuki | 0:9f16c9de320a | 52 | LPS331 barometer(i2c); |
yasuyuki | 0:9f16c9de320a | 53 | #endif |
yasuyuki | 0:9f16c9de320a | 54 | #ifdef EEPROM |
yasuyuki | 0:9f16c9de320a | 55 | M24LC64 eeprom(i2c); |
yasuyuki | 0:9f16c9de320a | 56 | #endif |
yasuyuki | 0:9f16c9de320a | 57 | #ifdef ADCON |
yasuyuki | 0:9f16c9de320a | 58 | PCF8591 adc(i2c); |
yasuyuki | 0:9f16c9de320a | 59 | #endif |
yasuyuki | 0:9f16c9de320a | 60 | |
yasuyuki | 0:9f16c9de320a | 61 | int main() { |
yasuyuki | 0:9f16c9de320a | 62 | |
yasuyuki | 0:9f16c9de320a | 63 | char msg[10]; |
yasuyuki | 0:9f16c9de320a | 64 | #ifdef TEMP |
yasuyuki | 0:9f16c9de320a | 65 | int temp; |
yasuyuki | 0:9f16c9de320a | 66 | #endif |
yasuyuki | 0:9f16c9de320a | 67 | #ifdef BAR |
yasuyuki | 0:9f16c9de320a | 68 | long press; |
yasuyuki | 0:9f16c9de320a | 69 | #endif |
yasuyuki | 0:9f16c9de320a | 70 | #ifdef EEPROM |
yasuyuki | 0:9f16c9de320a | 71 | int l; |
yasuyuki | 0:9f16c9de320a | 72 | unsigned char eep; |
yasuyuki | 0:9f16c9de320a | 73 | #endif |
yasuyuki | 0:9f16c9de320a | 74 | #ifdef ADCON |
yasuyuki | 0:9f16c9de320a | 75 | unsigned char d; |
yasuyuki | 0:9f16c9de320a | 76 | #endif |
yasuyuki | 0:9f16c9de320a | 77 | |
yasuyuki | 0:9f16c9de320a | 78 | // i2c.frequency(100000); // default 100Kbps |
yasuyuki | 0:9f16c9de320a | 79 | sprintf(msg, "%d", SystemCoreClock ); |
yasuyuki | 0:9f16c9de320a | 80 | lcd.locate(0,0); |
yasuyuki | 0:9f16c9de320a | 81 | lcd.print(msg); |
yasuyuki | 0:9f16c9de320a | 82 | wait_ms(1000); |
yasuyuki | 0:9f16c9de320a | 83 | |
yasuyuki | 0:9f16c9de320a | 84 | while(1) { |
yasuyuki | 0:9f16c9de320a | 85 | |
yasuyuki | 0:9f16c9de320a | 86 | #ifdef EEPROM |
yasuyuki | 0:9f16c9de320a | 87 | // EEPROM 0x0002=0x5A |
yasuyuki | 0:9f16c9de320a | 88 | eeprom.put(0x0002, 0x5A); |
yasuyuki | 0:9f16c9de320a | 89 | |
yasuyuki | 0:9f16c9de320a | 90 | for(l=0;l<0x1FFF;l++){ |
yasuyuki | 0:9f16c9de320a | 91 | // EEPROM for 24LC64 |
yasuyuki | 0:9f16c9de320a | 92 | eep=eeprom.get(l); |
yasuyuki | 0:9f16c9de320a | 93 | sprintf(msg,"ADR=%4d",l); |
yasuyuki | 0:9f16c9de320a | 94 | lcd.locate(0,0); |
yasuyuki | 0:9f16c9de320a | 95 | lcd.print(msg); |
yasuyuki | 0:9f16c9de320a | 96 | sprintf(msg,"DAT=%2X ",eep); |
yasuyuki | 0:9f16c9de320a | 97 | lcd.locate(0,1); |
yasuyuki | 0:9f16c9de320a | 98 | lcd.print(msg); |
yasuyuki | 0:9f16c9de320a | 99 | wait_ms(1000); |
yasuyuki | 0:9f16c9de320a | 100 | } |
yasuyuki | 0:9f16c9de320a | 101 | #endif |
yasuyuki | 0:9f16c9de320a | 102 | |
yasuyuki | 0:9f16c9de320a | 103 | #ifdef ADCON |
yasuyuki | 0:9f16c9de320a | 104 | // A/D for PCF8591 |
yasuyuki | 0:9f16c9de320a | 105 | d=adc.get(0x40); // ch0 with D/A enable |
yasuyuki | 0:9f16c9de320a | 106 | // d=adc.get(0x01); // ch1 |
yasuyuki | 0:9f16c9de320a | 107 | // d=adc.get(0x02); // ch2 |
yasuyuki | 0:9f16c9de320a | 108 | // d=adc.getI2C(0x03); // ch3 |
yasuyuki | 0:9f16c9de320a | 109 | sprintf(msg,"A/D=%3d ",d); |
yasuyuki | 0:9f16c9de320a | 110 | lcd.locate(0,0); |
yasuyuki | 0:9f16c9de320a | 111 | lcd.print(msg); |
yasuyuki | 0:9f16c9de320a | 112 | // D/A for PCF8591 |
yasuyuki | 0:9f16c9de320a | 113 | adc.put(0x40, d); |
yasuyuki | 0:9f16c9de320a | 114 | wait_ms(1000); |
yasuyuki | 0:9f16c9de320a | 115 | // wait(1.0); bug for Nucleo |
yasuyuki | 0:9f16c9de320a | 116 | |
yasuyuki | 0:9f16c9de320a | 117 | #endif |
yasuyuki | 0:9f16c9de320a | 118 | |
yasuyuki | 0:9f16c9de320a | 119 | #ifdef TEMP |
yasuyuki | 0:9f16c9de320a | 120 | // Temperature |
yasuyuki | 0:9f16c9de320a | 121 | temp=temperature.value(); |
yasuyuki | 0:9f16c9de320a | 122 | // temp/=128; // for C |
yasuyuki | 0:9f16c9de320a | 123 | temp/=13; |
yasuyuki | 0:9f16c9de320a | 124 | sprintf(msg,"%2d.%1dC ",temp/10,temp%10); |
yasuyuki | 0:9f16c9de320a | 125 | lcd.locate(0,0); |
yasuyuki | 0:9f16c9de320a | 126 | lcd.print(msg); |
yasuyuki | 0:9f16c9de320a | 127 | |
yasuyuki | 0:9f16c9de320a | 128 | led1 = 1; // off |
yasuyuki | 0:9f16c9de320a | 129 | // led2 = 1; |
yasuyuki | 0:9f16c9de320a | 130 | wait_ms(500); |
yasuyuki | 0:9f16c9de320a | 131 | #endif |
yasuyuki | 0:9f16c9de320a | 132 | |
yasuyuki | 0:9f16c9de320a | 133 | #ifdef BAR |
yasuyuki | 0:9f16c9de320a | 134 | // Barometer |
yasuyuki | 0:9f16c9de320a | 135 | press=barometer.value(); |
yasuyuki | 0:9f16c9de320a | 136 | // press/=4096; // for hPa |
yasuyuki | 0:9f16c9de320a | 137 | press/=41; |
yasuyuki | 0:9f16c9de320a | 138 | sprintf(msg,"%dPa ",press); |
yasuyuki | 0:9f16c9de320a | 139 | lcd.locate(0,1); |
yasuyuki | 0:9f16c9de320a | 140 | lcd.print(msg); |
yasuyuki | 0:9f16c9de320a | 141 | |
yasuyuki | 0:9f16c9de320a | 142 | led1 = 0; // on |
yasuyuki | 0:9f16c9de320a | 143 | // led2 = 0; |
yasuyuki | 0:9f16c9de320a | 144 | wait_ms(500); |
yasuyuki | 0:9f16c9de320a | 145 | #endif |
yasuyuki | 0:9f16c9de320a | 146 | } |
yasuyuki | 0:9f16c9de320a | 147 | |
yasuyuki | 0:9f16c9de320a | 148 | } |
yasuyuki | 0:9f16c9de320a | 149 |