📄 rs232.lst
字号:
181 /* Function Name : RS232_rx_datalen *
182 /* *
183 /* Arguments : *
184 /* None. *
185 /* *
186 /* Return : *
187 /* The data length in bytes of RS232 RX FIFO. *
188 /* *
189 /* Comment : *
190 /* This function return the data length of RS232 RX FIFO. *
191 /* *
192 /************************************************************************/
193 int RS232_rx_datalen()
194 {
195 1 int ret_val;
196 1 data int current_rxb,last_rxb;
197 1
198 1 /*Critical section,disable interrupt*/
199 1 IE&=(~0x10);
200 1 current_rxb=RS232_current_rxb;
201 1 last_rxb=RS232_last_rxb;
202 1 IE|=0x10;
203 1
204 1 /*Calculate RX FIFO data length.*/
205 1 if (current_rxb<last_rxb)
206 1 ret_val=last_rxb-current_rxb;
207 1 else if (current_rxb>last_rxb)
208 1 ret_val=RS232_RXB_SIZE-current_rxb+last_rxb;
209 1 else ret_val=0;
210 1 return ret_val;
211 1 }
212
213 /************************************************************************
214 /* Function Name : RS232_rx_empty *
215 /* *
216 /* Arguments : *
217 /* None. *
218 /* *
219 /* Return : *
220 /* TRUE :RX FIFO is empty. *
221 /* FALSE :RX FIFO have data. *
222 /* *
223 /* Comment : *
224 /* This function return TRUE if RS232 RX FIFO is empty. *
225 /* *
226 /************************************************************************/
227 char RS232_rx_empty()
228 {
229 1 data int current_rxb,last_rxb;
230 1 /*Critical section,disable interrupt*/
231 1 IE&=(~0x10);
232 1 current_rxb=RS232_current_rxb;
233 1 last_rxb=RS232_last_rxb;
234 1 IE|=0x10;
235 1
236 1 if ((current_rxb!=last_rxb))
237 1 return 0;
238 1 return 1;
239 1 }
240 /************************************************************************
C51 COMPILER V7.50 RS232 10/12/2006 15:31:40 PAGE 5
241 /* Function Name : RS232_rx_getchar *
242 /* *
243 /* Arguments : *
244 /* None. *
245 /* *
246 /* Return : *
247 /* The char get from RS232 RX FIFO or *
248 /* 0 if no data in RX FIFO. *
249 /* *
250 /* Comment : *
251 /* This function get one byte from RS232 RX FIFO. *
252 /* *
253 /************************************************************************/
254 char RS232_rx_getchar()
255 {
256 1 char ret_val;
257 1 data int current_rxb,last_rxb;
258 1 /*Critical section,disable interrupt*/
259 1 IE&=(~0x10);
260 1 current_rxb=RS232_current_rxb;
261 1 last_rxb=RS232_last_rxb;
262 1 IE|=0x10;
263 1 /*RX FIFO not empty*/
264 1 if ((current_rxb!=last_rxb))
265 1 {
266 2 ret_val=RS232_rxb[current_rxb];
267 2 current_rxb=(current_rxb+1)%RS232_RXB_SIZE;
268 2 /*Critical section,disable interrupt*/
269 2 IE&=(~0x10);
270 2 RS232_current_rxb=current_rxb;
271 2 IE|=0x10;
272 2 #if USE_XON_XOFF
273 2 if ((xoff_flag==1) &&((RS232_rx_freelen())>RS232_BUFF_RES))
274 2 {
275 3 xoff_flag=0;
276 3 printf("\x11");
277 3 }
278 2 #endif
279 2 return ret_val;
280 2 }
281 1 return 0;
282 1 }
283 /************************************************************************
284 /* Function Name : RS232_rx_buffout *
285 /* *
286 /* Arguments : *
287 /* char *buff: The buffer to store data get from RX FIFO. *
288 /* int len : How many byte to get from RX FIFO. *
289 /* *
290 /* Return : *
291 /* Number of bytes out from RX FIFO. *
292 /* *
293 /* Comment : *
294 /* This function get bytes from RS232 RX FIFO. *
295 /* *
296 /************************************************************************/
297 int RS232_rx_buffout(char *buff,int len)
298 {
299 1 data int tmp,n1;
300 1 data int current_rxb,last_rxb;
301 1 /*Critical section,disable interrupt*/
302 1 IE&=(~0x10);
C51 COMPILER V7.50 RS232 10/12/2006 15:31:40 PAGE 6
303 1 current_rxb=RS232_current_rxb;
304 1 last_rxb=RS232_last_rxb;
305 1 IE|=0x10;
306 1
307 1 /*Buffer is NULL just set the point of RX FIFO*/
308 1 if (buff==0)
309 1 {
310 2 n1=RS232_rx_datalen();
311 2 n1=n1>len?len:n1;
312 2 current_rxb=(current_rxb+n1)%RS232_RXB_SIZE;
313 2 /*Critical section,disable interrupt*/
314 2 IE&=(~0x10);
315 2 /*Update RX FIFO data point.*/
316 2 RS232_current_rxb=current_rxb;
317 2 IE|=0x10;
318 2 #if USE_XON_XOFF
319 2 if ((xoff_flag==1) &&((RS232_rx_freelen())>RS232_BUFF_RES))
320 2 {
321 3 xoff_flag=0;
322 3 printf("\x11");
323 3 }
324 2 #endif
325 2 return n1;
326 2 }
327 1 /*Argument error.*/
328 1 if (len<=0)
329 1 return 0;
330 1 tmp=0;
331 1 /*
332 1 Copy bytes to buff.
333 1 Note : This can't replease by memcpy function.
334 1 */
335 1 while ((current_rxb!=last_rxb)&&(tmp<len))
336 1 {
337 2 buff[tmp]=RS232_rxb[current_rxb];
338 2 tmp++;
339 2 current_rxb=(current_rxb+1)%RS232_RXB_SIZE;
340 2 }
341 1 /*Critical section,disable interrupt*/
342 1 IE&=(~0x10);
343 1 /*Update RX FIFO data point.*/
344 1 RS232_current_rxb=current_rxb;
345 1 IE|=0x10;
346 1 #if USE_XON_XOFF
347 1 if ((xoff_flag==1) &&((RS232_rx_freelen())>RS232_BUFF_RES))
348 1 {
349 2 xoff_flag=0;
350 2 printf("\x11");
351 2 }
352 1 #endif
353 1 return tmp;
354 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 900 ----
CONSTANT SIZE = 2 ----
XDATA SIZE = 256 6
PDATA SIZE = ---- ----
DATA SIZE = 6 28
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
C51 COMPILER V7.50 RS232 10/12/2006 15:31:40 PAGE 7
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -