📄 serial.lst
字号:
C51 COMPILER V8.02 SERIAL 10/17/2006 11:01:56 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE SERIAL
OBJECT MODULE PLACED IN E:\DING\EVB805~1.0\SOFTWARE\FIRMWARE\DIRECT~1\SMTP_WEB\SERIAL.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE E:\DING\EVB805~1.0\SOFTWARE\FIRMWARE\DIRECT~1\SMTP_WEB\SERIAL.C DB SB OE
line level source
1 /*
2 ###############################################################################
3
4 File Name : SERIAL.C
5
6 Version : 2.0
7
8 Created : 2001/01/09
9
10 Description : Definition of functions referring to RS232C
11 All of functions in 'Serial.h' are implemented by polling.
12
13 Modified History
14
15 Modified : 2002/03/15
16 Description : Eliminate disused function
17 Modified : 2002/10/20
18 Description : Version Up
19 Add GetString()
20 Delete PrintLn()
21 Delete Print()
22 Modify PutString() to Re-Entrance function
23 Modify PutStringLn() to Re-Entrance function
24 ###############################################################################
25 */
26
27
28
29 /*
30 ###############################################################################
31 Include Part
32 ###############################################################################
33 */
34
35 #include <reg51.h>
36 #include <serial.h>
37
38
39 /*
40 ###############################################################################
41 Define Part
42 ###############################################################################
43 */
44
45
46 /*
47 ###############################################################################
48 Grobal Variable Definition Part
49 ###############################################################################
50 */
51
52
53
54
55 /*
C51 COMPILER V8.02 SERIAL 10/17/2006 11:01:56 PAGE 2
56 ###############################################################################
57 Function Implementation Part
58 ###############################################################################
59 */
60
61 /*
62 Description : Initialization of Serial Port(Ex.Baud Rate setting)
63 Argument :
64 Return Value :
65 Note :
66 */
67 void InitSerial(void)
68 {
69 1 ET1 = 0; /* TIMER1 INT DISABLE */
70 1 TMOD = 0x20;
71 1 PCON |= 0x80;
72 1
73 1 // TH1 = 0xFC; /* X2 57600(SMOD=1) at 22.1184 MHZ */
74 1 TH1 = 0xFD; /* X2 57600(SMOD=1) at 16 MHZ */
75 1
76 1 TR1 = 1; /* START THE TIMER1 */
77 1 SCON = 0x52; /* SERIAL MODE 1, REN=1, TI=1, RI=0 */
78 1
79 1 /* Interrupt */
80 1 ES = 0; /* Serial interrupt disable */
81 1 RI = 0;
82 1 TI = 0;
83 1 while(TI && RI);
84 1 }
85
86 /*
87 Description : Output 1 character through Serial Port
88 Argument : byData - character to output(INPUT)
89 Return Value :
90 Note :
91 */
92 void PutByte(UCHAR byData)
93 {
94 1 // Write data into serial-buffer.
95 1 SBUF = byData;
96 1 // Wait till data recording is finished.
97 1 while(!TI);
98 1 TI = 0;
99 1 }
100
101 /*
102 Description : Read 1 character from Serial.
103 Argument :
104 Return Value : Read 1 character from Serial and Return.
105 Note :
106 */
107 unsigned char GetByte(void)
108 {
109 1 unsigned char byData;
110 1 // Wait till data is received.
111 1 while( !RI );
112 1 RI = 0;
113 1 // Read data.
114 1 byData = SBUF;
115 1 return byData;
116 1 }
117
C51 COMPILER V8.02 SERIAL 10/17/2006 11:01:56 PAGE 3
118
119 /*
120 Description : Check to input to Serial or not.
121 Argument :
122 Return Value : 1)If there's input, then returned value is '1'.
123 2)If there's no input, then returned value is '-1'.
124 Note :
125 */
126 char IsPressedKey()
127 {
128 1 if( RI == 1 ) return 1;
129 1 return -1;
130 1 }
131
132
133 /*
134 Description : Output 1 Byte Hexadecimal digit to 2Byte ASCII character. ex) 0x2E --> "2E"
135 Argument : byData - character to output(INPUT)
136 Return Value :
137 Note :
138 */
139 void PutHTOA(UCHAR byData)
140 {
141 1 // HIGH DIGIT
142 1 if((byData / 0x10) >= 10)
143 1 PutByte('A'+((byData/0x10)%0x0A));
144 1 else
145 1 PutByte('0'+((byData/0x10)%0x0A));
146 1 // LOW DIGIT
147 1 if((byData % 0x10) >= 10)
148 1 PutByte('A' + ((byData%0x10)%0x0A));
149 1 else
150 1 PutByte('0' + ((byData%0x10)%0x0A));
151 1 }
152
153 /*
154 Description : Output 2 Byte Integer to 4Byte ASCII character ex) 0x12FD --> "12FD"
155 Argument : byData - Integer to output(INPUT)
156 Return Value :
157 Note :
158 */
159 void PutITOA(UINT byData)
160 {
161 1 PutHTOA(byData / 0x100);
162 1 PutHTOA(byData % 0x100);
163 1 }
164
165 /*
166 Description : Output 4 Byte Long to 8Byte ASCII character. ex) 0x001234FF --> "001234FF"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -