📄 uart0.lst
字号:
if (bRxFull && !bFullSend) { //接收缓冲区满,则发送full信号
bFullSend = TRUE;
DebugMsg(51);
}
if (inRxBuf == outRxBuf) { //为空
ES = 1;
bRxFull = FALSE;
if(!bEptSend) { //RxBuf Empty
bEptSend = TRUE;
DebugMsg(52);
}
return 0;
}
*ch=*outRxBuf;
outRxBuf++; //数据被读走,读指针加1
if(outRxBuf == RxBuf+LenRxBuf) {
outRxBuf = RxBuf; //如果读指针到缓冲区尾部,则返回到头部
}
ES = 1;
return 1;
}
#endif
232
233 /*
234 *****************************************************************************************************
235 *Func: 从串口缓冲区读1字节数据,并对缓冲区状态进行检查。如果满了,则
236 发送缓冲区满信号,如果为空,则发送缓冲区为空信号。
237 *Note:
238 * 1: 为了实现接收串口的数据,对缓冲区溢出情况进行处理
239 * 2: 用备份指针对其操作,减少分侦的可能性
240 *****************************************************************************************************
C51 COMPILER V7.06 UART0 09/26/2008 13:35:52 PAGE 5
241 */
242 bit Mygetch(unsigned char xdata *ch)
243 {
244 1 ES = 0;
245 1
246 1 if (bRxFull && !bFullSend) { //接收缓冲区满,则发送full信号
247 2 bFullSend = TRUE;
248 2 DebugMsg(51);
249 2 }
250 1 if (inRxBuf_Bak == outRxBuf) { //为空
251 2 ES = 1;
252 2 bRxFull = FALSE;
253 2 if(!bEptSend) { //RxBuf Empty
254 3 bEptSend = TRUE;
255 3 DebugMsg(52);
256 3 }
257 2 return 0;
258 2 }
259 1 *ch=*outRxBuf;
260 1 outRxBuf++; //数据被读走,读指针加1
261 1 if(outRxBuf == RxBuf+LenRxBuf) {
262 2 outRxBuf = RxBuf; //如果读指针到缓冲区尾部,则返回到头部
263 2 }
264 1 ES = 1;
265 1 return 1;
266 1 }
267
268 /*
269 *****************************************************************************************************
270 *Func: 显示字符
271 *Note:
272 * 1:
273 * 2:
274 *****************************************************************************************************
275 */
276 void PrintChar(unsigned char ch)
277 {
278 1 unsigned char xdata *t;
279 1
280 1 ES = 0; //hong
281 1 if(TIflag)
282 1 {
283 2 TIflag = 0;
284 2 TI = 1;
285 2 }
286 1 t = inTxBuf;t++;
287 1 if(t == TxBuf+LenTxBuf) t = TxBuf;
288 1 if(t == outTxBuf)
289 1 {
290 2 ES = 1;
291 2 return;
292 2 }//TxBuf Full
293 1 *inTxBuf = ch;
294 1 inTxBuf = t;
295 1 ES=1; //hong
296 1 }
297
298 /*
299 *****************************************************************************************************
300 *Func: 输出16进制数
301 *Note:
302 *****************************************************************************************************
C51 COMPILER V7.06 UART0 09/26/2008 13:35:52 PAGE 6
303 */
304
305 #ifdef _DEBUG_
void PrintCh(unsigned char ch)//内部使用,不建议用户看到。
{
if(ch>=0&&ch<=9) ch=ch+'0';
else if(ch>=10&&ch<=15) ch=ch+'A'-10;
PrintChar(ch);
}
void PrintByte(unsigned char Byte)//以十六进制格式显示1个字节数据
{
unsigned char c;
c=Byte;
c=c>>4;PrintCh(c);
c=Byte;c=c&0x0F;PrintCh(c);
}
void PrintWord(unsigned int Word)//以十六进制格式显示1个字数据
{
PrintByte(Word>>8);
PrintByte(Word&0xFF);
}
void PrintLong(unsigned long LongWord)//以十六进制格式显示1个长字数据
{
PrintWord(LongWord>>16);
PrintWord(LongWord&0xFFFF);
}
#endif
334 /*
335 *****************************************************************************************************
336 *Func: 发送一个字符串(SRAM)
337 *Note:
338 * 1:
339 * 2:
340 *****************************************************************************************************
341 */
342 void Uart0Puts(unsigned char *string)
343 {
344 1 while(*string) {
345 2 PrintChar(*string++);
346 2 }
347 1 }
348
349
350 /*
351 *****************************************************************************************************
352 *Func: 发送一个字符串(SRAM) ,长度已知
353 *Note:
354 * 1:
355 * 2:
356 *****************************************************************************************************
357 */
358 void Uart0Putsl(unsigned char *string,unsigned int length)
359 {
360 1 while(length--) {
361 2 PrintChar(*string++);
362 2 }
363 1 }
364
C51 COMPILER V7.06 UART0 09/26/2008 13:35:52 PAGE 7
365
366 /*
367 *****************************************************************************************************
368 *Func: 发送一个字符串(flash/code)
369 *Note:
370 * 1:
371 * 2:
372 *****************************************************************************************************
373 */
374 void Uart0Putf(unsigned char code *string)
375 {
376 1 unsigned char c;
377 1
378 1 while(*string) {
379 2 c=*string++;
380 2 PrintChar(c);
381 2 }
382 1 }
383
384
385 /*
386 *****************************************************************************************************
387 *Func: 一侦结束判断 终端到网络的数据
388 *Note:
389 * 1: 接收字节时的时间与当前时间比较,过了50MS,且接收缓冲区不为空,为一侦结束
390 * 2:
391 *****************************************************************************************************
392 */
393 void FramePush(unsigned char *source,unsigned int length)
394 {
395 1 unsigned int i;
396 1
397 1 while (FrameIn < MAX_BUF_NUM) {
398 2 if (0 == Te2NetBuf[FrameIn].statu) {
399 3 for (i=0; i<length; i++) {
400 4 Te2NetBuf[FrameIn].buf[i] = source[i]; //拷贝数据
401 4 }
402 3 Te2NetBuf[FrameIn].statu = 10; //有数据
403 3 Te2NetBuf[FrameIn].ttl = 20; //生存时间:单位S
404 3 Te2NetBuf[FrameIn].length = length; //长度
405 3 FrameIn++;
406 3 break;
407 3 } else {
408 3 FrameIn++;
409 3 }
410 2 }
411 1
412 1 if (FrameIn >= MAX_BUF_NUM) {
413 2 FrameIn = 0;
414 2 }
415 1 }
416
417
418 /*
419 *****************************************************************************************************
420 *Func: 网络到终端的数据缓冲区
421 *Note:
422 * 1:
423 * 2:
424 *****************************************************************************************************
425 */
426 void FramePush2(unsigned char *source,unsigned int length)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -