* src/z80/main.c (_process_pragma, _parseOptions): fixed bug 1583318
[fw/sdcc] / device / lib / serial_io.c
1 /* Default putchar and getchar to the serial port\r
2 \r
3    Written By -  Jesus Calvino-Fraga (October/2006)\r
4 \r
5    This library is free software; you can redistribute it and/or\r
6    modify it under the terms of the GNU Lesser General Public\r
7    License as published by the Free Software Foundation; either\r
8    version 2.1 of the License, or (at your option) any later version.\r
9 \r
10    This library is distributed in the hope that it will be useful,\r
11    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
13    Lesser General Public License for more details.\r
14 \r
15    You should have received a copy of the GNU Lesser General Public\r
16    License along with this library; if not, write to the Free Software\r
17    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA\r
18 */\r
19 \r
20 #ifdef SDCC_mcs51\r
21 #include <8051.h>\r
22 \r
23 bit serial_init_flag=0;\r
24 \r
25 void init_serial (void)\r
26 {\r
27         TR1=0;\r
28         TMOD=(TMOD&0x0f)|0x20;\r
29         PCON|=0x80;\r
30         TH1=TL1=0xff; //115200 baud with a 22MHz crystal \r
31         TR1=1;\r
32         SCON=0x52;\r
33         serial_init_flag=1;\r
34 }\r
35 \r
36 void putchar (char c)\r
37 {\r
38         if(!serial_init_flag) init_serial();\r
39         if (c=='\n')\r
40         {\r
41                 while (!TI);\r
42                 TI=0;\r
43                 SBUF='\r';\r
44         }\r
45         while (!TI);\r
46         TI=0;\r
47         SBUF=c;\r
48 }\r
49 \r
50 char getchar (void)\r
51 {\r
52         char c;\r
53         \r
54         if(!serial_init_flag) init_serial();\r
55 \r
56         while (!RI);\r
57         RI=0;\r
58         c=SBUF;\r
59         return c;\r
60 }\r
61 #endif\r