📄 main.lst
字号:
491 1 TL2 = 0xff;//(uchar)(~maxCaptureTimeLow);
492 1 TH2= 0xcf;//(uchar)((~maxCaptureTimeLow)>>8) ;
493 1 currentMaxTimeHi = 0xcf;//~maxCaptureTimeHi;
494 1 flag_tag_datarate_bigger=0;
495 1
496 1 for(j=0;j<32;j++)
497 1 {
498 2 autodection_data[j]=0;
499 2 }
500 1 for(i=0;i<0xf8;i++)
501 1 {
502 2 if(DEMOD_OUT == 0) //等待低电平,超时退出
503 2 break;
504 2 }
505 1 if(i>=0xf0)
506 1 {
507 2 return_00();
508 2 return;
509 2 }
510 1 for(i=0;i<0xf8;i++)
511 1 {
512 2 if(DEMOD_OUT == 1) //等待高电平,超时退出
513 2 break;
514 2 }
515 1 if(i>=0xf0)
516 1 {
517 2 return_00();
518 2 return;
519 2 }
520 1 ET2=1;
521 1 TR2=1; //counter 2 start run,interrupt enable
522 1 flag_wait=1;
523 1
524 1 while(flag_wait) //counter 2 is runing
525 1 {
526 2 for(i=0;i<0xf8;i++)
527 2 {
528 3 if(DEMOD_OUT == 0) //等待低电平,超时退出
529 3 break;
530 3 }
531 2 if(i>=0xf0)
532 2 {
533 3 return_00();
534 3 return;
535 3 }
536 2
537 2
538 2 icr=count_module();
539 2 capt=icr-last_capture;
540 2 last_capture=icr;
541 2 if ((capt>MaxCaptureHalfDateRate)&&(capt<MaxCaptureDateRate))
542 2 break; //1p hi,64个时钟
543 2 for(i=0;i<0xf8;i++)
544 2 {
545 3 if(DEMOD_OUT == 1) //等待高电平,超时退出
546 3 break;
547 3 }
548 2 if(i>=0xf0)
C51 COMPILER V7.50 MAIN 06/07/2006 18:04:04 PAGE 10
549 2 {
550 3 return_00();
551 3 return;
552 3 }
553 2
554 2 icr=count_module();
555 2 capt=icr-last_capture;
556 2 last_capture=icr;
557 2 }
558 1
559 1 flag_RO_last_capt_half=0;
560 1 flag_invalid_edge_manchester=0;
561 1 count_autodection_bit=0;
562 1 array_subscript=0;
563 1 bit_subscript=0;
564 1
565 1 // //manchester
566 1 times_capture_manchester=0;
567 1 while(flag_wait) //counter 2 is runing
568 1 {
569 2 for(i=0;i<0xf8;i++)
570 2 {
571 3 if(DEMOD_OUT == 1) //,test low time 等待高电平,超时退出
572 3 break;
573 3 }
574 2
575 2 if(i>=0xf0)
576 2 {
577 3 return_00();
578 3 return;
579 3 }
580 2
581 2 icr=count_module();
582 2 capt=icr-last_capture;
583 2 last_capture=icr;
584 2 if((capt<MaxCaptureHalfDateRate)&&(flag_invalid_edge_manchester==0))
585 2 { //0.5p low
586 3 flag_invalid_edge_manchester=1;
587 3 if((times_capture_manchester%2)==0)
588 3 {
589 4 array_subscript=(count_autodection_bit>>3);
590 4 bit_subscript=(count_autodection_bit%8);
591 4 autodection_data[array_subscript]=(autodection_data[array_subscript]|(1<<bit_subscript));
592 4 }
593 3 count_autodection_bit++;
594 3 }
595 2 else if ((capt<MaxCaptureHalfDateRate)&&(flag_invalid_edge_manchester==1))
596 2 { //0.5p low
597 3 flag_invalid_edge_manchester=0;
598 3 }
599 2 else if ((capt>MaxCaptureHalfDateRate)&&(capt<MaxCaptureDateRate))
600 2 { //1p low
601 3 if((times_capture_manchester%2)==0)
602 3 {
603 4 array_subscript=(count_autodection_bit>>3);
604 4 bit_subscript=(count_autodection_bit%8);
605 4 autodection_data[array_subscript]=(autodection_data[array_subscript]|(1<<bit_subscript));
606 4 }
607 3 count_autodection_bit++;
608 3 }
609 2 times_capture_manchester++;
610 2 //-----
C51 COMPILER V7.50 MAIN 06/07/2006 18:04:04 PAGE 11
611 2 for(i=0;i<0xf8;i++)
612 2 {
613 3 if(DEMOD_OUT == 0) //等待低电平,超时退出
614 3 break;
615 3 }
616 2 if(i>=0xf0)
617 2 {
618 3 return_00();
619 3 return;
620 3 }
621 2
622 2 icr=count_module();
623 2 capt=icr-last_capture;
624 2 last_capture=icr;
625 2 if((capt<MaxCaptureHalfDateRate)&&(flag_invalid_edge_manchester==0))
626 2 { //0.5p hi
627 3 flag_invalid_edge_manchester=1;
628 3 if((times_capture_manchester%2)==0)
629 3 {
630 4 array_subscript=(count_autodection_bit>>3);
631 4 bit_subscript=(count_autodection_bit%8);
632 4 autodection_data[array_subscript]=(autodection_data[array_subscript]|(1<<bit_subscript));
633 4 }
634 3 count_autodection_bit++;
635 3 }
636 2 else if ((capt<MaxCaptureHalfDateRate)&&(flag_invalid_edge_manchester==1))
637 2 { //0.5p hi
638 3 flag_invalid_edge_manchester=0;
639 3 }
640 2 else if ((capt>MaxCaptureHalfDateRate)&&(capt<MaxCaptureDateRate))
641 2 { //1p hi
642 3 if((times_capture_manchester%2)==0)
643 3 {
644 4 array_subscript=(count_autodection_bit>>3);
645 4 bit_subscript=(count_autodection_bit%8);
646 4 autodection_data[array_subscript]=(autodection_data[array_subscript]|(1<<bit_subscript));
647 4 }
648 3 count_autodection_bit++;
649 3 }
650 2 times_capture_manchester++;
651 2 }
652 1
653 1
654 1 //数据提取:找标志头、找停止位、检查校验和,一旦正确提取数据退出循环
655 1 if(count_autodection_bit>64)
656 1 {
657 2 flag_header_found=0;
658 2 for (j=0;j<(count_autodection_bit-54);j++) //找标志头9 bit 1
659 2 {
660 3 array_subscript=(j>>3);
661 3 bit_subscript=(j%8);
662 3 if ((autodection_data[array_subscript]&(1<<bit_subscript))==0) //不等于0,即可判断此位为1
663 3 {
664 4 flag_header_found=1;
665 4 for (k=(j+1);k<(j+10);k++)
666 4 {
667 5 array_subscript=(k>>3);
668 5 bit_subscript=(k%8);
669 5 if ((autodection_data[array_subscript]&(1<<bit_subscript))==0)
670 5 {
671 6 flag_header_found=0;
672 6 break;
C51 COMPILER V7.50 MAIN 06/07/2006 18:04:04 PAGE 12
673 6 }
674 5 }
675 4 if(flag_header_found==1) break;
676 4 }
677 3 }
678 2
679 2 flag_stop_found=0;
680 2 if (flag_header_found==1)//停止位
681 2 {
682 3 array_subscript=((j+64)>>3);
683 3 bit_subscript=((j+64)%8);
684 3 if ((autodection_data[array_subscript]&(1<<bit_subscript))==0) flag_stop_found=1;
685 3 }
686 2
687 2 flag_line_check=0;
688 2 if (flag_stop_found==1) //行校验
689 2 {
690 3 for (k=(j+10);k<(j+60);k=(k+5))
691 3 {
692 4 check=0;
693 4 for(l=k;l<(k+4);l++)
694 4 {
695 5 array_subscript=(l>>3);
696 5 bit_subscript=(l%8);
697 5 check=check^((autodection_data[array_subscript]>>bit_subscript)&1);
698 5 }
699 4 array_subscript=(l>>3);
700 4 bit_subscript=(l%8);
701 4 if ((autodection_data[array_subscript]&(1<<bit_subscript))!=(check<<bit_subscript))
702 4 {
703 5 flag_line_check=0;
704 5 break;
705 5 }
706 4 flag_line_check=1;
707 4 }
708 3 }
709 2
710 2 flag_column_check=0;
711 2 if (flag_line_check==1) //列校验
712 2 {
713 3 for(k=(j+10);k<(j+14);k++)
714 3 {
715 4 check=0;
716 4 for(l=k;l<(k+50);l=(l+5))
717 4 {
718 5 array_subscript=(l>>3);
719 5 bit_subscript=(l%8);
720 5 check=check^((autodection_data[array_subscript]>>bit_subscript)&1);
721 5 }
722 4 array_subscript=(l>>3);
723 4 bit_subscript=(l%8);
724 4 if ((autodection_data[array_subscript]&(1<<bit_subscript))!=(check<<bit_subscript))
725 4 {
726 5 flag_column_check=0;
727 5 break;
728 5 }
729 4 flag_column_check=1;
730 4 }
731 3 }
732 2
733 2 if (flag_column_check==1) //提取数据
734 2 {
C51 COMPILER V7.50 MAIN 06/07/2006 18:04:04 PAGE 13
735 3 custID=0;
736 3 DataItem[0]=0;DataItem[1]=0;DataItem[2]=0;DataItem[3]=0;
737 3 //客户ID
738 3 bit_number=0;
739 3 for (k=(j+10);k<(j+14);k++)
740 3 {
741 4 array_subscript=(k>>3);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -