📄 f34x_uart_stdio.lst
字号:
C51 COMPILER V8.08 F34X_UART_STDIO 04/13/2008 09:11:04 PAGE 1
C51 COMPILER V8.08, COMPILATION OF MODULE F34X_UART_STDIO
OBJECT MODULE PLACED IN F34x_UART_STDIO.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE F34x_UART_STDIO.c OPTIMIZE(7,SPEED) BROWSE DEBUG OBJECTEXTEND
line level source
1 //-----------------------------------------------------------------------------
2 // Includes
3 //-----------------------------------------------------------------------------
4
5 #include <C8051F340.h> // SFR declarations
6 #include <intrins.h>
7 #include <stdio.h>
8 #include <CH423.h>
9 #include <lcd.h>
10 //-----------------------------------------------------------------------------
11 // 16-bit SFR Definitions for 'F34x
12 //-----------------------------------------------------------------------------
13
14 sfr16 SBRL1 = 0xB4;
15
16 //-----------------------------------------------------------------------------
17 // Global CONSTANTS
18 //-----------------------------------------------------------------------------
19
20 #define SYSCLK 48000000 // SYSCLK frequency in Hz
21
22 #define BAUDRATE1 115200 // Baud rate of UART1 in bps
23
24
25 //-----------------------------------------------------------------------------
26 // Function PROTOTYPES
27 //-----------------------------------------------------------------------------
28
29 void SYSTEMCLOCK_Init (void);
30 void PORT_Init (void);
31 void UART1_Init (void);
32 void Delay (void);
33
34 //-----------------------------------------------------------------------------
35 // Global VARIABLES
36 //-----------------------------------------------------------------------------
37
38
39
40 //-----------------------------------------------------------------------------
41 // SYSTEMCLOCK_Init
42 //-----------------------------------------------------------------------------
43 //
44 // Return Value : None
45 // Parameters : None
46
47 // This routine initializes the system clock to use the internal system clock
48 // routed through the clock multiplier as its clock source.
49 //
50 //-----------------------------------------------------------------------------
51
52 void SYSTEMCLOCK_Init (void)
53 {
54 1 OSCICN |= 0x03; // Configure internal oscillator for
55 1 // its maximum frequency and enable
C51 COMPILER V8.08 F34X_UART_STDIO 04/13/2008 09:11:04 PAGE 2
56 1 // missing clock detector
57 1
58 1 CLKMUL = 0x00; // Select internal oscillator as
59 1 // input to clock multiplier
60 1
61 1 CLKMUL |= 0x80; // Enable clock multiplier
62 1 Delay(); // Delay for clock multiplier to begin
63 1 CLKMUL |= 0xC0; // Initialize the clock multiplier
64 1 Delay(); // Delay for clock multiplier to begin
65 1
66 1 while(!(CLKMUL & 0x20)); // Wait for multiplier to lock
67 1 CLKSEL = 0x03; // Select system clock
68 1 }
69
70 //-----------------------------------------------------------------------------
71 // PORT_Init
72 //-----------------------------------------------------------------------------
73
74 void PORT_Init (void)
75 {
76 1
77 1 P0MDIN |= 0xFF; // Lower four pins on P0 are digital
78 1 P0MDOUT = 0xFF; //pull-push
79 1
80 1 P1MDIN |= 0xFF;
81 1 P1MDOUT = 0xFF;
82 1
83 1 P2MDOUT =0x01;
84 1
85 1 P3MDIN |= 0xFF;
86 1 P3MDOUT = 0xFF;
87 1
88 1 P0 = 0xFF;
89 1 P1 = 0xFF;
90 1 P3 = 0xff;
91 1 P0SKIP = 0xFF;
92 1 P1SKIP = 0xFF;
93 1
94 1 XBR0 = 0x00;
95 1 XBR1 = 0x40; // Enable crossbar and enable
96 1 XBR2 = 0x01; // weak pull-ups
97 1 }
98
99 //-----------------------------------------------------------------------------
100 // UART1_Init
101 //-----------------------------------------------------------------------------
102 //
103 // Return Value : None
104 // Parameters : None
105 //
106 // Configure UART1 for baudrate1 and 8-N-1.
107 //
108 //-----------------------------------------------------------------------------
109
110 void UART1_Init (void)
111 {
112 1 SMOD1 = 0x0C; // set to disable parity, 8-data bit,
113 1 // disable extra bit,
114 1 // stop bit 1 bit wide
115 1
116 1 SCON1 = 0x10; // SCON1: 8-bit variable bit rate
117 1 // level of STOP bit is ignored
C51 COMPILER V8.08 F34X_UART_STDIO 04/13/2008 09:11:04 PAGE 3
118 1 // RX enabled
119 1 // ninth bits are zeros
120 1 // clear RI0 and TI0 bits
121 1
122 1 if (SYSCLK/BAUDRATE1/2/0xFFFF < 1) {
123 2 SBRL1 = -(SYSCLK/BAUDRATE1/2);
124 2 SBCON1 |= 0x03; // set prescaler to 1
125 2 } else if (SYSCLK/BAUDRATE1/2/0xFFFF < 4) {
126 2 SBRL1 = -(SYSCLK/BAUDRATE1/2/4);
127 2 SBCON1 &= ~0x03;
128 2 SBCON1 |= 0x01; // set prescaler to 4
129 2
130 2 } else if (SYSCLK/BAUDRATE1/2/0xFFFF < 12) {
131 2 SBRL1 = -(SYSCLK/BAUDRATE1/2/12);
132 2 SBCON1 &= ~0x03; // set prescaler to 12
133 2 } else {
134 2 SBRL1 = -(SYSCLK/BAUDRATE1/2/48);
135 2 SBCON1 &= ~0x03;
136 2 SBCON1 |= 0x02; // set prescaler to 4
137 2 }
138 1
139 1 SCON1 |= 0x02; // indicate ready for TX
140 1 SBCON1 |= 0x40; // enable baud rate generator
141 1 }
142
143
144 //-----------------------------------------------------------------------------
145 // putchar
146 //-----------------------------------------------------------------------------
147 //
148 // Return Value : UART0/1 buffer value
149 // Parameters : character to be transmitted across UART0/1
150 //
151 // This is an overloaded fuction found in the stdio library. When the
152 // function putchar is called, either by user code or through calls to stdio
153 // routines such as printf, the following routine will be executed instead
154 // of the function located in the stdio library.
155 //
156 // The function checks the UART global variable to determine which UART to
157 // use to receive a character.
158 //
159 // The routine expands '\n' to include a carriage return as well as a
160 // new line character by first checking to see whether the character
161 // passed into the routine equals '\n'. If it is, the routine waits for
162 // TI0/TI1 to be set, indicating that UART 0/1 is ready to transmit another
163 // byte. The routine then clears TI0/TI1 bit, and sets the UART0/1 output
164 // buffer to '0x0d', which is the ASCII character for carriage return.
165 //
166 // The routine the waits for TI0/TI1 to be set, clears TI0/TI1, and sets
167 // the UART output buffer to <c>.
168 //
169 //-----------------------------------------------------------------------------
170
171 char putchar (char c)
172 {
173 1 if (c == '\n')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -