📄 main.lst
字号:
863 2
864 2 TH0 = 0xE0;
865 2 TL0 = 0;
866 2 TR0 = TRUE;
867 2 while (!TF0); // Wait 4.4 ms
868 2 TR0 = FALSE;
869 2 TF0 = FALSE;
870 2 ET0 = TRUE;
871 2
872 2 AutoBaud = FALSE; // Baudrate had been choose, disable Autobaud
873 2
874 2 SBUF = NAK;
875 2 while (!TI);
876 2 TI = FALSE;
877 2 RI = FALSE;
878 2 ES = TRUE;
879 2 }
880 1 }
881
882 #pragma noaregs
883
884 /****************************************************************************
885 * *
886 * Function: delay_50us *
887 * *
888 * Input: _50us *
889 * Output: - *
890 * *
891 * Description: *
892 * *
893 * Time delay with a resolution of 50 us. *
894 * *
895 ****************************************************************************/
896
897 void delay_50us (uchar _50us)
898 {
899 1
900 1 RCAP2LH = RCAP2_50us;
901 1 T2LH = RCAP2_50us;
902 1 ET2 = 0; // Disable timer2 interrupt
903 1 T2CON = 0x04; // 16-bit auto-reload, clear TF2, start timer
904 1
905 1 while (_50us--)
906 1 {
907 2 while (!TF2);
908 2 TF2 = FALSE;
909 2 }
910 1
911 1 TR2 = FALSE;
912 1
913 1 }
914
915
916 /****************************************************************************
917 * *
918 * Function: delay_1ms *
919 * *
920 * Input: _1ms *
921 * Output: - *
922 * *
C51 COMPILER V7.06 MAIN 02/25/2005 08:31:59 PAGE 16
923 * Description: *
924 * *
925 * Time delay with a resolution of 1 ms. *
926 * *
927 ****************************************************************************/
928
929 void delay_1ms (uchar _1ms)
930 {
931 1
932 1 RCAP2LH = RCAP2_1ms;
933 1 T2LH = RCAP2_1ms;
934 1 ET2 = 0; // Disable timer2 interrupt
935 1 T2CON = 0x04; // 16-bit auto-reload, clear TF2, start timer
936 1
937 1 while (_1ms--)
938 1 {
939 2 while (!TF2);
940 2 TF2 = FALSE;
941 2 }
942 1 TR2 = FALSE;
943 1
944 1 }
945
946
947 /****************************************************************************
948 * *
949 * Function: delay_10ms *
950 * *
951 * Input: _10ms *
952 * Output: - *
953 * *
954 * Description: *
955 * *
956 * Time delay with a resolution of 10 ms. *
957 * *
958 ****************************************************************************/
959
960 void delay_10ms (uint _10ms)
961 {
962 1
963 1 RCAP2LH = RCAP2_10ms;
964 1 T2LH = RCAP2_10ms;
965 1 ET2 = 0; // Disable timer2 interrupt
966 1 T2CON = 0x04; // 16-bit auto-reload, clear TF2, start timer
967 1
968 1
969 1 while (_10ms--)
970 1 {
971 2 while (!TF2)
972 2 {
973 3 if (CmdValid || CmdReceived)
974 3 {
975 4 TR2 = FALSE;
976 4 TF2 = FALSE;
977 4 return;
978 4 }
979 3 }
980 2 TF2 = FALSE;
981 2 }
982 1 TR2 = FALSE;
983 1
984 1 }
C51 COMPILER V7.06 MAIN 02/25/2005 08:31:59 PAGE 17
985
986
987
988 void test_10ms(uint n_10ms)
989 {
990 1
991 1 RCAP2LH = RCAP2_10ms;
992 1 T2LH = RCAP2_10ms;
993 1 ET2 = 0; // Disable timer2 interrupt
994 1 T2CON = 0x04; // 16-bit auto-reload, clear TF2, start timer
995 1
996 1
997 1 while (n_10ms--)
998 1 {
999 2 while (!TF2)
1000 2 {
1001 3 if (CmdValid || CmdReceived)
1002 3 {
1003 4 TR2 = FALSE;
1004 4 TF2 = FALSE;
1005 4 return;
1006 4 }
1007 3 }
1008 2 TF2 = FALSE;
1009 2 }
1010 1 TR2 = FALSE;
1011 1
1012 1 }
1013
1014
1015
1016
1017
1018
1019
1020 #ifdef NOP_DELAY
/****************************************************************************
* *
* Function: delay_50us_NOP *
* *
* Input: - *
* Output: - *
* *
* Description: 延时函数 *
* *
* *
* *
****************************************************************************/
void delay_50us_NOP (void)
{
uchar i;
for(i=0; i<81; i++) _nop_();
}
#endif
1043
1044
1045 /****************************************************************************
1046 * *
C51 COMPILER V7.06 MAIN 02/25/2005 08:31:59 PAGE 18
1047 * Function: delay_8us_NOP *
1048 * *
1049 * Input: - *
1050 * Output: - *
1051 * *
1052 * Description: *
1053 * *
1054 * *
1055 ****************************************************************************/
1056
1057 void delay_8us_NOP (void)
1058 {
1059 1 uchar i;
1060 1
1061 1 for(i=0; i<14; i++) _nop_();
1062 1 }
1063
1064
1065 /*****************************************************
1066
1067
1068 *******************************************************/
1069 void RingOn (void)
1070 {
1071 1 BEEP = 0;
1072 1 delay_10ms(2);
1073 1 BEEP = 1;
1074 1 delay_10ms(2);
1075 1 BEEP = 0;
1076 1 delay_10ms(2);
1077 1 BEEP = 1;
1078 1 /*
1079 1 delay_10ms(2);
1080 1 BEEP = 0;
1081 1 delay_10ms(2);
1082 1 BEEP = 1;
1083 1 */
1084 1 }
1085
1086
1087 #pragma aregs
1088
1089
1090 /****************************************************************************
1091 * *
1092 * Function: xtoa_h *
1093 * *
1094 * Input: _byte *
1095 * Output: ASCII High-Nibble *
1096 * *
1097 * Description: *
1098 * *
1099 * Wandelt das High-Nibble des 乥ergebenen Bytes in ein ASCII-Zeichen um. *
1100 * *
1101 ****************************************************************************/
1102
1103 uchar xtoa_h (uchar _byte)
1104 {
1105 1 uchar nibble = _byte >> 4;
1106 1
1107 1 return ((nibble > 9)? nibble + 'A' - 10 : nibble + '0');
1108 1 }
C51 COMPILER V7.06 MAIN 02/25/2005 08:31:59 PAGE 19
1109
1110
1111 /****************************************************************************
1112 * *
1113 * Function: xtoa_l *
1114 * *
1115 * Input: _byte *
1116 * Output: ASCII Low-Nibble *
1117 * *
1118 * Description: *
1119 * *
1120 * Wandelt das Low-Nibble des 乥ergebenen Bytes in ein ASCII-Zeichen um. *
1121 * *
1122 ****************************************************************************/
1123
1124 uchar xtoa_l (uchar _byte)
1125 {
1126 1 uchar nibble = _byte & 0x0F;
1127 1
1128 1 return ((nibble > 9)? nibble + 'A' - 10 : nibble + '0');
1129 1 }
1130
1131
1132 /****************************************************************************
1133 * *
1134 * Function: isr_timer0 *
1135 * *
1136 * Input: - *
1137 * Output: - *
1138 * *
1139 * Description: *
1140 * *
1141 * *
1142 ****************************************************************************/
1143
1144 void isr_timer0 (void) interrupt 1 using 2
1145 {
1146 1 if (Timer0Cnt)
1147 1 {
1148 2 --Timer0Cnt;
1149 2 }
1150 1 else
1151 1 {
1152 2 STOP_T0();
1153 2
1154 2 #ifdef AUTODELAY
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -