📄 uart.lst
字号:
C51 COMPILER V7.06 UART 11/16/2008 16:00:30 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE UART
OBJECT MODULE PLACED IN UART.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE UART.c BROWSE DEBUG OBJECTEXTEND TABS(1)
stmt 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
28 volatile uint8 Sending;
29
30
31 /********************************************************************
32 函数功能:串口初始化。
33 入口参数:无。
34 返 回:无。
35 备 注:无。
36 ********************************************************************/
37 void InitUART(void)
38 {
39 1 EA=0; //暂时关闭中断
40 1 TMOD&=0x0F; //定时器1模式控制在高4位
41 1 TMOD|=0x20; //定时器1工作在模式2,自动重装模式
42 1 SCON=0x50; //串口工作在模式1
43 1 TH1=256-Fclk/(BitRate*12*16); //计算定时器重装值
44 1 TL1=256-Fclk/(BitRate*12*16);
45 1 PCON|=0x80; //串口波特率加倍
46 1 ES=1; //串行中断允许
47 1 TR1=1; //启动定时器1
48 1 REN=1; //允许接收
49 1 EA=1; //允许中断
50 1 }
51 ////////////////////////End of function//////////////////////////////
52
53 /********************************************************************
54 函数功能:串口中断处理。
55 入口参数:无。
C51 COMPILER V7.06 UART 11/16/2008 16:00:30 PAGE 2
56 返 回:无。
57 备 注:无。
58 ********************************************************************/
59 void UartISR(void) interrupt 4
60 {
61 1 if(RI) //收到数据
62 1 {
63 2 RI=0; //清中断请求
64 2 }
65 1 else //发送完一字节数据
66 1 {
67 2 TI=0;
68 2 Sending=0; //清正在发送标志
69 2 }
70 1 }
71 ////////////////////////End of function//////////////////////////////
72
73 /********************************************************************
74 函数功能:往串口发送一字节数据。
75 入口参数:d: 要发送的字节数据。
76 返 回:无。
77 备 注:无。
78 ********************************************************************/
79 void UartPutChar(uint8 d)
80 {
81 1 SBUF=d; //将数据写入到串口缓冲
82 1 Sending=1; //设置发送标志
83 1 while(Sending); //等待发送完毕
84 1 }
85 ////////////////////////End of function//////////////////////////////
86
87 /********************************************************************
88 函数功能:发送一个字符串。
89 入口参数:pd:要发送的字符串指针。
90 返 回:无。
91 备 注:无。
92 ********************************************************************/
93 void Prints(uint8 * pd)
94 {
95 1 while((*pd)!='\0') //发送字符串,直到遇到0才结束
96 1 {
97 2 UartPutChar(*pd); //发送一个字符
98 2 pd++; //移动到下一个字符
99 2 }
100 1 }
101 ////////////////////////End of function//////////////////////////////
102
103 #ifdef DEBUG1
104
105 /********************************************************************
106 函数功能:将整数转按十进制字符串发送。
107 入口参数:x:待显示的整数。
108 返 回:无。
109 备 注:无。
110 ********************************************************************/
111 void PrintLongInt(uint32 x)
112 {
113 1 int8 i;
114 1 uint8 display_buffer[10];
115 1
116 1 for(i=9;i>=0;i--)
117 1 {
C51 COMPILER V7.06 UART 11/16/2008 16:00:30 PAGE 3
118 2 display_buffer[i]='0'+x%10;
119 2 x/=10;
120 2 }
121 1 for(i=0;i<9;i++)
122 1 {
123 2 if(display_buffer[i]!='0')break;
124 2 }
125 1 for(;i<10;i++)UartPutChar(display_buffer[i]);
126 1 }
127 ////////////////////////End of function//////////////////////////////
128
129 #endif
130
131 code uint8 HexTable[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
132 /********************************************************************
133 函数功能:将短整数按十六进制发送。
134 入口参数:待发送的整数。
135 返 回:无。
136 备 注:无。
137 ********************************************************************/
138 void PrintShortIntHex(uint16 x)
139 {
140 1 uint8 i;
141 1 uint8 display_buffer[7];
142 1 display_buffer[6]=0;
143 1 display_buffer[0]='0';
144 1 display_buffer[1]='x';
145 1 for(i=5;i>=2;i--) //将整数转换为4个字节的HEX值
146 1 {
147 2 display_buffer[i]=HexTable[(x&0xf)];
148 2 x>>=4;
149 2 }
150 1 Prints(display_buffer);
151 1 }
152 ////////////////////////End of function//////////////////////////////
153
154 #if (defined DEBUG0)||(defined DEBUG1)
155 /********************************************************************
156 函数功能:发送一个byte的数据。
157 入口参数:待发送的数据。
158 返 回:无。
159 备 注:无。
160 ********************************************************************/
161 void Printc(uint8 x)
162 {
163 1 Sending=1;
164 1 SBUF=x;
165 1 while(Sending);
166 1 }
167 ////////////////////////End of function//////////////////////////////
168
169 /********************************************************************
170 函数功能:以HEX格式发送一个byte的数据。
171 入口参数:待发送的数据
172 返 回:无。
173 备 注:无。
174 ********************************************************************/
175 void PrintHex(uint8 x)
176 {
177 1 Printc('0');
178 1 Printc('x');
179 1 Printc(HexTable[x>>4]);
C51 COMPILER V7.06 UART 11/16/2008 16:00:30 PAGE 4
180 1 Printc(HexTable[x&0xf]);
181 1 Printc(' ');
182 1 }
183 ////////////////////////End of function//////////////////////////////
184 #endif
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 296 ----
CONSTANT SIZE = 16 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 1 22
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 + -