device/include/mcs51/serial_IO.h: putchar() and getchar() using serial port.
authorjesusc <jesusc@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 29 Oct 2006 20:55:38 +0000 (20:55 +0000)
committerjesusc <jesusc@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 29 Oct 2006 20:55:38 +0000 (20:55 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4444 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
device/include/mcs51/serial_IO.h [new file with mode: 0644]

index 6a81142756ec1b02a6eab2e4a85ff9296c94fbbc..1120cd0ea43d06bbbc761b27be1c6b23ec346429 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2006-10-29 Jesus Calvino-Fraga <jesusc at ece.ubc.ca>
+
+       * device/include/mcs51/serial_IO.h: putchar() and getchar() using
+         serial port.
+
 2006-10-29 Maarten Brock <sourceforge.brock AT dse.nl>
 
        * device/include/malloc.h,
diff --git a/device/include/mcs51/serial_IO.h b/device/include/mcs51/serial_IO.h
new file mode 100644 (file)
index 0000000..0922f95
--- /dev/null
@@ -0,0 +1,76 @@
+/* Default putchar() and getchar() to the serial port\r
+\r
+   Written By -  Jesus Calvino-Fraga (October/2006)\r
+\r
+   This library is free software; you can redistribute it and/or\r
+   modify it under the terms of the GNU Lesser General Public\r
+   License as published by the Free Software Foundation; either\r
+   version 2.1 of the License, or (at your option) any later version.\r
+\r
+   This library is distributed in the hope that it will be useful,\r
+   but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+   Lesser General Public License for more details.\r
+\r
+   You should have received a copy of the GNU Lesser General Public\r
+   License along with this library; if not, write to the Free Software\r
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA\r
+*/\r
+\r
+#ifndef SERIAL_IO_H\r
+#define SERIAL_IO_H\r
+\r
+__sfr __at (0x87) SIO_PCON;\r
+__sfr __at (0x89) SIO_TMOD;\r
+__sfr __at (0x8D) SIO_TH1;\r
+__sfr __at (0x8B) SIO_TL1;\r
+__sfr __at (0x98) SIO_SCON;\r
+__sfr __at (0x99) SIO_SBUF;\r
+__sbit __at (0x8E) SIO_TR1;\r
+\r
+/*SCON bits*/\r
+__sbit __at (0x98) SIO_RI;\r
+__sbit __at (0x99) SIO_TI;\r
+__sbit __at (0x9A) SIO_RB8;\r
+__sbit __at (0x9B) SIO_TB8;\r
+__sbit __at (0x9C) SIO_REN;\r
+__sbit __at (0x9D) SIO_SM2;\r
+__sbit __at (0x9E) SIO_SM1;\r
+__sbit __at (0x9F) SIO_SM0;\r
+\r
+void inituart (unsigned char t1_reload)\r
+{\r
+       SIO_TR1=0;\r
+       SIO_TMOD=(SIO_TMOD&0x0f)|0x20;\r
+       SIO_PCON|=0x80;\r
+       SIO_TH1=SIO_TL1=t1_reload;\r
+       SIO_TR1=1;\r
+       SIO_SCON=0x52;\r
+}\r
+\r
+void putchar (char c)\r
+{\r
+       if((!SIO_SM0)&&(!SIO_SM1)) inituart(0xff);\r
+       if (c=='\n')\r
+       {\r
+               while (!SIO_TI);\r
+               SIO_TI=0;\r
+               SIO_SBUF='\r';\r
+       }\r
+       while (!SIO_TI);\r
+       SIO_TI=0;\r
+       SIO_SBUF=c;\r
+}\r
+\r
+char getchar (void)\r
+{\r
+       char c;\r
+       \r
+       if((!SIO_SM0)&&(!SIO_SM1)) inituart(0xff);\r
+\r
+       while (!SIO_RI);\r
+       SIO_RI=0;\r
+       c=SIO_SBUF;\r
+       return c;\r
+}\r
+#endif\r