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.
main.cpp
00001 #include "mbed.h" 00002 #include "TextLCD.h" 00003 00004 #define READBUFFERSIZE (32) 00005 00006 Serial g_serial(USBTX, USBRX); 00007 TextLCD g_lcd(p15, p16, p17, p18, p19, p20); // RS, E, DB4, DB5, DB6, DB7 00008 00009 int ReadLineString( Serial& serial, 00010 char szReadBuffer[], const int ciReadBufferSize, int& riIndexChar, 00011 char szLineString[], const int ciLineStringSize ) 00012 { 00013 while( 1 ) 00014 { 00015 if( !serial.readable() ) 00016 { 00017 break; 00018 } 00019 char c = serial.getc(); 00020 if( '\r' == c ) 00021 { 00022 szReadBuffer[riIndexChar] = '\0'; 00023 strncpy( szLineString, szReadBuffer, ciLineStringSize - 1 ); 00024 szLineString[ciLineStringSize - 1] = '\0'; 00025 riIndexChar = 0; 00026 return 1; 00027 } 00028 else if( '\n' == c ) 00029 { 00030 ; 00031 } 00032 else 00033 { 00034 if( (ciReadBufferSize - 1) > riIndexChar ) 00035 { 00036 szReadBuffer[riIndexChar] = c; 00037 riIndexChar++; 00038 } 00039 } 00040 } 00041 00042 return 0; 00043 } 00044 00045 int main() 00046 { 00047 // setup 00048 g_serial.baud(9600); 00049 wait(0.001); 00050 g_lcd.cls(); wait(0.001); 00051 g_lcd.printf( "(ready)" ); 00052 00053 // loop 00054 char szReadBuffer[READBUFFERSIZE] = ""; 00055 int iIndexChar = 0; 00056 while(1) 00057 { 00058 char szLineString[READBUFFERSIZE]; 00059 if( !ReadLineString( g_serial, 00060 szReadBuffer, READBUFFERSIZE, iIndexChar, 00061 szLineString, READBUFFERSIZE ) ) 00062 { 00063 continue; 00064 } 00065 g_lcd.cls(); wait(0.001); 00066 g_lcd.locate(0, 0); 00067 g_lcd.printf( szLineString ); 00068 } 00069 }
Generated on Sat Jul 23 2022 06:40:02 by
1.7.2