WathchDog

Dependencies:   mbed WDT

Revision:
1:c896654c679b
Parent:
0:63c74ee8bffc
Child:
2:d69d10b670c5
--- a/main.cpp	Fri Jan 26 12:00:55 2018 +0000
+++ b/main.cpp	Thu Feb 21 13:30:36 2019 +0000
@@ -1,74 +1,79 @@
 #include "mbed.h"
 
-/*
-   This basic example just shows how to read the ADC internal channels raw values.
-   Please look in the corresponding device reference manual for a complete
-   description of how to make a temperature sensor, VBat or Vref measurement.
-*/
-
 Serial pc(SERIAL_TX,SERIAL_RX);
-Serial rs485(D1,D0);
-AnalogIn adc_1(A1);
-AnalogIn adc_2(A2);
-//AnalogIn adc_3(A3);
-//AnalogIn adc_4(A4);
-//AnalogIn adc_5(A5);
-//AnalogIn adc_6(A6);
-//AnalogIn adc_7(A7);
+Serial modem(D1,D0);
+AnalogIn adc_1(A0);
+AnalogIn adc_2(A1);
+AnalogIn adc_3(A2);
+AnalogIn adc_4(A3);
 
 DigitalOut led(LED1);
-//DigitalIn in1(PA_1,PullNone);
-//DigitalIn in2(PA_3,PullNone);
+DigitalOut sokutei(D3);
+DigitalOut commndout(D4);
+DigitalIn in1(D9,PullNone);
+DigitalIn in2(D10,PullNone);
+DigitalIn kansyutu(D6,PullNone);
+DigitalIn commandin(D7,PullNone);
+DigitalIn jmp(D2,PullUp);
 
 
 int main()
 {
-    float sum1,sum2;
-    float ad1,ad2;
+    float sum1,sum2,sum3,sum4;
+    float ad1,ad2,ad3,ad4;
     float temp,turb,s;
     int i,cnt;
 
-    rs485.baud(38400);
-    rs485.format(8,Serial::None,1);    
+    modem.baud(38400);
+    modem.format(8,Serial::None,1);    
 
     pc.printf("\nSTM32 ADC internal channels reading example\r\n");
     temp = 0;
     turb = 0;
     s = 0;
+    
+    sokutei = 1;
+    
     while(1) {
+        
+        if (jmp) sokutei = 1;
+        else sokutei = 0;
+        
         sum1 = 0;
         sum2 = 0;
+        sum3 = 0;
+        sum4 = 0;
         cnt = 0;
-        for (i=0;i<1000;i++) {
+        for (i=0;i<10;i++) {
             sum1 += adc_1.read();
             sum2 += adc_2.read();
+            sum3 += adc_3.read();
+            sum4 += adc_4.read();
             cnt += 1;
             wait(0.001);
 
-            if (rs485.readable()) {
-                pc.printf("%c\r",rs485.getc());
+            if (modem.readable()) {
+                pc.printf("%c\r",modem.getc());
                 wait(0.01);
-                rs485.printf("=01,PVAL,%01.04f,%01.03f,%01.03f\r", turb/1000,temp,s);
+                modem.printf("=01,PVAL,%01.04f,%01.03f,%01.03f\r", turb/1000,temp,s);
             }
         }
         if(cnt != 0) {
             ad1 = sum1/cnt;
             ad2 = sum2/cnt;
+            ad3 = sum3/cnt;
+            ad4 = sum4/cnt;
         } else {
             ad1 = adc_1.read();
             ad2 = adc_2.read();
+            ad3 = adc_3.read();
+            ad4 = adc_4.read();
         }
         
-        pc.printf("ADC 1 = %f ad %f mV : %f temp\r\n", ad1,ad1*3300,ad1*66-30+0.3);
-        pc.printf("ADC 2 = %f ad %f mA : %f turb\r\n", ad2,(ad2*3.3/2.74)*20,(ad2-0.166)/0.6642*1000+25.5);
+        pc.printf("ADC = %f  %f  %f  %f \r\n", ad1,ad2,ad3,ad4);
         temp = ad1*66-30+0.3;
         turb = 2.1*((ad2-0.166)/0.6642*1000+25.5);
         s = 0;
         
-//        if (rs485.readable()) {
-//            pc.printf("%c\r",rs485.getc());
-//            wait(0.01);
-//            rs485.printf("=01,PVAL,%01.03f,%01.03f,%01.03f\r", temp,turb,s);
-//        }
     }
 }