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.c
00001 #include "mbed.h" 00002 #include "useful.h" 00003 00004 Serial rs232(p13, p14); // tx, rx 00005 /******************************************/ 00006 /* */ 00007 /* Test the RS232 interface */ 00008 /* Should send and recieve data on the */ 00009 /* serial port, send a string, and get */ 00010 /* back what is returned from the RX */ 00011 /* */ 00012 /******************************************/ 00013 void rs232_opener(void) 00014 { 00015 rs232.baud(9600); 00016 rs232.printf("\n\r"); 00017 rs232.printf("Dome Controler\n\r"); 00018 rs232.printf("\n\rCMD > "); 00019 } 00020 00021 void rs232_output_string(char *buf) 00022 { 00023 int a = 0; 00024 while(a != strlen(buf)){ 00025 rs232.putc(buf[a]); 00026 if(buf[a]=='\n') 00027 rs232.putc('\r'); 00028 a++; 00029 } 00030 } 00031 00032 int rs232_readable(void) 00033 { 00034 return(rs232.readable()); 00035 } 00036 00037 int rs232_gets(char *s,int len) 00038 { 00039 char c; 00040 int cnt=0; 00041 00042 while ((c = rs232.getc()) != 0) { 00043 if ((c == 0x0a) || (c==0x0d)) { 00044 rs232.printf("\n\r"); 00045 *s++ = '\0'; 00046 return(cnt); /* Return length */ 00047 } else if (c==0x7f) { /* Delete */ 00048 rs232.putc(0x08); 00049 rs232.putc(0x20); 00050 rs232.putc(0x08); 00051 cnt--; 00052 *s--; 00053 } else if (c==0x08) { /* BS */ 00054 rs232.putc(0x08); 00055 rs232.putc(0x20); 00056 rs232.putc(0x08); 00057 cnt--; 00058 *s--; 00059 } else if (c==025) { /* CTRL-U */ 00060 while (cnt!=0) { 00061 rs232.putc(0x08); 00062 rs232.putc(0x20); 00063 rs232.putc(0x08); 00064 cnt--; 00065 *s--; 00066 } 00067 } else { 00068 *s++ = c; 00069 rs232.putc(c); 00070 cnt++; 00071 } 00072 } 00073 return(cnt); 00074 } 00075 00076 /******************************************/ 00077 /* */ 00078 /* Set the baud rate of the serial line */ 00079 /* from the command line input */ 00080 /* */ 00081 /******************************************/ 00082 #define BAUD_NUMBER 10 00083 void baud_rate(int c, char **a) 00084 { 00085 int b,cnt; 00086 int v[BAUD_NUMBER] = {300,600,1200,2400,4800,9600,19200,38400,57600,15200}; 00087 00088 b = atoi(a[1]); 00089 cnt = 0; 00090 while(cnt < BAUD_NUMBER){ 00091 if(v[cnt]==b){ 00092 rs232.baud(b); 00093 return; 00094 } 00095 cnt++; 00096 } 00097 cnt=0; 00098 lprintf("Select a speed from "); 00099 while(cnt < BAUD_NUMBER){ 00100 lprintf("%d ",v[cnt]); 00101 cnt++; 00102 } 00103 lprintf("\n\r"); 00104 } 00105 00106 void serial_test(int c, char **a) 00107 { 00108 char ch; 00109 00110 rs232_output_string("Serial Test Routine\n\r"); 00111 00112 while(1){ 00113 ch = rs232.getc(); 00114 printf("Got %c\n\r",ch); 00115 if(ch=='q') 00116 return; 00117 } 00118 }
Generated on Mon Jul 18 2022 01:14:06 by
1.7.2