From 1a30a6f3480b6a5aae015d9eacf173527a615886 Mon Sep 17 00:00:00 2001 From: jesusc Date: Tue, 24 Oct 2006 08:20:54 +0000 Subject: [PATCH] Added device/lib/serial_io.c: Default putchar() and getchar() for mcs51 uses serial port. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4433 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 5 ++++ device/lib/Makefile.in | 2 +- device/lib/libsdcc.lib | 1 + device/lib/serial_io.c | 61 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 device/lib/serial_io.c diff --git a/ChangeLog b/ChangeLog index 9612f9af..776b3728 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-10-24 Jesus Calvino-Fraga + + * device/lib/serial_io.c: Default putchar() and getchar() for + mcs51 uses serial port. + 2006-10-23 Maarten Brock * src/mcs51/gen.c (movc): improved check for 0 and 1, see RFE 1582704 diff --git a/device/lib/Makefile.in b/device/lib/Makefile.in index a41c7d17..6a0ab9c1 100644 --- a/device/lib/Makefile.in +++ b/device/lib/Makefile.in @@ -69,7 +69,7 @@ OPT_DISABLE_Z80 = @OPT_DISABLE_Z80@ SOURCES = _autobaud.c _bp.c _decdptr.c \ _gptrget.c _gptrgetc.c _gptrput.c \ _ser.c _setjmp.c \ - serial.c ser_ir.c \ + serial.c serial_io.c ser_ir.c \ _atof.c _atoi.c _atol.c _itoa.c _ltoa.c \ _schar2fs.c _sint2fs.c _slong2fs.c \ _uchar2fs.c _uint2fs.c _ulong2fs.c \ diff --git a/device/lib/libsdcc.lib b/device/lib/libsdcc.lib index eaad6ac5..fc6cf879 100644 --- a/device/lib/libsdcc.lib +++ b/device/lib/libsdcc.lib @@ -44,6 +44,7 @@ malloc realloc free serial +serial_io _autobaud _startup _ser diff --git a/device/lib/serial_io.c b/device/lib/serial_io.c new file mode 100644 index 00000000..29ad7460 --- /dev/null +++ b/device/lib/serial_io.c @@ -0,0 +1,61 @@ +/* Default putchar and getchar to the serial port + + Written By - Jesus Calvino-Fraga (October/2006) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifdef SDCC_mcs51 +#include <8051.h> + +bit serial_init_flag=0; + +void init_serial (void) +{ + TR1=0; + TMOD=(TMOD&0x0f)|0x20; + PCON|=0x80; + TH1=TL1=0xff; //115200 baud with a 22MHz crystal + TR1=1; + SCON=0x52; + serial_init_flag=1; +} + +void putchar (char c) +{ + if(!serial_init_flag) init_serial(); + if (c=='\n') + { + while (!TI); + TI=0; + SBUF='\r'; + } + while (!TI); + TI=0; + SBUF=c; +} + +char getchar (void) +{ + char c; + + if(!serial_init_flag) init_serial(); + + while (!RI); + RI=0; + c=SBUF; + return c; +} +#endif -- 2.30.2