1 /*-------------------------------------------------------------------------
2 _ser.c - this file contains a simple interrupt driven serial driver with
3 buffer (no check for overflow!!!).
5 Copyright (C) 1999, Sandeep Dutta <sandeep.dutta AT ieee.org>
7 This library is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this library; see the file COPYING. If not, write to the
19 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
22 As a special exception, if you link this library with other files,
23 some of which are compiled with SDCC, to produce an executable,
24 this library does not by itself cause the resulting executable to
25 be covered by the GNU General Public License. This exception does
26 not however invalidate any other reasons why the executable file
27 might be covered by the GNU General Public License.
28 -------------------------------------------------------------------------*/
30 /*KA******************************************************************
31 * PROJECT: PL-One/8052
32 **********************************************************************
34 **********************************************************************
36 * date author description
37 * --------------------------------------------------------------------
39 * 04/27/99 we comments
40 **********************************************************************
42 * This file contains a simple interrupt driven serial driver with
43 * buffer (no check for overflow!!!).
44 **********************************************************************
46 * ser_init Initialization; must be called first
47 * ser_putc output one char on the serial line
48 * ser_getc return a char if one has been received, else 0
49 * ser_printString print a 0-terminated string
50 * ser_charAvail return 1 if a char arrived on serial line
51 **********************************************************************
53 * Remember to enable all interrupts (EA=1) outside of this module!!
54 **********************************************************************
55 * COMPILE TIME OPTIONS: -
57 ******************************************************************KE*/
65 unsigned char __xdata ser_txIndexIn
;
66 unsigned char __xdata ser_txIndexOut
;
67 unsigned char __xdata ser_rxIndexIn
;
68 unsigned char __xdata ser_rxIndexOut
;
70 unsigned char __xdata ser_txBuffer
[0x100];
71 unsigned char __xdata ser_rxBuffer
[0x100];
73 static __bit ser_txBusy
;
89 /* Baudrate = 19200, oscillator frq. of my processor is 21.4772 MHz */
109 ser_interrupt_handler(void) __interrupt (4) __using (1)
115 ser_rxBuffer
[ser_rxIndexIn
++] = SBUF
;
120 if (ser_txIndexIn
== ser_txIndexOut
) {
124 SBUF
= ser_txBuffer
[ser_txIndexOut
++];
132 ser_putc(unsigned char c
)
137 ser_txBuffer
[ser_txIndexIn
++] = c
;
153 if (ser_rxIndexIn
!= ser_rxIndexOut
) {
154 tmp
= ser_rxBuffer
[ser_rxIndexOut
++];
165 ser_printString(char *String
)
177 if (ser_rxIndexIn
!= ser_rxIndexOut
) {
184 /*********************End of File************************************/