📄 uart.lst
字号:
C51 COMPILER V7.20 UART 01/31/2007 10:20:44 PAGE 1
C51 COMPILER V7.20, COMPILATION OF MODULE UART
OBJECT MODULE PLACED IN UART.OBJ
COMPILER INVOKED BY: D:\Program Files\Keil\C51\BIN\c51.exe UART.c DB OE
line level source
1 /****************************************************************************
2 **
3 ** 文件名: UART.c
4 ** 功能: C8051Fxxx串口驱动;
5 ** 创建时间:2005.08.05
6
7 ** 修改时间:2006.08.28
8 ** 修改说明:
9
10 ** 作者: 李立学
11 ** 版权申明:可以拷贝,可以修改,但必须保留修改时间和作者信息
12 **
13 ****************************************************************************/
14
15
16 #include "LZK.H"
17
18
19 /****************************************************************************
20 ** 函数名称: UART0_Init()
21 ** 功能描述: 串口0初始化.
22 ** 入口参数: 无
23 ** 出口参数: 无
24 ** 说明: 设置工作模式和波特率等,禁止波特率加倍方式.
25 ****************************************************************************/
26 void UART0_Init(void) // USE T4,初始化为19200bps
27 {
28 1 SFRPAGE = UART0_PAGE;
29 1 SCON0 = 0x70; // 0111_0000
30 1 // SCON0(00000000): UART0 Control Register.
31 1 // Bits7-6: SM00-SM10: Serial Port Operation Mode.
32 1 // 00 Mode 0: Synchronous Mode
33 1 // 01 Mode 1: 8-Bit UART, Variable Baud Rate
34 1 // 10 Mode 2: 9-Bit UART, Fixed Baud Rate
35 1 // 11 Mode 3: 9-Bit UART, Variable Baud Rate
36 1 // Bit5: SM20: Multiprocessor Communication Enable.
37 1 // Under Mode 0: No effect
38 1 // Mode 1: Checks for valid stop bit.
39 1 // Mode 2 and 3: Multiprocessor Communications Enable.
40 1 // Bit4: REN0: Receive Enable.
41 1 // Bit3: TB80: Ninth Transmission Bit.
42 1 // Bit2: RB80: Ninth Receive Bit.
43 1 // Bit1: TI0: Transmit Interrupt Flag.
44 1 // Bit0: RI0: Receive Interrupt Flag.
45 1 SSTA0 = 0x0f; // 0000_1111
46 1 // SSTA0(00000000): UART0 Status and Clock Selection Register.
47 1 // Bit7: FE0: Frame Error Flag.
48 1 // Bit6: RXOV0: Receive Overrun Flag.
49 1 // Bit5: TXCOL0: Transmit Collision Flag.
50 1 // Bit4: SMOD0: UART0 Baud Rate Doubler Enable.
51 1 // Bits3-2: UART0 Transmit Baud Rate Clock Selection Bits.
52 1 // 00 Timer 1 generates UART0 TX Baud Rate
53 1 // 01 Timer 2 Overflow generates UART0 TX baud rate
54 1 // 10 Timer 3 Overflow generates UART0 TX baud rate
55 1 // 11 Timer 4 Overflow generates UART0 TX baud rate
C51 COMPILER V7.20 UART 01/31/2007 10:20:44 PAGE 2
56 1 // Bits1-0: UART0 Receive Baud Rate Clock Selection Bits.
57 1 // 00 Timer 1 generates UART0 RX Baud Rate
58 1 // 01 Timer 2 Overflow generates UART0 RX baud rate
59 1 // 10 Timer 3 Overflow generates UART0 RX baud rate
60 1 // 11 Timer 4 Overflow generates UART0 RX baud rate
61 1 // SBUF0: UART0 Data Buffer Register.
62 1 // SADDR0: UART0 Slave Address Register.
63 1 // SADEN0: UART0 Slave Address Enable Register.
64 1 SFRPAGE = 0x00;
65 1 }
66
67
68 /****************************************************************************
69 ** 函数名称: UART0_SetBaudRate()
70 ** 功能描述: 串口0波特率设置.
71 ** 入口参数: uiBaudRate,波特率,如9600等.
72 ** 出口参数: 无
73 ** 全局变量: 使用定时器T4.
74 ** 调用模块: 无
75 ****************************************************************************/
76 void UART0_SetBaudRate(uint16 uiBaudRate) // Using T4.
77 {
78 1 switch(uiBaudRate)
79 1 {
80 2 case 19200: SFRPAGE = TMR4_PAGE;
81 2 RCAP4L = 0xD9; // 0xFFB2.
82 2 RCAP4H = 0xFF;
83 2 SFRPAGE = 0x00;
84 2 break;
85 2 case 9600: SFRPAGE = TMR4_PAGE; // 0xFF64.
86 2 RCAP4L = 0xB2;
87 2 RCAP4H = 0xFF;
88 2 SFRPAGE = 0x00;
89 2 break;
90 2 case 4800: SFRPAGE = TMR4_PAGE; // 0xFEC8.
91 2 RCAP4L = 0x64;
92 2 RCAP4H = 0xFF;
93 2 SFRPAGE = 0x00;
94 2 break;
95 2 case 2400: SFRPAGE = TMR4_PAGE; // 0xFD8F.
96 2 RCAP4L = 0xC8;
97 2 RCAP4H = 0xFE;
98 2 SFRPAGE = 0x00;
99 2 break;
100 2 default: break;
101 2 }
102 1 }
103
104 /****************************************************************************
105 ** 函数名称: UART1_Init()
106 ** 功能描述: 串口1初始化,固定为19200bps
107 ** 入口参数: 无
108 ** 出口参数: 无
109 ** 说明: 设置工作模式,定义波特率发生器等.1START_8BIT_1STOP_NOP.
110 ****************************************************************************/
111 void UART1_Init(void) // USE T1,57600bps
112 {
113 1 SFRPAGE = UART1_PAGE;
114 1 SCON1 = 0x10; // 0011_0000
115 1 // SCON1(0000000): Serial Port 1 Control Register.
116 1 // Bit7: S1MODE: Serial Port 1 Operation Mode.
117 1 // 0/1: 8-bit / 9-bit UART with Variable Baud Rate.
C51 COMPILER V7.20 UART 01/31/2007 10:20:44 PAGE 3
118 1 // Bit6: UNUSED. Read = 1b. Write = don’t care.
119 1 // Bit5: MCE1: Multiprocessor Communication Enable.
120 1 // Bit4: REN1: Receive Enable.
121 1 // Bit3: TB81: Ninth Transmission Bit.
122 1 // Bit2: RB81: Ninth Receive Bit.
123 1 // Bit1: TI1: Transmit Interrupt Flag, MUST be cleared manually by software.
124 1 // Bit0: RI1: Receive Interrupt Flag, MUST be cleared manually by software.
125 1
126 1 // SBUF1: Serial (UART1) Port Data Buffer Register
127 1 SFRPAGE = 0x00;
128 1 }
129
130 /****************************************************************************
131 ** 函数名称: UART0_SendByte()
132 ** 功能描述: 串口0发送1个字节.
133 ** 入口参数: ucDATA(要发送的数据)
134 ** 出口参数: 无
135 ** 说明:
136 ****************************************************************************/
137 bit UART0_SendByte(uint8 ucDATA)
138 {
139 1 uint16 data TimOutCnt;
140 1
141 1 SFRPAGE = UART0_PAGE;
142 1 TimOutCnt = 0;
143 1
144 1 TI0 = 0;
145 1 SBUF0 = ucDATA;
146 1 while( TI0 != 1 )
147 1 {
148 2 TimOutCnt++;
149 2 if(TimOutCnt > 50000) //
150 2 return 1; // Time OUT!
151 2 }
152 1
153 1 SFRPAGE = 0x00;
154 1 return 0;
155 1 }
156
157 /****************************************************************************
158 ** 函数名称: UART0_RecvByte()
159 ** 功能描述: 串口0接收1个字节.
160 ** 入口参数: 无
161 ** 出口参数: 接收到的数据,否则返回0x8000.
162 ** 说明:
163 ****************************************************************************/
164 uint16 UART0_RecvByte(void)
165 {
166 1 uint16 data TimOutCnt;
167 1 uint8 data ucTMP;
168 1
169 1 SFRPAGE = UART0_PAGE;
170 1 TimOutCnt = 0;
171 1
172 1 RI0 = 0;
173 1 while( RI0 != 1 ) // Wait for
174 1 {
175 2 TimOutCnt++;
176 2 if(TimOutCnt > 50000)
177 2 return 0x8000; // Time OUT!
178 2 }
179 1 ucTMP = SBUF0; // Receive DATA
C51 COMPILER V7.20 UART 01/31/2007 10:20:44 PAGE 4
180 1
181 1 SFRPAGE = 0x00;
182 1 return ucTMP;
183 1 }
184
185 /****************************************************************************
186 ** 函数名称: UART1_SendByte()
187 ** 功能描述: 串口1发送1个字节.
188 ** 入口参数: ucDATA(要发送的数据)
189 ** 出口参数: 无
190 ** 说明:
191 ****************************************************************************/
192 bit UART1_SendByte(uint8 ucDATA)
193 {
194 1 uint16 data TimOutCnt;
195 1
196 1 SFRPAGE = UART1_PAGE;
197 1 TimOutCnt = 0;
198 1
199 1 TI1 = 0;
200 1 SBUF1 = ucDATA;
201 1 while( TI1 != 1)
202 1 {
203 2 TimOutCnt++;
204 2 if( TimOutCnt > 5000 )
205 2 return 1; // Time OUT!
206 2 }
207 1
208 1 SFRPAGE = 0x00;
209 1 return 0;
210 1 }
211
212 /****************************************************************************
213 ** 函数名称: UART1_RecvByte()
214 ** 功能描述: 串口1接收1个字节.
215 ** 入口参数: 无
216 ** 出口参数: 接收到的数据,否则返回0x8000.
217 ** 说明:
218 ****************************************************************************/
219 uint16 UART1_RecvByte(void)
220 {
221 1 uint8 data TimOutCnt;
222 1 uint8 data ucTMP;
223 1
224 1 SFRPAGE = UART1_PAGE;
225 1 TimOutCnt = 0;
226 1
227 1 RI1 = 0;
228 1 while( RI1 != 1 ) // Wait for
229 1 {
230 2 TimOutCnt++;
231 2 if( TimOutCnt > 5000 )
232 2 return 0x8000; // Time OUT!
233 2 }
234 1 ucTMP = SBUF1; // Receive DATA
235 1 RI1 = 0;
236 1
237 1 SFRPAGE = 0x00;
238 1 return ucTMP;
239 1 }
240
241 /************************************************************
C51 COMPILER V7.20 UART 01/31/2007 10:20:44 PAGE 5
242 ********* UART的中断服务程序入口 ****************************
243 *************************************************************
244 void UART1_ISR(void) interrupt 20
245 {
246 }
247
248 void UART0_ISR(void) interrupt 4
249 {
250 }
251 ***********************************************************/
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 241 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -