📄 f34x_uart_multiuart.lst
字号:
C51 COMPILER V8.08 F34X_UART_MULTIUART 07/01/2008 20:14:26 PAGE 1
C51 COMPILER V8.08, COMPILATION OF MODULE F34X_UART_MULTIUART
OBJECT MODULE PLACED IN F34x_UART_MultiUART.OBJ
COMPILER INVOKED BY: C:\SiLabs\MCU\IDEfiles\C51\BIN\C51.exe F34x_UART_MultiUART.c DB OE
line level source
1 //-----------------------------------------------------------------------------
2 // F34x_UART_MultiUART.c
3 //-----------------------------------------------------------------------------
4 // Copyright 2006 Silicon Laboratories, Inc.
5 // http://www.silabs.com
6 //
7 // Program Description:
8 //
9 // This program configures UART0 and UART1 to operate in polled mode, suitable
10 // for use with the stdio.h functions printf() and scanf().
11 //
12 // Test code is included for printf() and getchar(), and shows an example
13 // of how the putchar() and _getkey() library routines can be overridden to
14 // allow for multiple UARTs to be selected by the functions (in this example,
15 // the global variable UART is used to select between UART0 and UART1).
16 //
17 // The example sets system clock to maximum frequency of 48 MHz.
18 //
19 // The system clock frequency is stored in a global constant SYSCLK. The
20 // target UART0 baud rate is stored in a global constant BAUDRATE0, and the
21 // target UART1 baud rate is stored in a global constant BAUDRATE1.
22 //
23 //
24 // How To Test:
25 //
26 // 1) Download code to a 'F34x device that is connected to a UART transceiver
27 // 2) Connect serial cable from the transceiver to a PC
28 // 3) On the PC, open HyperTerminal (or any other terminal program) and connect
29 // to the COM port at <BAUDRATE0>/<BAUDRATE1> and 8-N-1
30 // 4) To test UART 0, place jumpers connecting P0.4 to TX and P0.5 to RX on
31 // C8051F340 Target Board header J12. To test UART 1, run wires from
32 // P0.0 on J2 to the TX pin of J12, and P0.1 on J2 to the RX pin of J12.
33 //
34 //
35 // FID: 34X000081
36 // Target: C8051F34x
37 // Tool chain: KEIL C51 7.20 / KEIL EVAL C51
38 // Silicon Laboratories IDE version 2.72
39 //
40 // Release 1.0
41 // -Initial Revision (PD)
42 // -17 JUL 2006
43 // -Initial Release
44 //
45 //
46 //-----------------------------------------------------------------------------
47 // Includes
48 //-----------------------------------------------------------------------------
49
50 #include <C8051F340.h> // SFR declarations
51 #include <stdio.h>
52
53 //-----------------------------------------------------------------------------
54 // 16-bit SFR Definitions for 'F34x
55 //-----------------------------------------------------------------------------
C51 COMPILER V8.08 F34X_UART_MULTIUART 07/01/2008 20:14:26 PAGE 2
56
57 sfr16 SBRL1 = 0xB4;
58
59 //-----------------------------------------------------------------------------
60 // Global CONSTANTS
61 //-----------------------------------------------------------------------------
62
63 #define SYSCLK 48000000 // SYSCLK frequency in Hz
64 #define BAUDRATE0 115200 // Baud rate of UART0 in bps
65 #define BAUDRATE1 115200 // Baud rate of UART1 in bps
66
67 sbit LED = P2^2; // LED = 1 means ON
68
69 //-----------------------------------------------------------------------------
70 // Function PROTOTYPES
71 //-----------------------------------------------------------------------------
72
73 void SYSTEMCLOCK_Init (void);
74 void PORT_Init (void);
75 void UART0_Init (void);
76 void UART1_Init (void);
77 void Delay (void);
78
79 //-----------------------------------------------------------------------------
80 // Global VARIABLES
81 //-----------------------------------------------------------------------------
82
83 bit UART = 0; // '0 is UART0; '1' is UART1
84
85
86 //-----------------------------------------------------------------------------
87 // MAIN Routine
88 //-----------------------------------------------------------------------------
89
90 void main (void) {
91 1 char input_char;
92 1
93 1 PCA0MD &= ~0x40; // Disable Watchdog timer
94 1
95 1 SYSTEMCLOCK_Init (); // initialize oscillator
96 1 PORT_Init (); // initialize crossbar and GPIO
97 1 UART0_Init (); // initialize UART0
98 1 UART1_Init (); // initialize UART1
99 1
100 1 // transmit example UART0
101 1 UART = 0; // select UART0
102 1 printf ("Hello, from UART0!\n");
103 1
104 1
105 1 // transmit example UART1
106 1 UART = 1; // select UART1
107 1 printf ("Hello, from UART1!\n");
108 1
109 1
110 1 // receive example: a '1' turns LED on; a '0' turns LED off.
111 1 // select which UART to receive on by changing the next line of code.
112 1
113 1 UART = 1; // select UART: 0 = UART0, 1 = UART1
114 1
115 1 while (1) {
116 2 input_char = getchar();
117 2 printf (" '%c', 0x%02x\n", (unsigned char) input_char,
C51 COMPILER V8.08 F34X_UART_MULTIUART 07/01/2008 20:14:26 PAGE 3
118 2 (unsigned) input_char);
119 2
120 2 switch (input_char) {
121 3 case '0':
122 3 LED = 0;
123 3 break;
124 3 case '1':
125 3 LED = 1;
126 3 break;
127 3 default:
128 3 break;
129 3 }
130 2
131 2 }
132 1
133 1 }
134
135 //-----------------------------------------------------------------------------
136 // Initialization Subroutines
137 //-----------------------------------------------------------------------------
138
139 //-----------------------------------------------------------------------------
140 // SYSTEMCLOCK_Init
141 //-----------------------------------------------------------------------------
142 //
143 // Return Value : None
144 // Parameters : None
145
146 // This routine initializes the system clock to use the internal system clock
147 // routed through the clock multiplier as its clock source.
148 //
149 //-----------------------------------------------------------------------------
150
151 void SYSTEMCLOCK_Init (void)
152 {
153 1 OSCICN |= 0x03; // Configure internal oscillator for
154 1 // its maximum frequency and enable
155 1 // missing clock detector
156 1
157 1 CLKMUL = 0x00; // Select internal oscillator as
158 1 // input to clock multiplier
159 1
160 1 CLKMUL |= 0x80; // Enable clock multiplier
161 1 Delay(); // Delay for clock multiplier to begin
162 1 CLKMUL |= 0xC0; // Initialize the clock multiplier
163 1 Delay(); // Delay for clock multiplier to begin
164 1
165 1 while(!(CLKMUL & 0x20)); // Wait for multiplier to lock
166 1 CLKSEL = 0x03; // Select system clock
167 1 }
168
169 //-----------------------------------------------------------------------------
170 // PORT_Init
171 //-----------------------------------------------------------------------------
172 //
173 // Return Value : None
174 // Parameters : None
175
176 // Configure the Crossbar and GPIO ports
177 //
178 // P0.0 TX1 (UART 1)
179 // P0.1 RX1 (UART 1)
C51 COMPILER V8.08 F34X_UART_MULTIUART 07/01/2008 20:14:26 PAGE 4
180 // P0.2
181 // P0.3
182 // P0.4 TX0 (UART 0)
183 // P0.5 RX0 (UART 0)
184 // P0.6
185 // P0.7
186
187 // P1 not used in this example
188
189 // P2.0
190 // P2.1
191 // P2.2 LED
192 // P2.3
193 // P2.4
194 // P2.5
195 // P2.6
196 // P2.7
197 //-----------------------------------------------------------------------------
198
199 void PORT_Init (void)
200 {
201 1 XBR0 = 0x01; // route UART 0 to crossbar
202 1 XBR2 = 0x01; // route UART 1 to crossbar
203 1 XBR1 = 0x40; // enable crossbar
204 1 P0MDOUT |= 0x11; // set P0.4 to push-pull output
205 1 P2MDOUT |= 0x04; // set LED to push-pull
206 1 }
207
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -