Data logger: Sensors -> Barometer & temperature (BMP180), Humidity & temp. (RHT03), Sunshine (Cds): Display -> 20 chracters x 4 lines: Strage -> EEPROM (AT24C1024): Special functions -> Enter sleep mode to save current, reading the logging data via serial line

Dependencies:   AT24C1024 BMP180 M41T62 RHT03 TextLCD WakeUp mbed

Fork of LPC1114_barometer_with_data_logging by Kenji Arai

Please refer following Notebook.
http://mbed.org/users/kenjiArai/notebook/mbed-lpc1114fn28-data-logger/

Files at this revision

API Documentation at this revision

Comitter:
kenjiArai
Date:
Sun Jun 22 06:10:57 2014 +0000
Parent:
13:950adc9d6d61
Child:
15:065fbeddc305
Commit message:
Barometer program / Step by step approach -> 8th step,; Check each function on I2C devices, EEPROM, LCD, RTC and BMP180

Changed in this revision

AT24C1024.lib Show annotated file Show diff for this revision Revisions of this file
BMP180.lib Show annotated file Show diff for this revision Revisions of this file
M41T62.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
main_aqm0802.h Show annotated file Show diff for this revision Revisions of this file
main_at24c1024.h Show annotated file Show diff for this revision Revisions of this file
main_bmp180.h Show annotated file Show diff for this revision Revisions of this file
main_m41t62.h Show annotated file Show diff for this revision Revisions of this file
main_normal.h Show annotated file Show diff for this revision Revisions of this file
--- a/AT24C1024.lib	Sun Jun 22 01:48:32 2014 +0000
+++ b/AT24C1024.lib	Sun Jun 22 06:10:57 2014 +0000
@@ -1,1 +1,1 @@
-AT24C1024#f5809bb0d965
+AT24C1024#b9f5cf0309af
--- a/BMP180.lib	Sun Jun 22 01:48:32 2014 +0000
+++ b/BMP180.lib	Sun Jun 22 06:10:57 2014 +0000
@@ -1,1 +1,1 @@
-BMP180#23942d7b7023
+BMP180#b81e7659be7a
--- a/M41T62.lib	Sun Jun 22 01:48:32 2014 +0000
+++ b/M41T62.lib	Sun Jun 22 06:10:57 2014 +0000
@@ -1,1 +1,1 @@
-M41T62#9d7702a887d3
+M41T62#c58da9ec9ae3
--- a/main.cpp	Sun Jun 22 01:48:32 2014 +0000
+++ b/main.cpp	Sun Jun 22 06:10:57 2014 +0000
@@ -1,11 +1,11 @@
 /*
  * mbed Application program for the mbed LPC1114FN28
- * Test program -> Check RTC module
+ * Test program -> Check I2C line control
  *
  * Copyright (c) 2014 Kenji Arai / JH1PJL
  *  http://www.page.sannet.ne.jp/kenjia/index.html
  *  http://mbed.org/users/kenjiArai/
- *      Created: June      13th, 2014
+ *      Created: June      22nd, 2014
  *      Revised: June      22nd, 2014
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
@@ -14,285 +14,30 @@
  * DAMAGES OR OTHER  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
-
-#include "mbed.h"
-#include "BMP180.h"             // Own lib. / Pressure sensor             
-#include "RHT03.h"              // Std. lib./ Humidity sensor
-#include "TextLCD.h"            // Std. lib./ LCD control
-#include "AT24C1024.h"          // Own lib. / EEPROM control
-#include "m41t62_rtc.h"         // Own lib. / RTC control
-
-#define USE_C_STD_LIB   1
-
-#define VREF_VOLT       2.482   // TA76431F Vref real measued data
-#define R_FIX           9930    // 10K ohm <- real measued data
-#define VOL_OFFSET      3       // Offset data ,= real measured data
-#define CDS_TBL_SIZE    13
-
-I2C         i2c(dp5,dp27);      // SDA, SCL
-DigitalOut  myled0(dp28);       // LED for Debug
-DigitalOut  myled1(dp14);       // Indicate state transition
-DigitalOut  analog_pwr(dp6);    // VCC for analog interface (vol, cds and vref)
-DigitalOut  vref_pwr(dp4);      // VCC for Vref
-DigitalIn   sw_chng(dp1,PullUp);// SW for select
-DigitalIn   sw_mode(dp2,PullUp);// SW for Mode change
-AnalogIn    cds(dp11);          // Input / CDS data
-AnalogIn    vref(dp9);          // Input / Bandgap 2.5V
-AnalogIn    vol(dp10);          // Input / contrast volume
-RHT03       humtemp(dp26);      // RHT03 interface
-Serial      pc(dp16,dp15);      // UART (vertual COM)
-BMP180      bmp180(i2c);        // Bosch sensor
-TextLCD_I2C_N i2clcd(&i2c, 0x7c, TextLCD::LCD8x2);  // LCD(Akizuki AQM0802A)
-AT24C1024   at24c1024(i2c);     // Atmel 1Mbit EE-PROM 
-M41T62      m41t62(i2c);        // STmicro RTC(M41T62) 
-
-typedef enum {CDS = 0, VREF, VOL} ADC_Select;
-
-//  ADC
-float av_cds, av_vref, av_vol, cal_vcc;
-float r_cds, lux;
-uint32_t nor_vol;
-
-//  Humidity Sensor
-float humidity_temp, humidity;
-
-//  EEPROM
-uint8_t eep_buf[256 + 2];
-
-// Cds GL5528 (Dark Resistance 1 Mohm type) SENBA OPTICAL & ELECTRONIC CO.,LTD.
-//      Table value referrence: http://homepage3.nifty.com/skomo/f35/hp35_20.htm
-const float lux_cds[CDS_TBL_SIZE][2] =
-    {{50,21194},{100,8356},{200,3294},{400,1299},{800,512},{1600,202},{3200,79.6},{6400,31.4},
-    {12800,12.4},{25600,4.88},{51200,1.92},{102400,0.758},{409600,0.118}};
-
-#if USE_C_STD_LIB == 0
-const char week[7][4] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
-#endif
-      
-//-------------------------------------------------------------------------------------------------
-//  Control Program
-//-------------------------------------------------------------------------------------------------
-// Normalize ADC data
-void adc_normalize (ADC_Select n){
-int i;
-float x1,y1,dx;
+// You need to select (set 1) only one from blow
+#define TST_NORMAL      1
+#define TST_LCD8x2      0
+#define TST_EEPROM      0
+#define TST_BMP180      0
+#define TST_M41T62      0
+// You need to select (set 1) only one from above
 
-    switch (n){
-    case CDS:
-        // v_adc = Rfix / (Rcds + Rfix) ->  Rcds = ( Rfix / v_adc ) - Rfix 
-        r_cds = (R_FIX / av_cds) - R_FIX;
-        // CDS resistance to Lux conversion using convertion table (luc_cds[][])
-        for (i =0; i < CDS_TBL_SIZE; i++){  // search table
-            if ( r_cds <= lux_cds[i][0]){ break; }
-        }
-        // Check table position
-        if (i == 0){
-            lux = lux_cds[0][1];
-            break;
-        } else if ( i == CDS_TBL_SIZE ){
-            if ( r_cds <= lux_cds[i][0] ){
-                lux = lux_cds[i-1][1];
-                break;
-            }
-        }
-        //  Linear interpolation
-        y1 = lux_cds[i-1][1] - lux_cds[i][1];
-        x1 = lux_cds[i][0] - lux_cds[i-1][0];
-        dx = r_cds - lux_cds[i-1][0];
-        lux = lux_cds[i-1][1] - ((dx/x1) * y1);
-        break;
-    case VREF:
-        //  vref = VREF_VOLT / VCC -> VCC = VREF_VOLT / vref
-        cal_vcc = VREF_VOLT / vref;
-        break;
-    case VOL:
-        // Vol center = 1.00 (actual 100)
-        nor_vol = (uint32_t)(av_vol * 200) + VOL_OFFSET;
-        break;
-    }
-}
-
-//  Read adc data and averaging
-void adc_all_read (void){
-    if (av_cds == 0){   av_cds = cds.read();
-    } else {            av_cds = av_cds *0.5 + cds.read() * 0.5;
-    }
-    if (av_vref == 0){  av_vref = vref.read();
-    } else {            av_vref = av_vref *0.9 + vref.read() * 0.1;
-    }
-    if (av_vol == 0){   av_vol = vol.read();
-    } else {            av_vol = av_vol *0.2 + vol.read() * 0.8;
-    } 
-}
-
-// Read Humidity sensor data
-void hum_RHT03_read (void){
-    while (true){   // wait data
-        if ( humtemp.readData() == RHT_ERROR_NONE ){ break; }
-    }
-    if (humidity_temp == 0){humidity_temp = humtemp.getTemperatureC();
-    } else {                humidity_temp = humidity_temp * 0.9 + humtemp.getTemperatureC() * 0.1;
-    }
-    if ( humidity == 0 ){   humidity = humtemp.getHumidity();
-    } else {                humidity = humidity * 0.9 + humtemp.getHumidity() * 0.1;
-    }
-}
-
-// Clear LCD
-void cls(void){
-    i2clcd.locate(0, 0);
-    i2clcd.printf("        ");
-    i2clcd.locate(0, 1);
-    i2clcd.printf("        ");
-}
-
-// Set initial time
-void set_initial_time (void){
-    // Set Initial data -> 2014/06/22 10:20:00
-#if USE_C_STD_LIB
-struct tm t;
+#if TST_NORMAL 
+#include "main_normal.h"
+#endif
 
-    m41t62.read_rtc_std(&t);
-    if ((sw_chng == 0) && (sw_mode == 0)){  
-        t.tm_sec  = 0;
-        t.tm_min  = 20;
-        t.tm_hour = 10;
-        t.tm_mday = 22;
-        t.tm_wday = 0; // Sun is not 7 but 0
-        t.tm_mon  = 5; // Jan. = 0
-        t.tm_year = 14 + 100; // 1900+x = now
-        m41t62.write_rtc_std(&t);
-    }
-#else
-rtc_time t;
+#if TST_LCD8x2 
+#include "main_aqm0802.h"
+#endif
 
-    m41t62.read_rtc_direct(&t);
-    if ((sw_chng == 0) && (sw_mode == 0)){   
-        t.rtc_seconds = 0;
-        t.rtc_minutes = 20;
-        t.rtc_hours   = 10;
-        t.rtc_date    = 22;
-        t.rtc_weekday = RTC_Wk_Sunday;
-        t.rtc_month   = 6;
-        t.rtc_year_raw= 14;
-        m41t62.write_rtc_direct(&t);
-    }
+#if TST_EEPROM 
+#include "main_at24c1024.h"
 #endif
-}
 
-//-------------------------------------
-// Application program starts here
-//-------------------------------------
-int main() {
-    pc.baud(9600);
-    pc.printf("\r\nmbed LPC1114FN28 test program by JH1PJL created on "__DATE__"(UTC)\r\n");
-    i2clcd.setContrast(25);
-    i2clcd.locate(0, 0);
-    i2clcd.printf("LPC1114F");
-    i2clcd.locate(0, 1);
-    i2clcd.printf(" JH1PJL ");
-    // Initialize data
-    av_cds = 0;
-    av_vref = 0;
-    av_vol = 0;
-    humidity_temp = 0;
-    humidity = 0;
-    // RTC
-    m41t62.set_sq_wave(RTC_SQW_NONE);
-    set_initial_time();
-    // Show initial screen
-    wait(5.0);    
-    while(1) {
-    //  ---------- Cds Sensor, Vref, Volume ---------------------------------------------------
-        // Power on / Analog sensor
-        analog_pwr = 1;
-        vref_pwr = 1;
-        wait(0.2);
-        adc_all_read();
-        // Power off / Analog sensor
-        analog_pwr = 0; 
-        // Normalize
-        adc_normalize(CDS);
-        adc_normalize(VREF);
-        adc_normalize(VOL);
-        cls();       
-        i2clcd.locate(0, 0);    // 1st line top
-        //             12345678
-        i2clcd.printf("L:%.1f", lux);
-        i2clcd.locate(0, 1);    // 2nd line top
-        i2clcd.printf("V:%.3f", cal_vcc);       
-        myled0 = 1;
-        pc.printf( "\r\nCds:%.0fohm->%.1flux, Vcc:%.3fV, Vol:%d\r\n",
-            r_cds, lux, cal_vcc, nor_vol );
-        myled0 = 0;
-        wait(4.0);
-    //  ---------- Barometer Sensor / BMP180 --------------------------------------------------
-        bmp180.normalize();
-        cls();
-        i2clcd.locate(0, 0);    // 1st line top
-        i2clcd.printf("P:%.1f", bmp180.read_pressure());
-        i2clcd.locate(0, 1);    // 2nd line top
-        i2clcd.printf("T:%\+-6.1f", bmp180.read_temperature());
-        myled1 = 1;
-        pc.printf("Pres:%4.1fhPa, Temp:%\+-0.1fdegC\r\n",
-                bmp180.read_pressure(), bmp180.read_temperature());
-        myled1 = 0;
-        wait(4.0);
-    //  ---------- Humidity Sensor / RHT03 ----------------------------------------------------
-        hum_RHT03_read();       // Read Humidity data then avaraging
-        cls();
-        i2clcd.locate(0, 0);    // 1st line top
-        i2clcd.printf("H:%.1f", humidity);
-        i2clcd.locate(0, 1);    // 2nd line top
-        i2clcd.printf("T:%\+-6.1f", humidity_temp);
-        myled1 = 1;
-        pc.printf("Humid: %0.1f%%RH, Temp:%\+-0.1fdegC\r\n", humidity, humidity_temp);          
-        myled1 = 0; 
-        wait(4.0);
-    //  ---------- Check RTC ------------------------------------------------------------------
-#if USE_C_STD_LIB
-tm t;
-time_t seconds;
-char buf[40];
+#if TST_BMP180 
+#include "main_bmp180.h"
+#endif
 
-        m41t62.read_rtc_std(&t);
-        seconds = mktime(&t);
-        cls();
-        i2clcd.locate(0, 0);    // 1st line top
-        i2clcd.printf("%02d/%02d/%02d", t.tm_year % 100, t.tm_mon, t.tm_mday);
-        i2clcd.locate(0, 1);    // 2nd line top
-        i2clcd.printf("%02d:%02d:%02d", t.tm_hour, t.tm_min, t.tm_sec);
-        myled1 = 1;
-        // Show Time with several example
-        // ex.1
-        pc.printf("Date: %04d/%02d/%02d, %02d:%02d:%02d\r\n",
-                    t.tm_year + 1900, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
-        // ex.2
-        strftime(buf, 40, "%x %X", localtime(&seconds));
-        printf("Date: %s\r\n", buf);
-        // ex.3
-        strftime(buf, 40, "%I:%M:%S %p (%Y/%m/%d)", localtime(&seconds));
-        printf("Date: %s\r\n", buf);
-        // ex.4
-        strftime(buf, 40, "%B %d,'%y, %H:%M:%S", localtime(&seconds));
-        printf("Date: %s\r\n", buf);
-        myled1 = 0;
-        wait(4.0);
-#else
-rtc_time t;
- 
-        m41t62.read_rtc_direct(&t);
-        cls();
-        i2clcd.locate(0, 0);    // 1st line top
-        i2clcd.printf("%02d/%02d/%02d", t.rtc_year, t.rtc_month, t.rtc_date);
-        i2clcd.locate(0, 1);    // 2nd line top
-        i2clcd.printf("%02d:%02d:%02d", t.rtc_hours, t.rtc_minutes, t.rtc_seconds);
-        myled1 = 1;
-        pc.printf("Date:%04d/%02d/%02d(%s), Time:%02d:%02d:%02d\r\n",
-            t.rtc_year, t.rtc_month, t.rtc_date, &week[t.rtc_weekday-1][0],
-            t.rtc_hours, t.rtc_minutes, t.rtc_seconds);          
-        myled1 = 0;
-        wait(4.0);
-#endif  
-    }
-}
+#if TST_M41T62 
+#include "main_m41t62.h"
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main_aqm0802.h	Sun Jun 22 06:10:57 2014 +0000
@@ -0,0 +1,56 @@
+/*
+ * mbed Application program for the mbed LPC1114FN28
+ * Test program -> Check RTC module
+ *
+ * Copyright (c) 2014 Kenji Arai / JH1PJL
+ *  http://www.page.sannet.ne.jp/kenjia/index.html
+ *  http://mbed.org/users/kenjiArai/
+ *      Created: June      22nd, 2014
+ *      Revised: June      22nd, 2014
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
+ * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#include "mbed.h"
+#include "TextLCD.h"            // Std. lib./ LCD control
+
+I2C         i2c(dp5,dp27);      // SDA, SCL
+TextLCD_I2C_N i2clcd(&i2c, 0x7c, TextLCD::LCD8x2);  // LCD(Akizuki AQM0802A)
+   
+//-------------------------------------------------------------------------------------------------
+//  Control Program
+//-------------------------------------------------------------------------------------------------
+// Clear LCD
+void cls(void){
+    i2clcd.locate(0, 0);
+    i2clcd.printf("        ");
+    i2clcd.locate(0, 1);
+    i2clcd.printf("        ");
+}
+
+//-------------------------------------
+// Application program starts here
+//-------------------------------------
+int main() {
+uint16_t no = 0;
+
+    i2clcd.setContrast(25);
+    i2clcd.locate(0, 0);
+    i2clcd.printf("LPC1114F");
+    i2clcd.locate(0, 1);
+    i2clcd.printf(" JH1PJL ");
+    // Show initial screen
+    wait(5.0);    
+    while(1) {
+        cls();       
+        i2clcd.locate(0, 0);    // 1st line top
+        //             12345678
+        i2clcd.printf(" test");
+        i2clcd.locate(0, 1);    // 2nd line top
+        i2clcd.printf("%8d", ++no);
+        wait(1.0);       
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main_at24c1024.h	Sun Jun 22 06:10:57 2014 +0000
@@ -0,0 +1,151 @@
+/*
+ * mbed Application program for the mbed LPC1114FN28
+ * Test program -> Check RTC module
+ *
+ * Copyright (c) 2014 Kenji Arai / JH1PJL
+ *  http://www.page.sannet.ne.jp/kenjia/index.html
+ *  http://mbed.org/users/kenjiArai/
+ *      Created: June      22nd, 2014
+ *      Revised: June      22nd, 2014
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
+ * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "mbed.h"
+#include "AT24C1024.h"          // Own lib. / EEPROM control
+
+Serial      pc(dp16,dp15);      // UART (vertual COM)
+#if 1
+AT24C1024   at24c1024(dp5,dp27);// Atmel 1Mbit EE-PROM 
+#else
+I2C         i2c(dp5,dp27);      // SDA, SCL
+AT24C1024   at24c1024(i2c);     // Atmel 1Mbit EE-PROM 
+#endif
+
+//  EEPROM
+uint8_t eep_buf[256 + 2];
+
+// EEPROM test charcters
+const uint8_t eep_char[256] =
+//0        1         2         3         4         5         6         7
+//12345678901234567890123456789012345678901234567890123456789012345678901
+ "The AT24C1024 provides 1048576 bits of serial electrically erasable and"
+//7       8         9        10        11        12        13        14        15
+//2345678901234567890123456789012345678901234567890123456789012345678901234567890123
+ " programmable read only memory (EEPROM) organized as 131,072 words of 8 bits each."
+//15   16        17        18        19        20        21        22        23        24
+//45678901234567890123456789012345678901234567890123456789012345678901234567890123456789012
+ " The devices cascadable feature allows up to four devices to share a common two-wire bus."
+//24    25   256
+//34567890123456
+ "  JH1PJL Arai"; // eep_char[255] = 0;
+  
+//-------------------------------------------------------------------------------------------------
+//  Control Program
+//-------------------------------------------------------------------------------------------------
+int main() {
+int no =0;
+uint8_t dt[4];
+AT24C_STATUS status;
+
+    pc.baud(9600);
+    pc.printf("\r\nmbed LPC1114FN28 EEPROM test by JH1PJL created on "__DATE__"(UTC)\r\n");
+    dt[0] = 0;     dt[1] = 0;     dt[2] = 0;     dt[3] = 0; //initialize data 
+    while(1) {
+    //  ---------- Check EEPROM ----------------------------------------------------
+        if (no == 4) {  // check page write mode (part1)
+            ++no;
+            strcpy((char *)eep_buf,(char *)eep_char);   // copy the data         
+            status = at24c1024.write_page(0x100, eep_buf, sizeof(eep_buf)); // 0x100= page address
+            pc.printf("(Status: %d) ", status);
+            if (status == AT24C_OK){    // wrote without trouble
+                wait(1.0);
+                for (int i=0; i < 256; i++){    // clear buffer for read data checking
+                    eep_buf[i] = 0;
+                }
+                status = at24c1024.read_page(0x100, eep_buf, sizeof(eep_buf));
+                pc.printf("(Status: %d) ", status);
+                if (status == AT24C_OK){    // read w/o trouble
+                    pc.printf("\r\n%s\r\n", eep_buf);
+                    if (strncmp((char *)eep_buf, (char *)eep_char, 256) == 0){ // equal R/W data
+                        pc.printf("Page access OK\r\n");
+                    } else {    // Read != Wrote
+                        pc.printf("Page access Comp NG\r\n");
+                    }
+                } else {    // read w/ trouble
+                    pc.printf("Page access read NG\r\n");
+                }
+            } else {        // write w/ trouble
+                pc.printf("Write NG\r\n");
+            }
+            wait(2.0);       
+        } else if (no == 5) {  // check page write mode (part2)
+            no = 0;
+            for (int i=0; i < 256; i++){    // set writing data 255,254,,,,,3,2,1,0
+                eep_buf[i] = 255 - (uint8_t)i;
+            }        
+            status = at24c1024.write_page(0x1ff00, eep_buf, sizeof(eep_buf));
+            pc.printf("(Status: %d) ", status);
+            if (status == AT24C_OK){
+                wait(1.0);
+                for (int i=0; i < 256; i++){    // clear buffer
+                    eep_buf[i] = 0;
+                }
+                status = at24c1024.read_page(0x1ff00, eep_buf, sizeof(eep_buf));
+                pc.printf("(Status: %d) ", status);
+                if (status == AT24C_OK){
+                    pc.printf("\r\n0:%d, 64:%d, 128:%d, 254:%d, 255:%d\r\n",
+                            eep_buf[0], eep_buf[64], eep_buf[128], eep_buf[254], eep_buf[255]);
+                    if ((eep_buf[0] == 255) && (eep_buf[64] == 255 - 64)
+                            && (eep_buf[128] == 255-128) && (eep_buf[255] == 0)){
+                        pc.printf("Page access OK\r\n");
+                    } else {
+                        pc.printf("Page access Comp NG\r\n");
+                    }
+                } else {
+                    pc.printf("Page access read NG\r\n");
+                }
+            } else {
+                pc.printf("Write NG\r\n");
+            }
+            wait(2.0);
+        } else {    // Write and read (single byte)
+            if (no == 0){   // Initial setting
+                // Check EEPROM (step0)
+                at24c1024.write(0,no);
+                wait(0.1);
+                at24c1024.write(1,0);
+                wait(0.1);
+                at24c1024.write(2,0x55);
+                wait(0.1);
+                at24c1024.write(3,0xaa);
+                wait(0.1);
+                dt[0] = 0xff;
+                dt[1] = 1;
+                dt[2] = 2;
+                dt[3] = 3;
+            }
+            // read 4 bytes
+            dt[0] = at24c1024.read(0);
+            dt[1] = at24c1024.read(1);
+            dt[2] = at24c1024.read(2);
+            dt[3] = at24c1024.read(3);     
+            if (dt[0] != no){
+                pc.printf("NG\r\n");
+            } else {           
+                if ((dt[1] == 0) && (dt[2] == 0x55) && (dt[3] == 0xaa)){
+                    pc.printf("OK\r\n");        
+                } else {
+                    pc.printf("NG\r\n");
+                }
+            }
+            pc.printf("EEPROM 0x%x,0x%x,0x%x,0x%x\r\n", dt[0],dt[1],dt[2],dt[3]);
+            at24c1024.write(0,++no);    // write sequence number into EEPROM
+            wait(2.0);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main_bmp180.h	Sun Jun 22 06:10:57 2014 +0000
@@ -0,0 +1,42 @@
+/*
+ * mbed Application program for the mbed LPC1114FN28
+ * Test program -> Check RTC module
+ *
+ * Copyright (c) 2014 Kenji Arai / JH1PJL
+ *  http://www.page.sannet.ne.jp/kenjia/index.html
+ *  http://mbed.org/users/kenjiArai/
+ *      Created: June      22nd, 2014
+ *      Revised: June      22nd, 2014
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
+ * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "mbed.h"
+#include "BMP180.h"             // Own lib. / Pressure sensor             
+
+Serial      pc(dp16,dp15);      // UART (vertual COM)
+#if 1
+BMP180      bmp180(dp5,dp27);   // Bosch sensor
+#else
+I2C         i2c(dp5,dp27);      // SDA, SCL
+BMP180      bmp180(i2c);        // Bosch sensor
+#endif
+   
+//-------------------------------------------------------------------------------------------------
+//  Control Program
+//-------------------------------------------------------------------------------------------------
+int main() {
+    pc.baud(9600);
+    pc.printf("\r\nmbed LPC1114FN28 BMP180 test by JH1PJL created on "__DATE__"(UTC)\r\n"); 
+    while(1) {
+    //  ---------- Barometer Sensor / BMP180 --------------------------------------------------
+        bmp180.normalize();
+        pc.printf("Pres:%4.1fhPa, Temp:%\+-0.1fdegC\r\n",
+                bmp180.read_pressure(), bmp180.read_temperature());
+        wait(1.0);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main_m41t62.h	Sun Jun 22 06:10:57 2014 +0000
@@ -0,0 +1,68 @@
+/*
+ * mbed Application program for the mbed LPC1114FN28
+ * Test program -> Check RTC module
+ *
+ * Copyright (c) 2014 Kenji Arai / JH1PJL
+ *  http://www.page.sannet.ne.jp/kenjia/index.html
+ *  http://mbed.org/users/kenjiArai/
+ *      Created: June      22nd, 2014
+ *      Revised: June      22nd, 2014
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
+ * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "mbed.h"
+#include "m41t62_rtc.h"         // Own lib. / RTC control
+
+Serial      pc(dp16,dp15);      // UART (vertual COM)
+#if 1
+M41T62      m41t62(dp5,dp27);   // STmicro RTC(M41T62) 
+#else
+I2C         i2c(dp5,dp27);      // SDA, SCL
+M41T62      m41t62(i2c);        // STmicro RTC(M41T62) 
+#endif
+   
+//-------------------------------------------------------------------------------------------------
+//  Control Program
+//-------------------------------------------------------------------------------------------------
+int main() {
+    pc.baud(9600);
+    pc.printf("\r\nmbed LPC1114FN28 test program by JH1PJL created on "__DATE__"(UTC)\r\n");
+    // RTC
+    m41t62.set_sq_wave(RTC_SQW_NONE);  
+    while(1) {
+    //  ---------- Check RTC ------------------------------------------------------------------
+tm t;
+time_t seconds;
+char buf[40];
+
+        m41t62.read_rtc_std(&t);
+        seconds = mktime(&t);
+        // Show Time with several example
+#if 0
+        // ex.1
+        pc.printf("Date: %04d/%02d/%02d, %02d:%02d:%02d\r\n",
+                    t.tm_year + 1900, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
+#endif
+#if 0
+        // ex.2
+        strftime(buf, 40, "%x %X", localtime(&seconds));
+        printf("Date: %s\r\n", buf);
+#endif
+#if 1
+        // ex.3
+        strftime(buf, 40, "%I:%M:%S %p (%Y/%m/%d)", localtime(&seconds));
+        printf("Date: %s\r\n", buf);
+#endif
+#if 0
+        // ex.4
+        strftime(buf, 40, "%B %d,'%y, %H:%M:%S", localtime(&seconds));
+        printf("Date: %s\r\n", buf);
+#endif
+        wait(1.0); 
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main_normal.h	Sun Jun 22 06:10:57 2014 +0000
@@ -0,0 +1,299 @@
+/*
+ * mbed Application program for the mbed LPC1114FN28
+ * Test program -> same as LPC1114_test_step_7
+ *
+ * Copyright (c) 2014 Kenji Arai / JH1PJL
+ *  http://www.page.sannet.ne.jp/kenjia/index.html
+ *  http://mbed.org/users/kenjiArai/
+ *      Created: June      13th, 2014
+ *      Revised: June      22nd, 2014
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
+ * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "mbed.h"
+#include "BMP180.h"             // Own lib. / Pressure sensor             
+#include "RHT03.h"              // Std. lib./ Humidity sensor
+#include "TextLCD.h"            // Std. lib./ LCD control
+#include "AT24C1024.h"          // Own lib. / EEPROM control
+#include "m41t62_rtc.h"         // Own lib. / RTC control
+
+#define USE_C_STD_LIB   1
+
+#define VREF_VOLT       2.482   // TA76431F Vref real measued data
+#define R_FIX           9930    // 10K ohm <- real measued data
+#define VOL_OFFSET      3       // Offset data ,= real measured data
+#define CDS_TBL_SIZE    13
+
+I2C         i2c(dp5,dp27);      // SDA, SCL
+DigitalOut  myled0(dp28);       // LED for Debug
+DigitalOut  myled1(dp14);       // Indicate state transition
+DigitalOut  analog_pwr(dp6);    // VCC for analog interface (vol, cds and vref)
+DigitalOut  vref_pwr(dp4);      // VCC for Vref
+DigitalIn   sw_chng(dp1,PullUp);// SW for select
+DigitalIn   sw_mode(dp2,PullUp);// SW for Mode change
+AnalogIn    cds(dp11);          // Input / CDS data
+AnalogIn    vref(dp9);          // Input / Bandgap 2.5V
+AnalogIn    vol(dp10);          // Input / contrast volume
+RHT03       humtemp(dp26);      // RHT03 interface
+Serial      pc(dp16,dp15);      // UART (vertual COM)
+BMP180      bmp180(i2c);        // Bosch sensor
+TextLCD_I2C_N i2clcd(&i2c, 0x7c, TextLCD::LCD8x2);  // LCD(Akizuki AQM0802A)
+AT24C1024   at24c1024(i2c);     // Atmel 1Mbit EE-PROM 
+M41T62      m41t62(i2c);        // STmicro RTC(M41T62) 
+
+typedef enum {CDS = 0, VREF, VOL} ADC_Select;
+
+//  ADC
+float av_cds, av_vref, av_vol, cal_vcc;
+float r_cds, lux;
+uint32_t nor_vol;
+
+//  Humidity Sensor
+float humidity_temp, humidity;
+
+//  EEPROM
+uint8_t eep_buf[256 + 2];
+
+// Cds GL5528 (Dark Resistance 1 Mohm type) SENBA OPTICAL & ELECTRONIC CO.,LTD.
+//      Table value referrence: http://homepage3.nifty.com/skomo/f35/hp35_20.htm
+const float lux_cds[CDS_TBL_SIZE][2] =
+    {{50,21194},{100,8356},{200,3294},{400,1299},{800,512},{1600,202},{3200,79.6},{6400,31.4},
+    {12800,12.4},{25600,4.88},{51200,1.92},{102400,0.758},{409600,0.118}};
+
+#if USE_C_STD_LIB == 0
+const char week[7][4] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
+#endif
+      
+//-------------------------------------------------------------------------------------------------
+//  Control Program
+//-------------------------------------------------------------------------------------------------
+// Normalize ADC data
+void adc_normalize (ADC_Select n){
+int i;
+float x1,y1,dx;
+
+    switch (n){
+    case CDS:
+        // v_adc = Rfix / (Rcds + Rfix) ->  Rcds = ( Rfix / v_adc ) - Rfix 
+        r_cds = (R_FIX / av_cds) - R_FIX;
+        // CDS resistance to Lux conversion using convertion table (luc_cds[][])
+        for (i =0; i < CDS_TBL_SIZE; i++){  // search table
+            if ( r_cds <= lux_cds[i][0]){ break; }
+        }
+        // Check table position
+        if (i == 0){
+            lux = lux_cds[0][1];
+            break;
+        } else if ( i == CDS_TBL_SIZE ){
+            if ( r_cds <= lux_cds[i][0] ){
+                lux = lux_cds[i-1][1];
+                break;
+            }
+        }
+        //  Linear interpolation
+        y1 = lux_cds[i-1][1] - lux_cds[i][1];
+        x1 = lux_cds[i][0] - lux_cds[i-1][0];
+        dx = r_cds - lux_cds[i-1][0];
+        lux = lux_cds[i-1][1] - ((dx/x1) * y1);
+        break;
+    case VREF:
+        //  vref = VREF_VOLT / VCC -> VCC = VREF_VOLT / vref
+        cal_vcc = VREF_VOLT / vref;
+        break;
+    case VOL:
+        // Vol center = 1.00 (actual 100)
+        nor_vol = (uint32_t)(av_vol * 200) + VOL_OFFSET;
+        break;
+    }
+}
+
+//  Read adc data and averaging
+void adc_all_read (void){
+    if (av_cds == 0){   av_cds = cds.read();
+    } else {            av_cds = av_cds *0.5 + cds.read() * 0.5;
+    }
+    if (av_vref == 0){  av_vref = vref.read();
+    } else {            av_vref = av_vref *0.9 + vref.read() * 0.1;
+    }
+    if (av_vol == 0){   av_vol = vol.read();
+    } else {            av_vol = av_vol *0.2 + vol.read() * 0.8;
+    } 
+}
+
+// Read Humidity sensor data
+void hum_RHT03_read (void){
+    while (true){   // wait data
+        if ( humtemp.readData() == RHT_ERROR_NONE ){ break; }
+    }
+    if (humidity_temp == 0){humidity_temp = humtemp.getTemperatureC();
+    } else {                humidity_temp = humidity_temp * 0.9 + humtemp.getTemperatureC() * 0.1;
+    }
+    if ( humidity == 0 ){   humidity = humtemp.getHumidity();
+    } else {                humidity = humidity * 0.9 + humtemp.getHumidity() * 0.1;
+    }
+}
+
+// Clear LCD
+void cls(void){
+    i2clcd.locate(0, 0);
+    i2clcd.printf("        ");
+    i2clcd.locate(0, 1);
+    i2clcd.printf("        ");
+}
+
+// Set initial time
+void set_initial_time (void){
+    // Set Initial data -> 2014/06/22 10:20:00
+#if USE_C_STD_LIB
+struct tm t;
+
+    m41t62.read_rtc_std(&t);
+    if ((sw_chng == 0) && (sw_mode == 0)){  
+        t.tm_sec  = 0;
+        t.tm_min  = 20;
+        t.tm_hour = 10;
+        t.tm_mday = 22;
+        t.tm_wday = 0; // Sun is not 7 but 0
+        t.tm_mon  = 5; // Jan. = 0
+        t.tm_year = 14 + 100; // 1900+x = now
+        m41t62.write_rtc_std(&t);
+    }
+#else
+rtc_time t;
+
+    m41t62.read_rtc_direct(&t);
+    if ((sw_chng == 0) && (sw_mode == 0)){   
+        t.rtc_seconds = 0;
+        t.rtc_minutes = 20;
+        t.rtc_hours   = 10;
+        t.rtc_date    = 22;
+        t.rtc_weekday = RTC_Wk_Sunday;
+        t.rtc_month   = 6;
+        t.rtc_year_raw= 14;
+        m41t62.write_rtc_direct(&t);
+    }
+#endif
+}
+
+//-------------------------------------
+// Application program starts here
+//-------------------------------------
+int main() {
+    pc.baud(9600);
+    pc.printf("\r\nmbed LPC1114FN28 test program by JH1PJL created on "__DATE__"(UTC)\r\n");
+    i2clcd.setContrast(25);
+    i2clcd.locate(0, 0);
+    i2clcd.printf("LPC1114F");
+    i2clcd.locate(0, 1);
+    i2clcd.printf(" JH1PJL ");
+    // Initialize data
+    av_cds = 0;
+    av_vref = 0;
+    av_vol = 0;
+    humidity_temp = 0;
+    humidity = 0;
+    // RTC
+    m41t62.set_sq_wave(RTC_SQW_NONE);
+    set_initial_time();
+    // Show initial screen
+    wait(5.0);    
+    while(1) {
+    //  ---------- Cds Sensor, Vref, Volume ---------------------------------------------------
+        // Power on / Analog sensor
+        analog_pwr = 1;
+        vref_pwr = 1;
+        wait(0.2);
+        adc_all_read();
+        // Power off / Analog sensor
+        analog_pwr = 0; 
+        // Normalize
+        adc_normalize(CDS);
+        adc_normalize(VREF);
+        adc_normalize(VOL);
+        cls();       
+        i2clcd.locate(0, 0);    // 1st line top
+        //             12345678
+        i2clcd.printf("L:%.1f", lux);
+        i2clcd.locate(0, 1);    // 2nd line top
+        i2clcd.printf("V:%.3f", cal_vcc);       
+        myled0 = 1;
+        pc.printf( "\r\nCds:%.0fohm->%.1flux, Vcc:%.3fV, Vol:%d\r\n",
+            r_cds, lux, cal_vcc, nor_vol );
+        myled0 = 0;
+        wait(4.0);
+    //  ---------- Barometer Sensor / BMP180 --------------------------------------------------
+        bmp180.normalize();
+        cls();
+        i2clcd.locate(0, 0);    // 1st line top
+        i2clcd.printf("P:%.1f", bmp180.read_pressure());
+        i2clcd.locate(0, 1);    // 2nd line top
+        i2clcd.printf("T:%\+-6.1f", bmp180.read_temperature());
+        myled1 = 1;
+        pc.printf("Pres:%4.1fhPa, Temp:%\+-0.1fdegC\r\n",
+                bmp180.read_pressure(), bmp180.read_temperature());
+        myled1 = 0;
+        wait(4.0);
+    //  ---------- Humidity Sensor / RHT03 ----------------------------------------------------
+        hum_RHT03_read();       // Read Humidity data then avaraging
+        cls();
+        i2clcd.locate(0, 0);    // 1st line top
+        i2clcd.printf("H:%.1f", humidity);
+        i2clcd.locate(0, 1);    // 2nd line top
+        i2clcd.printf("T:%\+-6.1f", humidity_temp);
+        myled1 = 1;
+        pc.printf("Humid: %0.1f%%RH, Temp:%\+-0.1fdegC\r\n", humidity, humidity_temp);          
+        myled1 = 0; 
+        wait(4.0);
+    //  ---------- Check RTC ------------------------------------------------------------------
+#if USE_C_STD_LIB
+tm t;
+time_t seconds;
+char buf[40];
+
+        m41t62.read_rtc_std(&t);
+        seconds = mktime(&t);
+        cls();
+        i2clcd.locate(0, 0);    // 1st line top
+        i2clcd.printf("%02d/%02d/%02d", t.tm_year % 100, t.tm_mon + 1, t.tm_mday);
+        i2clcd.locate(0, 1);    // 2nd line top
+        i2clcd.printf("%02d:%02d:%02d", t.tm_hour, t.tm_min, t.tm_sec);
+        myled1 = 1;
+        // Show Time with several example
+        // ex.1
+        pc.printf("Date: %04d/%02d/%02d, %02d:%02d:%02d\r\n",
+                    t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
+        // ex.2
+        strftime(buf, 40, "%x %X", localtime(&seconds));
+        printf("Date: %s\r\n", buf);
+        // ex.3
+        strftime(buf, 40, "%I:%M:%S %p (%Y/%m/%d)", localtime(&seconds));
+        printf("Date: %s\r\n", buf);
+        // ex.4
+        strftime(buf, 40, "%B %d,'%y, %H:%M:%S", localtime(&seconds));
+        printf("Date: %s\r\n", buf);
+        myled1 = 0;
+        wait(4.0);
+#else
+rtc_time t;
+ 
+        m41t62.read_rtc_direct(&t);
+        cls();
+        i2clcd.locate(0, 0);    // 1st line top
+        i2clcd.printf("%02d/%02d/%02d", t.rtc_year, t.rtc_month, t.rtc_date);
+        i2clcd.locate(0, 1);    // 2nd line top
+        i2clcd.printf("%02d:%02d:%02d", t.rtc_hours, t.rtc_minutes, t.rtc_seconds);
+        myled1 = 1;
+        pc.printf("Date:%04d/%02d/%02d(%s), Time:%02d:%02d:%02d\r\n",
+            t.rtc_year, t.rtc_month, t.rtc_date, &week[t.rtc_weekday-1][0],
+            t.rtc_hours, t.rtc_minutes, t.rtc_seconds);          
+        myled1 = 0;
+        wait(4.0);
+#endif  
+    }
+}
+