📄 mcs51-项目开发经典.lst
字号:
396 //-------------------------------------------------------------------------------------------------
397 uchar change_hex_to_askii(uchar data_hex)//HEX转换成ASKII,实参范围:0-9、A-F
398 { if(data_hex<=0x09) return(data_hex+0x30);
399 1 else return(data_hex+0x37);
400 1 }
401 //=================================================================================================
402 // 函数功能:将格式为"data1,data2,...datan#" 的字符串中的data数据全部取出,并存储于temporary_data[]
403 //=================================================================================================
404 void get_data(uchar * how_much_data)
405 {
406 1 uchar i;
407 1 uchar j=0;
408 1 uchar k=0;
409 1 uchar how_much_temp_askii=0;
410 1 uchar temp_askii[5];
411 1 uint return_data;
412 1
413 1 for(i=0; i<strlen(how_much_data); i++)
414 1 {
415 2 if( (how_much_data[i] != ',') && (how_much_data[i] != '#') )
416 2 {
417 3 temp_askii[j] = how_much_data[i];
418 3 j=j+1;
419 3 how_much_temp_askii=how_much_temp_askii+1;
420 3 }
421 2 else
422 2 {j=0;
423 3 switch (how_much_temp_askii)
424 3 {case 1:{return_data = change_askii_to_hex(temp_askii[0]);
425 5 break;
426 5 }
427 4 case 2:{return_data = change_askii_to_hex(temp_askii[0])*10+
C51 COMPILER V7.06 MCS51__钅靠猒_____ 12/10/2008 19:58:27 PAGE 8
428 5 change_askii_to_hex(temp_askii[1]);
429 5 break;
430 5 }
431 4 case 3:{return_data = change_askii_to_hex(temp_askii[0])*100+
432 5 change_askii_to_hex(temp_askii[1])*10 +
433 5 change_askii_to_hex(temp_askii[2]);
434 5 break;
435 5 }
436 4 case 4:{return_data = change_askii_to_hex(temp_askii[0])*1000+
437 5 change_askii_to_hex(temp_askii[1])*100 +
438 5 change_askii_to_hex(temp_askii[2])*10 +
439 5 change_askii_to_hex(temp_askii[3]);
440 5 break;
441 5 }
442 4 case 5:{return_data = change_askii_to_hex(temp_askii[0])*10000+
443 5 change_askii_to_hex(temp_askii[1])*1000 +
444 5 change_askii_to_hex(temp_askii[2])*100 +
445 5 change_askii_to_hex(temp_askii[3])*10 +
446 5 change_askii_to_hex(temp_askii[4]);
447 5 break;
448 5 }
449 4 default:break;
450 4 }
451 3 temporary_data[k] = return_data;
452 3 k=k+1;
453 3 how_much_temp_askii=0;
454 3 }
455 2 }
456 1 }
457 //=================================================================================================
458 // 函数功能:字符串匹配函数
459 //=================================================================================================
460 char * strstr(char * haystack, char * needle)
461 { char *ptr1, *ptr2;
462 1 weizhi=0;
463 1 // Protect against NULL pointer
464 1 if (*needle == 0) return(haystack);
465 1 for( ; *haystack; haystack++ ,weizhi++)
466 1 {// Look for needle in haystack. If there is a
467 2 // match then this will continue all the way
468 2 // until ptr1 reaches the NULL at the end of needle
469 2 for(ptr1 = needle, ptr2 = haystack; *ptr1 && (*ptr1 == *ptr2); ++ptr1, ++ptr2);
470 2 // If there is a match then return pointer to needle in haystack
471 2 if(*ptr1 == 0) return(haystack);
472 2 }
473 1 return NULL;// no matching string found
474 1 }
475 //=================================================================================================
476 // 串口UART中断服务程序
477 // 可以自动接收格式为"@xxx...xxx#"的字符串,长度小于等于30
478 //=================================================================================================
479 void UART_interrupt (void) interrupt 4
480 { RI=0;
481 1 if( SBUF == '@' ) //判断头
482 1 {uart_buffer_address = 0;
483 2 uart_buffer[uart_buffer_address] = SBUF;
484 2 uart_buffer_address++;
485 2 uart_receive_start = 1; //置uart0接收启动标志
486 2 return;
487 2 }
488 1 if( uart_receive_start == 1 ) //接收中间数据
489 1 {uart_buffer[uart_buffer_address] = SBUF;
C51 COMPILER V7.06 MCS51__钅靠猒_____ 12/10/2008 19:58:27 PAGE 9
490 2 uart_buffer_address++; //每接收1字节缓冲区地址加1
491 2 }
492 1 if( (uart_receive_start == 1)&&(SBUF == '#') ) //判断尾
493 1 {uart_buffer[uart_buffer_address] = 0;//置字符串结束符号 \0,为字符串处理函数提供标准格式
494 2 uart_buffer_address = 0; //清缓冲区地址指针
495 2 uart_receive_start = 0; //清uart0接收启动标志
496 2 uart_receive_ok = 1; //置已接收完整串口命令标志
497 2 return;
498 2 }
499 1 if(uart_buffer_address>39) //uart0接收缓冲区地址溢出故障处理:
500 1 {uart_buffer_address = 0; //清缓冲区地址指针
501 2 uart_receive_start = 0; //清uart0接收启动标志
502 2 uart_receive_ok = 0; //清已接收完整串口命令标志
503 2 }
504 1 }
505
506 //=================================================================================================
507 // T1中断服务程序
508 //=================================================================================================
509 void T1_interrupt(void) interrupt 3
510 {
511 1 uchar key_value;
512 1 TH1=0x4c;//11.0592M晶振时T1定时时间长度为50毫秒
513 1 TL1=0x00;
514 1 t1_delay_time++;//在需要延时的地方清空并判断该变量
515 1 key_value=0xff;
516 1 //=================================================================================================
517 1 // 按住放手发射
518 1 //=================================================================================================
519 1 /*if(KEY_7279==0)
520 1 {key_press_counter++;
521 1 if(key_press_counter==4)
522 1 {key_value_previous=HD7279_GetKey();
523 1 }
524 1 }
525 1 else
526 1 {if(key_press_counter>4)
527 1 {key_value_main=key_value_previous;
528 1 }
529 1 key_press_counter=0;
530 1 }
531 1 */
532 1 //=================================================================================================
533 1 //0.5秒延时发送
534 1 //=================================================================================================
535 1 if(KEY_7279==0)
536 1 { key_press_timer++;
537 2 if(key_press_counter==0)
538 2 {key_value_previous=HD7279_GetKey();
539 3 }
540 2 if(key_press_timer>10)
541 2 {key_value=HD7279_GetKey();
542 3 if(key_value!=key_value_previous)
543 3 {key_value_main=0xff;
544 4 key_value=0xff;
545 4 key_value_previous=0xff;
546 4 key_press_timer=0;
547 4 key_press_counter=0;
548 4 }
549 3 else
550 3 {key_value_main=key_value_previous;
551 4 key_press_timer=0;
C51 COMPILER V7.06 MCS51__钅靠猒_____ 12/10/2008 19:58:27 PAGE 10
552 4 key_press_counter=0;
553 4 }
554 3 }
555 2 }
556 1 //=================================================================================================
557 1 //老师给通用延时
558 1 //=================================================================================================
559 1
560 1 /* if(!KEY_7279)//如果有按键触发,则取出该键键值
561 1 {key_value=HD7279_GetKey();
562 1 }
563 1 if(key_value!=0xff)//有键触发
564 1 {
565 1 if(key_press_counter==0)//如果上一次T1中断没发现按键触发,而本次T1中断发现了,做如下处理
566 1 {key_value_previous=key_value;//保存本次键值
567 1 key_press_counter+=1;//按键计数器加1
568 1 }
569 1 else//如果再次T1中断时key_press_counter不为0且键值与上次键值相等,则按键完成了50毫秒延时消抖
570 1 {if(key_value_previous==key_value)
571 1 {key_value_main=key_value;}//key_value_main中存储的键值在主程序中使用和清除
572 1 }
573 1 }
574 1 else//不管上次是否有键触发,只要本次无键触发就清空按键计数器,即如果按键时间不能持续50毫秒以上则重新判断
575 1 {key_press_counter=0;
576 1 }
577 1 */
578 1 }
579 //=================================================================================================
580 // end of the file
581 //=================================================================================================
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1464 ----
CONSTANT SIZE = 29 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 8 36
IDATA SIZE = 62 ----
BIT SIZE = 4 2
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -