📄 pc_o.lst
字号:
C51 COMPILER V6.21 PC_O 01/23/2002 18:10:46 PAGE 1
C51 COMPILER V6.21, COMPILATION OF MODULE PC_O
OBJECT MODULE PLACED IN PC_O.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE PC_O.c OPTIMIZE(6,SPEED) BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /*------------------------------------------------------------------*-
2
3 PC_O.C (v1.00)
4
5 ------------------------------------------------------------------
6
7 Core files for simple write-only PC link library for 8051 family
8 [Sends data to PC - cannot receive data from PC]
9
10 Uses the UART, and Pin 3.1 (Tx)
11
12 See text for details (Chapter 9).
13
14 COPYRIGHT
15 ---------
16
17 This code is associated with the book:
18
19 EMBEDDED C by Michael J. Pont
20 [Pearson Education, 2002: ISBN: 0-201-79523-X].
21
22 This code is copyright (c) 2001 by Michael J. Pont.
23
24 See book for copyright details and other information.
25
26 -*------------------------------------------------------------------*/
27
28 #include "Main.h"
29 #include "PC_O.h"
30
31 // ------ Public variable definitions ------------------------------
32
33 tByte Out_written_index_G; // Data in buffer that has been written
34 tByte Out_waiting_index_G; // Data in buffer not yet written
35
36 // ------ Private function prototypes ------------------------------
37
38 static void PC_LINK_O_Send_Char(const char);
39
40 // ------ Private constants ----------------------------------------
41
42 // The transmit buffer length
43 #define TRAN_BUFFER_LENGTH 20
44
45 // ------ Private variables ----------------------------------------
46
47 static tByte Tran_buffer[TRAN_BUFFER_LENGTH];
48
49 static tByte Time_count_G = 0;
50
51
52 /*------------------------------------------------------------------*-
53
54 PC_LINK_O_Update()
55
C51 COMPILER V6.21 PC_O 01/23/2002 18:10:46 PAGE 2
56 Sends next character from the software transmit buffer
57
58 NOTE: Output-only library (Cannot receive chars)
59
60 Uses on-chip UART hardware.
61
62 -*------------------------------------------------------------------*/
63 void PC_LINK_O_Update(void)
64 {
65 1 // Deal with transmit bytes here
66 1 //
67 1 // Are there any data ready to send?
68 1 if (Out_written_index_G < Out_waiting_index_G)
69 1 {
70 2 PC_LINK_O_Send_Char(Tran_buffer[Out_written_index_G]);
71 2
72 2 Out_written_index_G++;
73 2 }
74 1 else
75 1 {
76 2 // No data to send - just reset the buffer index
77 2 Out_waiting_index_G = 0;
78 2 Out_written_index_G = 0;
79 2 }
80 1 }
81
82 /*------------------------------------------------------------------*-
83
84 PC_LINK_O_Write_String_To_Buffer()
85
86 Copies a (null terminated) string to the character buffer.
87 (The contents of the buffer are then passed over the serial link)
88
89 -*------------------------------------------------------------------*/
90 void PC_LINK_O_Write_String_To_Buffer(const char* const STR_PTR)
91 {
92 1 tByte i = 0;
93 1
94 1 while (STR_PTR[i] != '\0')
95 1 {
96 2 PC_LINK_O_Write_Char_To_Buffer(STR_PTR[i]);
97 2 i++;
98 2 }
99 1 }
100
101 /*------------------------------------------------------------------*-
102
103 PC_LINK_O_Write_Char_To_Buffer()
104
105 Stores a character in the 'write' buffer, ready for
106 later transmission
107
108 -*------------------------------------------------------------------*/
109 void PC_LINK_O_Write_Char_To_Buffer(const char CHARACTER)
110 {
111 1 // Write to the buffer *only* if there is space
112 1 // (No error reporting in this simple library...)
113 1 if (Out_waiting_index_G < TRAN_BUFFER_LENGTH)
114 1 {
115 2 Tran_buffer[Out_waiting_index_G] = CHARACTER;
116 2 Out_waiting_index_G++;
117 2 }
C51 COMPILER V6.21 PC_O 01/23/2002 18:10:46 PAGE 3
118 1 }
119
120 /*------------------------------------------------------------------*-
121
122 PC_LINK_O_Send_Char()
123
124 Based on Keil sample code, with added (loop) timeouts.
125 Implements Xon / Off control.
126
127 Uses on-chip UART hardware.
128
129 -*------------------------------------------------------------------*/
130 void PC_LINK_O_Send_Char(const char CHARACTER)
131 {
132 1 tLong Timeout1 = 0;
133 1
134 1 if (CHARACTER == '\n')
135 1 {
136 2 Timeout1 = 0;
137 2 while ((++Timeout1) && (TI == 0));
138 2
139 2 if (Timeout1 == 0)
140 2 {
141 3 // UART did not respond - error
142 3 // No error reporting in this simple library...
143 3 return;
144 3 }
145 2
146 2 TI = 0;
147 2 SBUF = 0x0D; // Output CR
148 2 }
149 1
150 1 Timeout1 = 0;
151 1 while ((++Timeout1) && (TI == 0));
152 1
153 1 if (Timeout1 == 0)
154 1 {
155 2 // UART did not respond - error
156 2 // No error reporting in this simple library...
157 2 return;
158 2 }
159 1
160 1 TI = 0;
161 1
162 1 SBUF = CHARACTER;
163 1 }
164
165 /*------------------------------------------------------------------*-
166 ---- END OF FILE -------------------------------------------------
167 -*------------------------------------------------------------------*/
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 189 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 23 9
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 + -