Vasily Kushakov
/
PE_12-08_EthernetRead_DisplayLCD
test publish read ethernet packets from second mbed and display to onboard lcd
main.cpp@0:cdab0c569ba7, 2015-02-18 (annotated)
- Committer:
- vk5653
- Date:
- Wed Feb 18 21:32:24 2015 +0000
- Revision:
- 0:cdab0c569ba7
test commit 1; ; 2/18/15
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vk5653 | 0:cdab0c569ba7 | 1 | /* Program Example 12.8: Ethernet read with display to onboard lcd |
vk5653 | 0:cdab0c569ba7 | 2 | */ |
vk5653 | 0:cdab0c569ba7 | 3 | #include "mbed.h" |
vk5653 | 0:cdab0c569ba7 | 4 | #include "C12832.h" |
vk5653 | 0:cdab0c569ba7 | 5 | |
vk5653 | 0:cdab0c569ba7 | 6 | C12832 lcd(p5, p7, p6, p8, p11); |
vk5653 | 0:cdab0c569ba7 | 7 | |
vk5653 | 0:cdab0c569ba7 | 8 | Ethernet eth; // Ethernet object |
vk5653 | 0:cdab0c569ba7 | 9 | |
vk5653 | 0:cdab0c569ba7 | 10 | char buf[0xFF]; // create a large buffer to store data |
vk5653 | 0:cdab0c569ba7 | 11 | int main() { |
vk5653 | 0:cdab0c569ba7 | 12 | lcd.locate(0,0); |
vk5653 | 0:cdab0c569ba7 | 13 | lcd.printf("Ethernet data read and display\n\r"); |
vk5653 | 0:cdab0c569ba7 | 14 | while (1) { |
vk5653 | 0:cdab0c569ba7 | 15 | int size = eth.receive(); // get size of incoming data packet |
vk5653 | 0:cdab0c569ba7 | 16 | if (size > 0) { // if packet received |
vk5653 | 0:cdab0c569ba7 | 17 | eth.read(buf, size); // read packet to data buffer |
vk5653 | 0:cdab0c569ba7 | 18 | lcd.locate(10,0); |
vk5653 | 0:cdab0c569ba7 | 19 | lcd.printf("size = %d data = ",size); // print to screen |
vk5653 | 0:cdab0c569ba7 | 20 | for (int i=0;i<size;i++) { // loop for each data byte |
vk5653 | 0:cdab0c569ba7 | 21 | lcd.locate(20,0); |
vk5653 | 0:cdab0c569ba7 | 22 | lcd.printf("%02X ",buf[i]); // print data to screen |
vk5653 | 0:cdab0c569ba7 | 23 | wait(0.33); |
vk5653 | 0:cdab0c569ba7 | 24 | } |
vk5653 | 0:cdab0c569ba7 | 25 | // pc.printf("\n\r"); |
vk5653 | 0:cdab0c569ba7 | 26 | } |
vk5653 | 0:cdab0c569ba7 | 27 | } |
vk5653 | 0:cdab0c569ba7 | 28 | } |