📄 uart.lst
字号:
C51 COMPILER V8.05a UART 04/21/2009 19:44:21 PAGE 1
C51 COMPILER V8.05a, COMPILATION OF MODULE UART
OBJECT MODULE PLACED IN UART.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE UART.c BROWSE DEBUG OBJECTEXTEND
line level source
1 /******************************************************************
2 本程序只供学习使用,未经作者许可,不得用于其它任何用途
3
4 欢迎访问我的USB专区:http://group.ednchina.com/93/
5 欢迎访问我的blog: http://www.ednchina.com/blog/computer00
6 http://computer00.21ic.org
7
8 感谢PCB赞助商——电子园: http://bbs.cepark.com/
9
10 UART.C file
11
12 作者:电脑圈圈
13 建立日期: 2008.06.27
14 修改日期: 2008.07.10
15 版本:V1.1
16 版权所有,盗版必究。
17 Copyright(C) 电脑圈圈 2008-2018
18 All rights reserved
19 *******************************************************************/
20
21 #include <at89x52.H>
22
23 #include "UART.h"
24 #include "MyType.h"
25 #include "config.h"
26
27 idata uint8 UartBuffer[BUF_LEN];
28 idata uint8 UsbEp2Buffer[BUF_LEN];
29
30 uint8 UartBufferOutputPoint;
31 uint8 UartBufferInputPoint;
32 uint8 UsbEp2BufferOutputPoint;
33
34 uint8 UartByteCount;
35 uint8 UsbEp2ByteCount;
36
37 volatile uint8 Sending;
38
39
40 /********************************************************************
41 函数功能:串口初始化。
42 入口参数:无。
43 返 回:无。
44 备 注:无。
45 ********************************************************************/
46 void InitUART(void)
47 {
48 1 EA=0; //暂时关闭中断
49 1 TMOD&=0x0F; //定时器1模式控制在高4位
50 1 TMOD|=0x20; //定时器1工作在模式2,自动重装模式
51 1 SCON=0x50; //串口工作在模式1
52 1 TH1=256-Fclk/(BitRate*12*16); //计算定时器重装值
53 1 TL1=256-Fclk/(BitRate*12*16);
54 1 PCON|=0x80; //串口波特率加倍
55 1 ES=1; //串行中断允许
C51 COMPILER V8.05a UART 04/21/2009 19:44:21 PAGE 2
56 1 TR1=1; //启动定时器1
57 1 REN=1; //允许接收
58 1 EA=1; //允许中断
59 1 }
60 ////////////////////////End of function//////////////////////////////
61
62 /********************************************************************
63 函数功能:串口中断处理。
64 入口参数:无。
65 返 回:无。
66 备 注:无。
67 ********************************************************************/
68 void UartISR(void) interrupt 4
69 {
70 1 if(RI) //收到数据
71 1 {
72 2 RI=0; //清中断请求
73 2 //从SBUF读回一字节数据保存在缓冲区中
74 2 UartBuffer[UartBufferInputPoint]=SBUF;
75 2 //将输入位置下移
76 2 UartBufferInputPoint++;
77 2 //如果已经到达缓冲区末尾,则切换到缓冲区开头
78 2 if(UartBufferInputPoint>=BUF_LEN)
79 2 {
80 3 UartBufferInputPoint=0;
81 3 }
82 2 //接收字节数加1
83 2 UartByteCount++;
84 2 }
85 1 else //发送完一字节数据
86 1 {
87 2 TI=0;
88 2 Sending=0; //清正在发送标志
89 2 }
90 1 }
91 ////////////////////////End of function//////////////////////////////
92
93 /********************************************************************
94 函数功能:往串口发送一字节数据。
95 入口参数:d: 要发送的字节数据。
96 返 回:无。
97 备 注:无。
98 ********************************************************************/
99 void UartPutChar(uint8 d)
100 {
101 1 SBUF=d; //将数据写入到串口缓冲
102 1 Sending=1; //设置发送标志
103 1 while(Sending); //等待发送完毕
104 1 }
105 ////////////////////////End of function//////////////////////////////
106
107 /********************************************************************
108 函数功能:发送一个字符串。
109 入口参数:pd:要发送的字符串指针。
110 返 回:无。
111 备 注:无。
112 ********************************************************************/
113 void Prints(uint8 * pd)
114 {
115 1 while((*pd)!='\0') //发送字符串,直到遇到0才结束
116 1 {
117 2 UartPutChar(*pd); //发送一个字符
C51 COMPILER V8.05a UART 04/21/2009 19:44:21 PAGE 3
118 2 pd++; //移动到下一个字符
119 2 }
120 1 }
121 ////////////////////////End of function//////////////////////////////
122
123 #ifdef DEBUG1
124
125 /********************************************************************
126 函数功能:将整数转按十进制字符串发送。
127 入口参数:x:待显示的整数。
128 返 回:无。
129 备 注:无。
130 ********************************************************************/
131 void PrintLongInt(uint32 x)
132 {
133 1 int8 i;
134 1 uint8 display_buffer[10];
135 1
136 1 for(i=9;i>=0;i--)
137 1 {
138 2 display_buffer[i]='0'+x%10;
139 2 x/=10;
140 2 }
141 1 for(i=0;i<9;i++)
142 1 {
143 2 if(display_buffer[i]!='0')break;
144 2 }
145 1 for(;i<10;i++)UartPutChar(display_buffer[i]);
146 1 }
147 ////////////////////////End of function//////////////////////////////
148
149 #endif
150
151 code uint8 HexTable[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
152 /********************************************************************
153 函数功能:将短整数按十六进制发送。
154 入口参数:待发送的整数。
155 返 回:无。
156 备 注:无。
157 ********************************************************************/
158 void PrintShortIntHex(uint16 x)
159 {
160 1 uint8 i;
161 1 uint8 display_buffer[7];
162 1 display_buffer[6]=0;
163 1 display_buffer[0]='0';
164 1 display_buffer[1]='x';
165 1 for(i=5;i>=2;i--) //将整数转换为4个字节的HEX值
166 1 {
167 2 display_buffer[i]=HexTable[(x&0xf)];
168 2 x>>=4;
169 2 }
170 1 Prints(display_buffer);
171 1 }
172 ////////////////////////End of function//////////////////////////////
173
174 #if (defined DEBUG0)||(defined DEBUG1)
175 /********************************************************************
176 函数功能:发送一个byte的数据。
177 入口参数:待发送的数据。
178 返 回:无。
179 备 注:无。
C51 COMPILER V8.05a UART 04/21/2009 19:44:21 PAGE 4
180 ********************************************************************/
181 void Printc(uint8 x)
182 {
183 1 Sending=1;
184 1 SBUF=x;
185 1 while(Sending);
186 1 }
187 ////////////////////////End of function//////////////////////////////
188
189 /********************************************************************
190 函数功能:以HEX格式发送一个byte的数据。
191 入口参数:待发送的数据
192 返 回:无。
193 备 注:无。
194 ********************************************************************/
195 void PrintHex(uint8 x)
196 {
197 1 Printc('0');
198 1 Printc('x');
199 1 Printc(HexTable[x>>4]);
200 1 Printc(HexTable[x&0xf]);
201 1 Printc(' ');
202 1 }
203 ////////////////////////End of function//////////////////////////////
204 #endif
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 333 ----
CONSTANT SIZE = 16 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 6 22
IDATA SIZE = 128 ----
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 + -