Charles Tritt
/
SerialEcho_UC
Echos ASCII message converted to uppercase. Uses toupper function from standard C library.
main.cpp@4:0ed7a3594910, 2019-02-11 (annotated)
- Committer:
- CSTritt
- Date:
- Mon Feb 11 18:51:56 2019 +0000
- Revision:
- 4:0ed7a3594910
- Parent:
- 3:041d6aaa4a7b
Initial version. Echos ASCII message, converted to upper case.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
CSTritt | 1:ea72a608382f | 1 | /* |
CSTritt | 2:e53dfe50252a | 2 | Project: SerialEcho |
CSTritt | 1:ea72a608382f | 3 | File: main.cpp |
CSTritt | 1:ea72a608382f | 4 | Created by: Dr. C. S. Tritt |
CSTritt | 3:041d6aaa4a7b | 5 | Last revised: 1/17/19 (v. 1.0) |
CSTritt | 1:ea72a608382f | 6 | |
CSTritt | 2:e53dfe50252a | 7 | Receives serial data from PC to and echos it back, character for character. |
CSTritt | 1:ea72a608382f | 8 | |
CSTritt | 1:ea72a608382f | 9 | Tera Term configurations |
CSTritt | 1:ea72a608382f | 10 | Terminal - New-line, Receive LF, Transmit LF |
CSTritt | 1:ea72a608382f | 11 | Serial port - Data 8 bit, Parity none, Stop 1 bit, Flow control none. |
CSTritt | 1:ea72a608382f | 12 | Baud as specified below. |
CSTritt | 1:ea72a608382f | 13 | */ |
CSTritt | 4:0ed7a3594910 | 14 | #include <cctype> |
CSTritt | 0:2f9e67d4c561 | 15 | #include "mbed.h" |
CSTritt | 0:2f9e67d4c561 | 16 | |
CSTritt | 1:ea72a608382f | 17 | Serial pc(USBTX, USBRX, 9600); // Standard to PC via USB channel. |
CSTritt | 0:2f9e67d4c561 | 18 | |
CSTritt | 3:041d6aaa4a7b | 19 | DigitalOut actLED(LED1); // Activity LED. |
CSTritt | 0:2f9e67d4c561 | 20 | |
CSTritt | 0:2f9e67d4c561 | 21 | int main() |
CSTritt | 0:2f9e67d4c561 | 22 | { |
CSTritt | 1:ea72a608382f | 23 | while (true) { |
CSTritt | 1:ea72a608382f | 24 | if (pc.readable()) { |
CSTritt | 4:0ed7a3594910 | 25 | char myChar = (char) pc.getc(); // Get a char from the PC. |
CSTritt | 4:0ed7a3594910 | 26 | myChar = std::toupper(myChar); |
CSTritt | 4:0ed7a3594910 | 27 | pc.putc(myChar); // Send it back to the PC. |
CSTritt | 3:041d6aaa4a7b | 28 | actLED = !actLED; // Toggle the activity LED. |
CSTritt | 1:ea72a608382f | 29 | } |
CSTritt | 0:2f9e67d4c561 | 30 | } |
CSTritt | 0:2f9e67d4c561 | 31 | } |