📄 lpc935.lst
字号:
634 {
635 1
636 1 SIO_Out_Byte(AD_Load);
637 1 SIO_Out_Byte(AD_Battery);
638 1 SIO_Out_Byte(AD_Current);
639 1 SIO_Out_Byte(0x0D);
640 1 SIO_Out_Byte(0x0A);
641 1 //Snd_Time_Cnt=0;
642 1 }
643
644 /***********************************************************************
645 DESC: Initializes Counter/timers
646 Timer 0 is not used
647 Timer 1 generates an interrupt every 1 falling edges on T1
648 RETURNS: Nothing
649 CAUTION: If interrupts are being used then EA must be set to 1
650 after calling this function
651 ************************************************************************/
652 void Counter_init(void)
653 {
654 1 // configure timer 1
655 1 TMOD &= 0x0F;
656 1 TMOD |= 0x10;
657 1
658 1 // timer values
659 1 TH1 = 0x00;
660 1 TL1 = 0x00;
661 1
662 1
663 1 // enable timer 1 interrupt
664 1 ET1 = 1;
665 1
666 1 // stop timer 1
667 1 TR1 = 0;
668 1
669 1 } // timers_init
670
671 /***********************************************************************
672 DESC: Counter/Timer 1 Interrupt Service Routine
673 RETURNS: Nothing
674 CAUTION: timers_init must be called first
675 EA must be set to 1
C51 COMPILER V7.09 LPC935 03/14/2006 04:35:09 PAGE 12
676 ************************************************************************/
677 void Counter_isr(void) interrupt 3
678 {
679 1 // reinitialize
680 1 TH1 = 0x00;
681 1 TL1 = 0x00;
682 1 } // Counter_isr
683
684 /***********************************************************************
685 DESC: Starts Counter/timer 1
686 RETURNS: Nothing
687 CAUTION: timers_init must be called first
688 ************************************************************************/
689 void Counter_start(void)
690 {
691 1 TR1 = 1;
692 1 } // Counter_start
693
694 /***********************************************************************
695 DESC: Stops Counter/timer 1
696 RETURNS: Nothing
697 CAUTION: timers_init must be called first
698 ************************************************************************/
699 void Counter_stop(void)
700
701
702 {
703 1 TR1 = 0;
704 1 } // Counter_stop
705
706 /***********************************************************************
707 DESC: Generates a 13 us delay needed to stabilize a
708 comparator output after enabling.
709 Note that the datasheet mentions a 10 us delay.
710 Because the timer may be clocked from the watchdog timer, which
711 can be up to 30% faster than stated, 30% has been added to the
712 absolute minimum delay of 10us to give 13us.
713 Uses timer 0
714 Actual delay: 13.02 us
715 RETURNS: Nothing
716 CAUTION: The delay must be an absolute minimum of 10us
717 ************************************************************************/
718 void comparators_13usdelay(void)
719 {
720 1 /*
721 1 // ensure timer 0 stopped
722 1 TR0 = 0;
723 1 // configure timer 0 as 16-bit timer
724 1 TMOD &= 0xF0;
725 1 TMOD |= 0x01;
726 1 TAMOD &= 0xFE;
727 1 // set reload value
728 1 TH0 = 0xFF;
729 1 TL0 = 0xD0;
730 1 // disable timer interrupt
731 1 ET0 = 0;
732 1 // run timer and wait for overflow
733 1 TF0 = 0;
734 1 TR0 = 1;
735 1 while (!TF0);
736 1 // stop timer and clean up
737 1 TR0 = 0;
C51 COMPILER V7.09 LPC935 03/14/2006 04:35:09 PAGE 13
738 1 TF0 = 0;
739 1 */
740 1 }
741
742 /***********************************************************************
743 DESC: Initializes a comparator
744 Selects the comparator inputs/reference voltage source, enables
745 comparator output, enables comparator, configures I/O pins
746 needed, enables interrupts
747 If a comparator is being enabled then comparators_13usdelay
748 is called to provide a 13us delay to stabilize the comparator
749 RETURNS: Nothing
750 CAUTION: Set EA to 1 to enable interrupts after calling
751 ************************************************************************/
752 void comparators_init()
753
754 {
755 1 P0M1 |= 0x10;
756 1 P0M2 &= ~0x10;
757 1 PT0AD |= 0x10;
758 1 CMP1=0x28;
759 1 // enable comparator interrupt
760 1 delayms(1);
761 1 EC = 1;
762 1 }
763
764 /***********************************************************************
765 DESC: Comparator Interrupt Service Routine
766 Uses register bank 1
767 RETURNS: Nothing
768 CAUTION: comparators_init must be called and EA set to 1 to enable
769 interrupts.
770 Called when the output of any enabled comparator changes
771 ************************************************************************/
772 void comparators_isr(void) interrupt 8
773 {
774 1 byte temp_TH1,temp_TL1;
775 1 // check if comparator 1 caused interrupt
776 1 EA=0;
777 1 temp_TH1=TH1;
778 1 temp_TL1=TL1;
779 1 LED7=1;
780 1 delayms(2);
781 1 LED7=0;
782 1 if (CMP1 & 0x01)
783 1 {
784 2 // clear interrupt flag
785 2 CMP1 &= ~0x01;
786 2 Counter_stop();
787 2 SIO_Out_Byte(Temp_TH);
788 2 SIO_Out_Byte(temp_TH1);
789 2 SIO_Out_Byte(temp_TL1);
790 2 SIO_Out_Byte(0x0D);
791 2 SIO_Out_Byte(0x0A);
792 2 Flag_GetCounter=true;
793 2 }
794 1 // check if comparator 2 caused interrupt
795 1 if (CMP2 & 0x01)
796 1 {
797 2 // clear interrupt flag
798 2 CMP2 &= ~0x01;
799 2 }
C51 COMPILER V7.09 LPC935 03/14/2006 04:35:09 PAGE 14
800 1 EA=1;
801 1 }
802
803 /***********************************************************************
804 DESC: Disables a comparator
805 RETURNS: Nothing
806 CAUTION: The port pins used by the comparator are not reconfigured to
807 be digital inputs or outputs.
808 ************************************************************************/
809 void comparators_disable
810 (
811 bit compnum // comparator number: COMP_1 or COMP_2
812 )
813 {
814 1 // disable comparator 1
815 1 if (compnum == COMP_1)
816 1 {
817 2 CMP1 &= ~0x20;
818 2 }
819 1 // disable comparator 2
820 1 else
821 1 {
822 2 CMP2 &= ~0x20;
823 2 }
824 1 }
825
826 /***********************************************************************
827 DESC: Gets the current output of a comparator
828 RETURNS: Current comparator output
829 CAUTION: comparators_init must be called first
830 ************************************************************************/
831 bit comparators_getoutput
832 (
833 bit compnum // comparator number: COMP_1 or COMP_2
834 )
835 {
836 1 // get output of comparator 1
837 1 if (compnum == COMP_1)
838 1 {
839 2 return (CMP1 >> 1) & 0x01;
840 2 }
841 1 // get output of comparator 2
842 1 else
843 1 {
844 2 return (CMP2 >> 1) & 0x01;
845 2 }
846 1 }
847
848 /***********************************************************************
849 DESC: Selects a positive input source for a comparator
850 RETURNS: Nothing
851 CAUTION: comparators_init must be called first.
852 The comparator interrupt is disabled while the input is
853 changed. This means that the other comparator not being changed
854 will also not generate an interrupt.
855 ************************************************************************/
856 void comparators_selectposinput
857 (
858 bit compnum, // comparator number: COMP_1 or COMP_2
859 unsigned char posinput // positive input A or B: COMP_INPUTA or COMP_INPUTB
860 )
861 {
C51 COMPILER V7.09 LPC935 03/14/2006 04:35:09 PAGE 15
862 1 // disable comparator interrupt
863 1 EC = 0;
864 1
865 1 // configure comparator 1
866 1 if (compnum == COMP_1)
867 1 {
868 2 // initialize port pins according to configuration
869 2 if (posinput == COMP_INPUTA)
870 2 {
871 3 // select CIN1A as analog input
872 3 P0M1 |= 0x10;
873 3 P0M2 &= ~0x10;
874 3 PT0AD |= 0x10;
875 3 }
876 2 else
877 2 {
878 3 // select CIN1B as analog input
879 3 P0M1 |= 0x08;
880 3 P0M2 &= ~0x08;
881 3 PT0AD |= 0x08;
882 3 }
883 2 // clear input selection
884 2 CMP1 &= ~0x10;
885 2 // select new input
886 2 CMP1 |= posinput;
887 2 }
888 1 // configure comparator 2
889 1 else
890 1 {
891 2 // initialize port pins according to configuration
892 2 if (posinput == COMP_INPUTA)
893 2 {
894 3 // select CIN2A as analog input
895 3 P0M1 |= 0x04;
896 3 P0M2 &= ~0x04;
897 3 PT0AD |= 0x04;
898 3 }
899 2 else
900 2 {
901 3 // select CIN2B as analog input
902 3 P0M1 |= 0x02;
903 3 P0M2 &= ~0x02;
904 3 PT0AD |= 0x02;
905 3 }
906 2 // clear input selection
907 2 CMP2 &= ~0x10;
908 2 // select new input
909 2 CMP2 |= posinput;
910 2 }
911 1
912 1 // enable comparator interrupt
913 1 EC = 1;
914 1 }
915
916 void Get_Count()
917 {
918 1 EA=0;
919 1 DIVM=1;
920 1 Init_IO();
921 1 LED7=0;
922 1 Counter_init();
923 1 PDA=Low;
C51 COMPILER V7.09 LPC935 03/14/2006 04:35:09 PAGE 16
924 1 delayms(200);
925 1 LED7=1;
926 1 delayms(1);
927 1 LED7=0;
928 1 TH1 = 0x00;
929 1 TL1 = 0x00;
930 1 TR1=1;
931 1 P0M1 |= 0x10;
932 1 P0M2 &= ~0x10;
933 1 PT0AD |= 0x10;
934 1 CMP1=0x28;
935 1 EC = 1;
936 1
937 1 TR0=0;
938 1 EA=1;
939 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1722 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 26 ----
PDATA SIZE = ---- ----
DATA SIZE = 24 ----
IDATA SIZE = ---- ----
BIT SIZE = 10 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -