summaryrefslogtreecommitdiff
path: root/firmware/serial.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/serial.c')
-rw-r--r--firmware/serial.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/firmware/serial.c b/firmware/serial.c
new file mode 100644
index 0000000000..1269083aab
--- /dev/null
+++ b/firmware/serial.c
@@ -0,0 +1,82 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Alan Korr
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include <serial.h>
21#include <lcd.h>
22
23#define TDRE 7 /* transmit data register empty */
24#define RDRF 6 /* receive data register full */
25#define ORER 5 /* overrun error */
26#define FER 4 /* frame error */
27#define PER 3 /* parity error */
28
29static int serial_byte,serial_flag;
30
31void serial_putc (char byte)
32 {
33 static int i = 0;
34 while (!(QI(SCISSR1) & (1<<TDRE)));
35 QI(SCITDR1) = byte;
36 clear_bit (TDRE,SCISSR1);
37 lcd_goto ((i++)%11,1); lcd_putc (byte);
38 }
39
40void serial_puts (char const *string)
41 {
42 int byte;
43 while ((byte = *string++))
44 serial_putc (byte);
45 }
46
47int serial_getc( void )
48 {
49 int byte;
50 while (!serial_flag);
51 byte = serial_byte;
52 serial_flag = 0;
53 serial_putc (byte);
54 return byte;
55 }
56
57void serial_setup (int baudrate)
58 {
59 QI(SCISCR1) =
60 QI(SCISSR1) =
61 QI(SCISMR1) = 0;
62 QI(SCIBRR1) = (PHI/(32*baudrate))-1;
63 QI(SCISCR1) = 0x70;
64 }
65
66#pragma interrupt
67void REI1 (void)
68 {
69 clear_bit (FER,SCISSR1);
70 }
71
72#pragma interrupt
73void RXI1 (void)
74 {
75 serial_byte = QI(SCIRDR1);
76 serial_flag = 1;
77 clear_bit (RDRF,SCISSR1);
78 if (serial_byte == '0')
79 lcd_turn_off_backlight ();
80 if (serial_byte == '1')
81 lcd_turn_on_backlight ();
82 }