main.lst
来自「这是一整套USB2.0试验程序」· LST 代码 · 共 1,034 行 · 第 1/5 页
LST
1,034 行
594 DAC0H = CylinderPressValue[z-1000]>>8;
595 }
596 }
597 else
598 {
599 z = 0;
600 }
601 }*/
602 /*void PCAInterrupt(void) interrupt 9 //using 3 //IRQ_VECT_CT0
603 {
604 if(CCF1)
605 {
606 CCF1 = 0;
607 PCA0L = 0;
608 PCA0H = 0;
609 // CEX1=!CEX1;
610 if(Cex1Flag)//(CEX1==1)
611 {
612 if(SwitchUp)
C51 COMPILER V7.50 MAIN 04/22/2008 11:45:45 PAGE 11
613 {
614 if(COUNTER<StepCounter[0]) //加速过程
615 {
616 PCA0CPL1 = PCACPAL[COUNTER];
617 PCA0CPH1 = PCACPAH[COUNTER];
618 if(COUNTER == BDBegin)
619 P4 &= 0xf7;
620 if(COUNTER == BDEnd)
621 P4 |= 0x08;
622 COUNTER++;
623 }
624 else if(COUNTER<=StepCounter[1]) //下降过程
625 {
626 PCA0CPL1 = PCACPAL[StepCounter[1]-COUNTER];
627 PCA0CPH1 = PCACPAH[StepCounter[1]-COUNTER];
628 COUNTER++;
629 }
630 else
631 {
632 SwitchUp=0;
633 bUp = 1;
634 COUNTER=0;
635 StateCode = 0;
636 PCA0CPL1 = 34560;
637 PCA0CPH1 = 34560>>8;
638 Putf(18,68,"62",fSpeedTime,0);
639 Putstr(PromptX3,PromptY3,"空确认键开始加速空",0,0);
640 }
641 }
642 else if(FunctionCode == 3) //闭合角检定时改变比较器值
643 {
644 P4 |= 0x08;
645 PCA0CPL1 = pcacpLH;
646 PCA0CPH1 = pcacpHH;
647 }
648 CylinderCounter++;
649 if(CylinderCounter > CylinderNumberEnd)
650 {
651 CylinderCounter = 1;//101;
652 P4 |= 0x01;
653 if(FunctionCode == 4)
654 {
655 if(bAhead2)//已经取得主程序计数值
656 {
657 // if(!bAhead3)
658 // {
659 bAhead3 = 1;
660 mainfunccounter = AheadCounters;
661 PressValue = PressValueStart;
662 P4 &= 0xf7;
663 TMR3L = TMR3RLL;
664 TMR3H = TMR3RLH;
665 TMR3CN = 0x05;
666 // }
667 }
668 else
669 {
670 //第一步,先通知主程序对这个脉冲周期进行计数并记录计数值
671 if(!bAhead0)
672 {
673 COUNTER = 0;
674 bAhead0 = 1;
C51 COMPILER V7.50 MAIN 04/22/2008 11:45:45 PAGE 12
675 }
676 else if(!bAhead1)//停止计数
677 {
678 bAhead1 = 1;
679 bAhead0 = 0;
680 }
681 }
682 }
683 else if(FunctionCode == 7) //闪光角检定时标志信号
684 {
685 if(bFlash)
686 {
687 P4 &= 0xf7;
688 TMR3L = TMR3RLL;
689 TMR3H = TMR3RLH;
690 TMR3CN = 0x05;
691 bFlash = 0;
692 }
693 }
694 }
695 // else
696 // {
697 // if(FunctionCode == 4)
698 // PressValue = 0;
699 // }
700 }
701 else
702 {
703 if(FunctionCode == 3)
704 {
705 P4 &= 0xf7;
706 PCA0CPL1 = pcacpLL;
707 PCA0CPH1 = pcacpHL;
708 }
709 P4 &= 0xfe;
710 }
711
712 }
713 else if (CCF0)
714 {
715 CCF0 = 0;
716 PCA0L = 0;
717 PCA0H = 0;
718 }
719 else if (CCF2)
720 CCF2 = 0;
721 else if (CCF3)
722 CCF3 = 0;
723 else if (CCF4)
724 CCF4 = 0;
725 else if (CF)
726 CF = 0;
727 }
728
729 void Timer3(void) interrupt 14 //using 3 //用timer3来计时,优先级要置高
730 {
731 TMR3CN &= 0x7f;
732 // COUNTER = AheadCounterLimit;
733 P4 |= 0x08;
734 bAhead3 = 0; //标志
735 TMR3CN = 0x01; //timer3外部时钟的8分频 ,停止
736 }
C51 COMPILER V7.50 MAIN 04/22/2008 11:45:45 PAGE 13
737 void SetFreq(float freq)
738 {
739 uchar temp; //Timer0高字节重载值
740
741 CKCON &= 0xf0; //Timer0使用系统时钟/12
742 TMOD = 0x02; //Timer0设定为8位重载
743
744 PCADRVCLOCK = SYSCLOCK/12;
745 PCADRVCLOCK = PCADRVCLOCK/256;//
746 temp = PCADRVCLOCK/2/freq;
747
748 PCA0CN = 0x40; //pca使能
749 PCA0MD = 0x84; //选用TIMER0的溢出为驱动时钟
750 PCA0CPM1 = 0x46; //pca1为频率输出方式,禁止CCFn中断
751
752 PCA0CPL1 = 0;
753 PCA0CPH1 = temp;
754
755 TL0 = 0;
756 TH0 = 0;
757 TR0 = 1;
758
759 }
760 void SetWrithe()
761 {
762
763 float freq;
764 uchar Timer0H; //Timer0高字节重载值
765 // uint outCounter;
766 uint outCounter1;
767 // float k=1.0008807750820722235567299223317;
768 // float b=0.20017615501641444471134598446633; //调整系数
769 // WRITHE = withe;
770 // EIE1 &= 0xf7;//禁止PCA中断
771
772 freq = (float)WRITHE*CYLINDERNUMBER/120;
773 freq = freq*fSpeedParaMul+fSpeedParaAdd;
774 DisplayCounter = (int)(freq+0.5);//间隔1秒左右显示转速
775 FlashDisplayCounter = DisplayCounter/CYLINDERNUMBER;
776 if(freq >= 11)
777 {
778 //校正频率
779 // k = 1.0021620139889821291195430147937;
780 // b = 0.02782397050110974542174747322905;
781 // freq = freq*k-b;
782 PCADRVCLOCK = SYSCLOCK/8;
783 outCounter = (float)PCADRVCLOCK/freq/2+0.5;
784 outCounter -= 6;
785 PCA0CN = 0x40;
786 PCA0MD = 0x8a;
787 PCA0CPM1 = 0x4D;
788
789 //标准缸信号
790 // PCA0MD = 0x0a;
791 // PCA0CPM0 = 0x4D;
792 }
793 else if(freq>=0.8)
794 {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?