📄 uart.lst
字号:
C51 COMPILER V8.00 UART 11/17/2008 10:50:44 PAGE 1
C51 COMPILER V8.00, COMPILATION OF MODULE UART
OBJECT MODULE PLACED IN uart.OBJ
COMPILER INVOKED BY: C:\Program Files\Keil\C51\BIN\C51.exe uart.c DB OE BR
line level source
1 /*
2 ** ============================================================================
3 **
4 ** FILE
5 ** uart.c
6 **
7 ** DESCRIPTION
8 ** Contains the UART functions.
9 **
10 ** CREATED
11 ** Silicon Laboratories Hungary Ltd
12 **
13 ** COPYRIGHT
14 ** Copyright 2008 Silicon Laboratories, Inc.
15 ** http://www.silabs.com
16 **
17 ** ============================================================================
18 */
19 /*------------------------------------------------------------------------*/
20 /* INCLUDE */
21 /*------------------------------------------------------------------------*/
22 #include "uart.h"
23 #include "global_definitions.h"
24 #ifdef USB_CONNECTION_SUPPORT
25 #include "USB_connection.c"
26 #endif
27
28 /*------------------------------------------------------------------------*/
29 /* GLOBAL variables */
30 /*------------------------------------------------------------------------*/
31
32 bit fUartCommandReceived, fCharSent;
33 idata uint8 UartRxPointer;
34 idata uint8 UartRxBuffer[UART_RX_BUFFER_SIZE], UartRxMessage[UART_RX_BUFFER_SIZE];
35 idata uint8 UartEcho;
36
37
38 /*------------------------------------------------------------------------*/
39 /* LOCAL function prototypes */
40 /*------------------------------------------------------------------------*/
41
42 void _PrintOk(void);
43 void _PrintWrongParam(void);
44
45 /*------------------------------------------------------------------------*/
46 /* UART INTERRUPT */
47 /*------------------------------------------------------------------------*/
48 INTERRUPT(Uart0_ISR, INTERRUPT_UART0)
49 {
50 1 //check RX interrupt
51 1 if( RI0 == 1 )
52 1 {
53 2 //clear IT Flag
54 2 RI0 = 0;
55 2 UartRxISR();
C51 COMPILER V8.00 UART 11/17/2008 10:50:44 PAGE 2
56 2 }
57 1 if( TI0 == 1 )
58 1 {
59 2 TI0 = 0;
60 2 fCharSent = 1;
61 2 }
62 1 }
63
64
65 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
66 +
67 + FUNCTION NAME: void UartInit(void)
68 +
69 + DESCRIPTION: initialize the UART peripheral
70 +
71 + RETURN: None
72 +
73 + NOTES:
74 +
75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
76
77 void UartInit(void)
78 {
79 1
80 1 SCON0 = 0x10; // SCON0: 8-bit variable bit rate
81 1 // level of STOP bit is ignored
82 1 // RX enabled
83 1 // ninth bits are zeros
84 1 // clear RI0 and TI0 bits
85 1 #if (SYSCLK/BAUDRATE/2/256 < 1)
86 1 TH1 = -(SYSCLK/BAUDRATE/2);
87 1 CKCON &= ~0x0B; // T1M = 1; SCA1:0 = xx
88 1 CKCON |= 0x08;
89 1 #elif (SYSCLK/BAUDRATE/2/256 < 4)
TH1 = -(SYSCLK/BAUDRATE/2/4);
CKCON &= ~0x0B; // T1M = 0; SCA1:0 = 01
CKCON |= 0x01;
#elif (SYSCLK/BAUDRATE/2/256 < 12)
TH1 = -(SYSCLK/BAUDRATE/2/12);
CKCON &= ~0x0B; // T1M = 0; SCA1:0 = 00
#else
TH1 = -(SYSCLK/BAUDRATE/2/48);
CKCON &= ~0x0B; // T1M = 0; SCA1:0 = 10
CKCON |= 0x02;
#endif
101 1
102 1 TL1 = TH1; // init Timer1
103 1 TMOD &= ~0xf0; // TMOD: timer 1 in 8-bit autoreload
104 1 TMOD |= 0x20;
105 1 TR1 = 1; // START Timer1
106 1 TI0 = 1; // Indicate TX0 ready
107 1 fCharSent = 1; //Indicate putchar ready
108 1 UartEcho = 1; //set UART echo mode to 1
109 1 EnableUartRxIt();
110 1 }
111
112
113
114 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
115 +
116 + FUNCTION NAME: void UartRxISR(void)
117 +
C51 COMPILER V8.00 UART 11/17/2008 10:50:44 PAGE 3
118 + DESCRIPTION: UART Receive interrupt handler
119 +
120 + RETURN: None
121 +
122 + NOTES: UartInit() has to be call before
123 +
124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
125 void UartRxISR(void)
126 {
127 1 uint8 RxData;
128 1
129 1 //get data from the register
130 1 RxData = SBUF0;
131 1 if( (RxData != ' ') && (RxData != CHAR_LF) )
132 1 {
133 2 UartRxBuffer[UartRxPointer] = RxData;
134 2 }
135 1 else
136 1 {
137 2 return;
138 2 }
139 1 //is the buffer full, or was the last char ENTER?
140 1 if( (UartRxPointer == UART_RX_BUFFER_SIZE - 1) || (UartRxBuffer[UartRxPointer] == MESSAGE_END) )
141 1 {
142 2 //Message received - last char should be NULL
143 2 UartRxBuffer[UartRxPointer] = 0;
144 2 UartRxPointer = 0;
145 2 strcpy((uint8*)UartRxMessage,(uint8*)UartRxBuffer);
146 2 fUartCommandReceived = TRUE;
147 2 }
148 1 else
149 1 {
150 2 //if the last char was not back space, then inc the pointer
151 2 if( !(UartRxBuffer[UartRxPointer] == CHAR_BACKSPACE) )
152 2 UartRxPointer++;
153 2 else
154 2 {
155 3 if(UartRxPointer > 0)
156 3 UartRxPointer--;
157 3 }
158 2 }
159 1 }
160
161 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
162 +
163 + FUNCTION NAME: char putchar(char c)
164 +
165 + DESCRIPTION: prints one character into the serial port
166 +
167 + RETURN: None
168 +
169 + NOTES: UartInit() has to be call before
170 +
171 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
172 char putchar(char c)
173 {
174 1 while( fCharSent == 0);
175 1 fCharSent = 0;
176 1 SBUF0 = c;
177 1
178 1 #ifdef __C51__
179 1 return c;
C51 COMPILER V8.00 UART 11/17/2008 10:50:44 PAGE 4
180 1 #elif defined SDCC
#endif
183 1 }
184
185 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
186 +
187 + FUNCTION NAME: void CommandInterpreter(void)
188 +
189 + DESCRIPTION: it check the received string and execute the operation
190 + if it is a valid UART command
191 +
192 + RETURN: None
193 +
194 + NOTES: UartInit() has to be call before
195 +
196 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
197 void UartCommandInterpreter(void)
198 {
199 1 /*ENTER*/
200 1 if( UartRxMessage[0] == 0 )
201 1 {
202 2 printf("\n\r>");
203 2 return;
204 2 }
205 1
206 1 #ifdef USB_CONNECTION_SUPPORT
207 1 if( USBConnectionSupport( (uint8*)&UartRxMessage[0] ) )
208 1 {
209 2 _PrintOk();
210 2 return;
211 2 }
212 1 #endif
213 1
214 1 /*INVALID COMMAND*/
215 1 _PrintWrongParam();
216 1 }
217
218 /*------------------------------------------------------------------------*/
219 /* LOCAL functions */
220 /*------------------------------------------------------------------------*/
221 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
222 +
223 + FUNCTION NAME: void _PrintOk(void)
224 +
225 + DESCRIPTION: print OK and new prompt
226 +
227 + RETURN:
228 +
229 + NOTES:
230 +
231 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
232 void _PrintOk(void)
233 {
234 1 switch(UartEcho)
235 1 {
236 2 case 0:
237 2 case 1:
238 2 case 2:
239 2 printf("\n\rOK\n\r>");
240 2 break;
241 2
C51 COMPILER V8.00 UART 11/17/2008 10:50:44 PAGE 5
242 2 default:
243 2 printf("\n\r>");
244 2 break;
245 2 }
246 1 }
247
248 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
249 +
250 + FUNCTION NAME: void _PrintWrongParam(void)
251 +
252 + DESCRIPTION: print worng parameter message
253 +
254 + RETURN:
255 +
256 + NOTES:
257 +
258 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
259 void _PrintWrongParam(void)
260 {
261 1 printf("\n\rERROR\n\r>");
262 1 }
263
264
265
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 837 ----
CONSTANT SIZE = 420 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 22
IDATA SIZE = 22 ----
BIT SIZE = 2 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -