Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetNetIf mbed
main.cpp
00001 //--------------------------------------------------------------------------------------------- 00002 #include "mbed.h" 00003 #include "EthernetNetIf.h" 00004 //--------------------------------------------------------------------------------------------- 00005 DigitalOut myled(LED1); 00006 Serial pc(USBTX, USBRX); // tx, rx 00007 //--------------------------------------------------------------------------------------------- 00008 #define internaldebug // send debug messages to USB Serial port (9600,1,N) 00009 #define dhcpenable // auto-setup IP Address from DHCP router 00010 //--------------------------------------------------------------------------------------------- 00011 // Ethernet Object Setup 00012 //--------------------------------------------------------------------------------------------- 00013 #ifdef dhcpenable 00014 EthernetNetIf eth; 00015 #else 00016 EthernetNetIf eth( 00017 IpAddr(192,168,1,100), //IP Address 00018 IpAddr(255,255,255,0), //Network Mask 00019 IpAddr(192,168,1,254), //Gateway 00020 IpAddr(192,168,1,254) //DNS 00021 ); 00022 #endif 00023 //--------------------------------------------------------------------------------------------- 00024 // MAIN 00025 //--------------------------------------------------------------------------------------------- 00026 int main() 00027 { 00028 //-------------------------------------------------------- 00029 // Set Serial Port Transfer Rate 00030 pc.baud(115200); 00031 //-------------------------------------------------------- 00032 00033 //-------------------------------------------------------- 00034 // Setting Ethernet 00035 //-------------------------------------------------------- 00036 #ifdef internaldebug 00037 printf("\r\nSetting up Ethernet interface!\r\n"); 00038 #endif 00039 // Create return object for error check 00040 EthernetErr ethErr = eth.setup(); 00041 if(ethErr) 00042 { 00043 #ifdef internaldebug 00044 printf("\r\nError %d in Ethernet setup.\r\n", ethErr); 00045 #endif 00046 return -1; 00047 } 00048 #ifdef internaldebug 00049 printf("\r\nEthernet setup completed with success!\r\n"); 00050 #endif 00051 //-------------------------------------------------------- 00052 00053 // main loop 00054 while(1) 00055 { 00056 myled = 1; 00057 wait(0.5); 00058 myled = 0; 00059 wait(0.5); 00060 } 00061 } 00062 //---------------------------------------------------------------------------------------------
Generated on Mon Aug 1 2022 05:01:52 by
1.7.2