lpc824break mbed sd文件系统

Dependencies:   DS1302 SDFileSystem mbed

Fork of temp_humid_time_DS1302_LM35_DHT11 by Clovis Fritzen

Files at this revision

API Documentation at this revision

Comitter:
dadangjia
Date:
Thu Jun 08 15:20:57 2017 +0000
Parent:
0:8f0934e41a57
Commit message:
lpc824break mbed sd????

Changed in this revision

SDFileSystem.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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/SDFileSystem.lib	Fri Jul 04 08:08:38 2014 +0000
+++ b/SDFileSystem.lib	Thu Jun 08 15:20:57 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/SDFileSystem/#7b35d1709458
+http://mbed.org/users/mbed_official/code/SDFileSystem/#8db0d3b02cec
--- a/main.cpp	Fri Jul 04 08:08:38 2014 +0000
+++ b/main.cpp	Thu Jun 08 15:20:57 2017 +0000
@@ -1,88 +1,83 @@
 #include "mbed.h"
+#include "DS1302.h"
 #include "SDFileSystem.h"
-#include "DHT.h"
-#include "DS1302.h"
 
+Serial pc(P0_4,P0_0,921600);
+Ticker ticker; 
+float sampleTime = 1.0;
 // Defines for the DS1302 timer module
-#define SCLK    PTC1
-#define IO      PTB19
-#define CE      PTB18
+//#define INITIAL_RUN 1
+#define LED1    P0_15
+#define LED2    P0_16
+#define LED3    P0_17
+#define SCLK    P0_20
+#define IO      P0_21
+#define CE      P0_22
 
-SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); //MOSI, MISO, SCLK, SSEL. (SD Card) Tested on K64F, correct pins.
-AnalogIn LM35(PTB2);
-AnalogIn LDR(PTB3);
-int count=0;
-float ldrcalc= 0.00;
-DigitalOut RedLed(LED1); // Error indication
-DigitalOut GreenLed(LED2); // LM35 read indication
+SDFileSystem sd(P0_26, P0_25, P0_24, P0_15, "sd"); //MOSI, MISO, SCLK, SSEL. (SD Card) Tested on K64F, correct pins.
+DS1302 clk(SCLK, IO, CE); // ports for the DS1302 time keeper
+AnalogIn PH0(P0_6);  //PH传感器 A0
+AnalogIn AD1(P0_14);  //AD采集信号 A1
+float ad1= 0.00;
+float ph0= 0.00;
+char sd_flag;
+DigitalOut RedLed(LED1); // 工作指示灯,每秒闪灭一次
+DigitalOut GreenLed(LED2); // SD卡读取状态寄存器
 DigitalOut Blueled(LED3); // DHT11 read indication
-DHT sensor(PTB20,DHT11); // Use the DHT11 sensor, on pin 
-DS1302 clk(SCLK, IO, PTB18); // ports for the DS1302 time keeper
- 
-int main() {
-    // the 6 lines below are for the time keeper chip
-    #ifdef INITIAL_RUN
-    clk.set_time(1403949720);
+
+void LPC824_ticker()
+{
+    RedLed=!RedLed;
+    ph0 = PH0.read() * 3300; 
+    ad1 = AD1.read() * 3300; 
+    time_t seconds = clk.time(NULL);
+    pc.printf("PH0:%.0f mVd,AD1:%.0f mV,%s\r\n",ph0,ad1,ctime(&seconds));
+    
+    if(sd_flag)
+    {
+        GreenLed= 0;
+        FILE *fp = fopen("/sd/LPC824date/data001.csv", "a");
+        if(fp != NULL) 
+        {
+            fprintf(fp, "%s\t%.0f\t%.0f\n", ctime(&seconds), ph0,ad1); 
+            fclose(fp); 
+            GreenLed= 0;  
+        }
+        else 
+        {
+             GreenLed= 1;            
+        }        
+    }    
+}
+
+void sd_init()
+{
+    RedLed=1;
+    mkdir("/sd/LPC824date", 0777);
+    FILE *fp = fopen("/sd/LPC824date/data001.csv", "w");
+    if(fp == NULL) {
+        pc.printf("Could not open file for write, Please insert your SD CARD!\n");
+        GreenLed= 1;
+        sd_flag=0;
+        }
+     else 
+     {
+         sd_flag = 1;
+         GreenLed= 0;
+     }      
+}
+
+int main() {   
+    pc.printf("LPC824 sd-dh11-ph-ds1302 demo start\r\n");
+    #ifdef INITIAL_RUN    
+    clk.set_time(1494675200); //2017.5.13.11.33
     #endif
-    
     char storedByte = clk.recallByte(0);
-    //printf("\r\nStored byte was %d, now increasing by one\r\n", storedByte);
-    clk.storeByte(0, storedByte + 1);
-    //
-    
-    int err;
-    wait(1); // wait 1 second for DHT11 to stabilyze
-    
-    //printf("Hello World!\n");   
- 
-    mkdir("/sd/dados", 0777);
-    
-    FILE *fp = fopen("/sd/dados/data001.csv", "w");
-    if(fp == NULL) {
-        error("Could not open file for write\n");
-        RedLed= 0;
+    clk.storeByte(0, storedByte + 1); 
+    sd_init(); 
+    ticker.attach(&LPC824_ticker, sampleTime);   
+    while(1)
+    {
         
-        }
-    while (1) {
-    
-    Blueled= 1;
-    RedLed= 1;
-    GreenLed= 1;
-    
-   if (count < 12000000){
-        count++;
-        } else{  
-        // --------------------------
-       
-        err = sensor.readData();
-        if (err == 0) {
-            GreenLed= 0;
-            printf("Temperature is %4.2f \r\n",sensor.ReadTemperature(CELCIUS));
-            //printf("Temperature is %4.2f F \r\n",sensor.ReadTemperature(FARENHEIT));
-            //printf("Temperature is %4.2f K \r\n",sensor.ReadTemperature(KELVIN));
-            printf("Humidity is %4.2f \r\n",sensor.ReadHumidity());
-            //printf("Dew point is %4.2f  \r\n",sensor.CalcdewPoint(sensor.ReadTemperature(CELCIUS), sensor.ReadHumidity()));
-            //printf("Dew point (fast) is %4.2f  \r\n",sensor.CalcdewPointFast(sensor.ReadTemperature(CELCIUS), sensor.ReadHumidity()));
-            
-        } else
-            printf("\r\nErr %i \n",err);
-            
-        // ----------------------------  
-    FILE *fp = fopen("/sd/dados/data001.csv", "a");
-    if(fp == NULL) {
-        error("Could not open file for write\n");
-        
-       }
-    
-    ldrcalc= LDR.read();
-    ldrcalc= (1/ldrcalc)-1;
-    time_t seconds = clk.time(NULL);
-    //fprintf(fp, "%s\r,%f,%f,%f\n", "LM35", "DHT11", "Humid", "Month", "Day", "Hour", "Year");
-    fprintf(fp, "%s\r,%f,%f,%f,%f", ctime(&seconds), 333.333*LM35.read(), sensor.ReadTemperature(CELCIUS), sensor.ReadHumidity(), ldrcalc); 
-    fclose(fp);  
-    //printf("Goodbye World!\n");
-    count=0;
-    Blueled= 0;
     }
-    }
-    }
\ No newline at end of file
+}
--- a/mbed.bld	Fri Jul 04 08:08:38 2014 +0000
+++ b/mbed.bld	Thu Jun 08 15:20:57 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/024bf7f99721
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/faff56e089b2
\ No newline at end of file