-
- printf("\r\n====== openMSP430 in action ======\r\n"); //say hello
- printf("\r\nSimple Line Editor Ready\r\n"); //say hello
-
- printf("\n[QCount = 0x%08lX]\n", qcount());
-
- while (1) { //main loop, never ends...
- printf("> "); //show prompt
- reading = 1;
- while (reading) { //loop and read characters
- LPM0; //sync, wakeup by irq
-
- led++; // Some lighting...
- if (led==9) {
- led = 0;
- }
- P3OUT = (0x01 << led);
-
- switch (rxdata) {
- //process RETURN key
- case '\r':
- //case '\n':
- printf("\r\n"); //finish line
- buf[pos++] = 0; //to use printf...
- printf(":%s\r\n", buf);
- reading = 0; //exit read loop
- pos = 0; //reset buffer
- break;
- //backspace
- case '\b':
- if (pos > 0) { //is there a char to delete?
- pos--; //remove it in buffer
- putchar('\b'); //go back
- putchar(' '); //erase on screen
- putchar('\b'); //go back
- }
- break;
- //other characters
- default:
- //only store characters if buffer has space
- if (pos < sizeof(buf)) {
- putchar(rxdata); //echo
- buf[pos++] = rxdata; //store
- }
- }
- }