?? 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 + -