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 int iCounter = 0; 00055 char szReadBuffer[READBUFFERSIZE] = ""; 00056 int iIndexChar = 0; 00057 while(1) 00058 { 00059 // send 00060 g_serial.printf( "%d\n", iCounter ); 00061 iCounter++; 00062 wait(1.0); 00063 00064 // read 00065 char szLineString[READBUFFERSIZE]; 00066 if( !ReadLineString( g_serial, 00067 szReadBuffer, READBUFFERSIZE, iIndexChar, 00068 szLineString, READBUFFERSIZE ) ) 00069 { 00070 continue; 00071 } 00072 g_lcd.cls(); wait(0.001); 00073 g_lcd.locate(0, 0); 00074 g_lcd.printf( szLineString ); 00075 } 00076 }
Generated on Wed Jul 13 2022 21:12:06 by
1.7.2