PLC

Dependencies:   EthernetNetIf HTTPServer TextLCD mbed

Fork of ethernet_test_http by Yasushi TAUCHI

Files at this revision

API Documentation at this revision

Comitter:
twinkling
Date:
Mon May 12 04:55:35 2014 +0000
Parent:
0:7dcfd77d344d
Commit message:
PLC??

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun May 08 09:03:08 2011 +0000
+++ b/main.cpp	Mon May 12 04:55:35 2014 +0000
@@ -2,31 +2,44 @@
 #include "TextLCD.h"
 #include "EthernetNetIf.h"
 #include "HTTPServer.h"
+#include "adc.h"
+
 
 DigitalOut led1(LED1,"led1");
 DigitalOut led2(LED2,"led2");
 DigitalOut led3(LED3,"led3");
 DigitalOut led4(LED4,"led4");
+InterruptIn pin5(p5);
 
 TextLCD lcd(p24, p26, p27, p28, p29, p30);
-
-#if 1
-/*
- * Use DHCP
- */
-        EthernetNetIf ethif;
-#else
-/*
- * Use "static IP address" (Parameters:IP, Subnet mask, Gateway, DNS)
- */
-        EthernetNetIf ethif(IpAddr(xxx,xxx,xxx,xxx), IpAddr(xxx,xxx,xxx,xxx), IpAddr(xxx,xxx,xxx,xxx), IpAddr(xxx,xxx,xxx,xxx));
-#endif
-    
+EthernetNetIf ethif(IpAddr(192,168,11,26), IpAddr(255,255,255,0), IpAddr(192,168,11,1), IpAddr(192,168,11,1));
     HTTPServer server;
     LocalFileSystem local("local");
+    FILE *fp;
+
+void int_rise() {
+    led4 = 1;
+    if ( NULL == (fp = fopen( "/local/test.txt", "w" )) )
+        error( "" );
+    fprintf( fp, "st detect");
+    lcd.locate(0,1);
+    lcd.printf("Detect");
+    wait( 0.1 );
+    fclose( fp );
+}
+void int_fall() {
+    led4 = 0;
+    if ( NULL == (fp = fopen( "/local/test.txt", "w" )) )
+        error( "" );
+    fprintf( fp, "%st undetect");
+    lcd.locate(0,1);
+    lcd.printf("Undetect");
+    wait( 0.1 );
+    fclose( fp );
+}
 
 int main(void) {
-
+    
     Base::add_rpc_class<DigitalOut>();
 
     lcd.cls();
@@ -37,19 +50,51 @@
         error("Ethernet setup failed.");
         return 1;
     }
-    IpAddr ethIp=ethif.getIp();
+    
+    led1=1;
+    wait(1);
+    led1=0;
+    server.addHandler<SimpleHandler>("/hello");
+    server.addHandler<RPCHandler>("/rpc");
+    FSHandler::mount("/local", "/");
+    server.addHandler<FSHandler>("/");
+    server.bind(80);
+
+    pin5.rise(&int_rise);  // attach the address of the flip function to the rising edge
+    pin5.fall(&int_fall);
+    
+    lcd.locate(0,0);
+    lcd.printf("Now mode is  ");
     
-    lcd.locate(0,1);
-    lcd.printf("%d.%d.%d.%d", ethIp[0], ethIp[1], ethIp[2], ethIp[3]);
-    led1=1;
+    int volt[2000];
+    int a[5];
+    int n=0, m=0, p=0, v=0, q=0;
+    int v1, v2, v3;
+    int min;
+    check = 0;
+    
+    adc.setup(p19,1);
+            volt_max=0;
+            mled1 = 1;
+    Base::add_rpc_class<DigitalOut>();
+
+    lcd.cls();
+    lcd.locate(0,0);
+    lcd.printf("Program init..  ");
+
+    if (ethif.setup()) {
+        error("Ethernet setup failed.");
+        return 1;
+    }
+    
     wait(1);
     server.addHandler<SimpleHandler>("/hello");
     server.addHandler<RPCHandler>("/rpc");
     FSHandler::mount("/local", "/");
     server.addHandler<FSHandler>("/");
     server.bind(80);
-    while (1) {
+    
+while(1){
         Net::poll();
     }
-    return 0;
 }