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.
serial.cpp
00001 /* 00002 Copyright (C) 2014 Frank Duignan 00003 00004 This program is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU General Public License 00006 as published by the Free Software Foundation; either version 2 00007 of the License, or (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; if not, write to the Free Software 00016 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 */ 00018 00019 #include "mbed.h" 00020 Serial pc(USBTX, USBRX); 00021 void eputc(const char c) 00022 { 00023 pc.putc(c); 00024 } 00025 char egetc() 00026 { 00027 if (pc.readable()) 00028 return pc.getc(); 00029 else 00030 return 0; 00031 } 00032 void eputs(const char *String) 00033 { 00034 while(*String) 00035 { 00036 eputc(*String); 00037 String++; 00038 } 00039 } 00040 00041 void printString(const char *String) 00042 { 00043 eputs(String); 00044 eputs("\r\n"); 00045 } 00046 00047 char HexDigit(int Value) 00048 { 00049 if ((Value >=0) && (Value < 10)) 00050 return Value+'0'; 00051 else 00052 return Value-10 + 'A'; 00053 } 00054 void printHex(unsigned int Number) 00055 { 00056 // Output the number over the serial port as 00057 // as hexadecimal string. 00058 char TxString[9]; 00059 int Index=8; 00060 TxString[Index]=0; // terminate the string 00061 Index--; 00062 while(Index >=0) 00063 { 00064 TxString[Index]=HexDigit(Number & 0x0f); 00065 Number = Number >> 4; 00066 Index--; 00067 } 00068 eputs(TxString); 00069 }
Generated on Thu Jul 21 2022 10:42:25 by
1.7.2