エレキジャック Web版 mbedで初めてのマイコン開発 mbedをLANに接続してみよう!のプログラムです。 http://www.eleki-jack.com/arm/mbed/cat691/mbedlan/ <1/3>に RJ45モジュラージャックの加工について <3/3>にプログラムの解説があります。

Dependencies:   EthernetNetIf mbed

Files at this revision

API Documentation at this revision

Comitter:
sunifu
Date:
Thu Oct 07 09:23:04 2010 +0000
Commit message:

Changed in this revision

EthernetNetIf.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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetNetIf.lib	Thu Oct 07 09:23:04 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Oct 07 09:23:04 2010 +0000
@@ -0,0 +1,56 @@
+#include "mbed.h"
+#include "EthernetNetIf.h"
+#include "UDPSocket.h"
+
+int main() {
+
+    EthernetNetIf eth;   // (1)  -- DHCP
+//    EthernetNetIf eth( // (2)  -- static IP address 
+//        IpAddr(192,168,0,2),     // IP Address
+//        IpAddr(255,255,255,0),   // Subnet Mask
+//        IpAddr(192,168,0,1),     // Default Gateway
+//        IpAddr(192,168,0,1)      // DNS Server
+//    ) ;
+   UDPSocket udp;
+   char msg[64] ;
+   Timer tmr;
+   int i = 1 ;
+
+   printf("Setting up...\r\n");
+
+   EthernetErr ethErr = eth.setup();
+
+   if( ethErr != ETH_OK )
+   {
+       printf("Error %d in setup.\r\n", ethErr);
+       return -1;
+   }
+
+   printf("Setup OK\r\n");
+
+   Host host(IpAddr(192,168,0,3), 12345, NULL); 
+
+   udp.bind(host);
+
+   tmr.start();
+
+   while(true)
+   {
+       Net::poll();
+
+       if(tmr.read() > 5){
+           tmr.reset();
+ 
+           if ( i % 5 != 0 ){
+	           sprintf(msg, "No.%3d --- Hello World! ---\r\n",i);
+               udp.sendto( msg, strlen(msg), &host );
+               printf("%s\r\n", msg);  
+           }else{
+               sprintf(msg, "No.%3d --- End! ---\r\n",i);
+               udp.sendto( msg, strlen(msg), &host );
+               printf("%s\r\n", msg);
+           }
+           i++;
+       }
+   }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Oct 07 09:23:04 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e