Initialize uart only if SM0 and SM1 are zero. Also, use flag 'putchar_crlf' to turn...
[fw/sdcc] / device / lib / _putchar.c
1 /* Default polling putchar() using 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 putchar_crlf=0;\r
24 void inituart(unsigned char t1_reload);\r
25 \r
26 void putchar (char c)\r
27 {\r
28         if((!SM0)&&(!SM1)) inituart(0xff);\r
29         if ((c=='\n') && putchar_crlf)\r
30         {\r
31                 while (!TI);\r
32                 TI=0;\r
33                 SBUF='\r';\r
34         }\r
35         while (!TI);\r
36         TI=0;\r
37         SBUF=c;\r
38 }\r
39 \r
40 #endif\r