📄 main.lst
字号:
926 2 SerBuffer[SECNR], SerBuffer[AUTHADD]);
927 2 break;
928 2
929 2
930 2 case 0x57: // Decrement+Transfer
931 2
932 2 Status = M500PiccValue(PICC_DECREMENT, SerBuffer[ADR], &SerBuffer[VALUE], SerBuffer[ADR]);
933 2 break;
934 2
935 2 default:
936 2
937 2 Status = MI_NY_IMPLEMENTED;
938 2 break;
939 2
940 2
941 2 } // end switch (Command)
942 1
943 1 SerBuffer[STATUS] = ~Status+1;
944 1
945 1 if (cmd < 0x48 || cmd > 0x4A)
946 1 {
947 2 EnableTransferCmd = FALSE;
948 2 }
949 1 else
950 1 {
951 2 EnableTransferCmd = TRUE;
952 2 }
953 1 }
954
955
956 /****************************************************************************
957 * *
958 * Function: auto_baud *
959 * *
960 * Input: - *
961 * Output: - *
962 * *
963 * Description: *
964 * *
965 * Mi醫 die Zeitspanne zwischen Start- und Stopbit des ersten empfangenen *
966 * Zeichens (STX) und ermittelt daraus die Baudrate. *
967 * *
968 ****************************************************************************/
969
970 void auto_baud (void)
971 {
972 1 //int temp;
973 1
974 1 if (AutoBaud && !RXD) // If autobaud is enable and RXD pin is low
975 1 {
976 2 TR0 = TRUE; // Start timer0
977 2
978 2 do
979 2 {
980 3 if (RXD) // When RXD pin is high
981 3 {
982 4 Capt_L = TL0;
C51 COMPILER V4.01, MAIN 29/08/06 08:02:00 PAGE 16
983 4 Capt_H = TH0;
984 4
985 4 do
986 4 {
987 5 if (!RXD)
988 5 {
989 6 break;
990 6 }
991 5 } while (!TF0);
992 4 }
993 3 } while (!TF0);
994 2
995 2 TR0 = FALSE;
996 2 TF0 = FALSE;
997 2
998 2 Capt = ((uint)Capt_H << 5) | ((uint)Capt_L & 0x001F);
999 2
1000 2 for (BaudRate = BAUD_CNT; BaudRate >= 0; BaudRate--)
1001 2 {
1002 3 if (Capt >= CmpTable[BaudRate])
1003 3 {
1004 4 break;
1005 4 }
1006 3 }
1007 2
1008 2 if (BaudRate < 0 || BaudRate == BAUD_CNT) // Error baud count
1009 2 {
1010 3 TH0 = 0;
1011 3 TL0 = 0;
1012 3 Capt_L = 0;
1013 3 Capt_H = 0;
1014 3 return;
1015 3 }
1016 2
1017 2 TMOD = 0x21; // Timer 0, mode 1, 16-bit counter
1018 2 TH1 = BaudRateTable[BaudRate];
1019 2 TL1 = TH1;
1020 2 TR1 = TRUE;
1021 2
1022 2 TH0 = 0xE0;
1023 2 TL0 = 0;
1024 2 TR0 = TRUE;
1025 2 while (!TF0); // Wait 4.4 ms
1026 2 TR0 = FALSE;
1027 2 TF0 = FALSE;
1028 2 ET0 = TRUE;
1029 2
1030 2 AutoBaud = FALSE; // Baudrate had been choose, disable Autobaud
1031 2
1032 2 SBUF = NAK;
1033 2 while (!TI);
1034 2 TI = FALSE;
1035 2 RI = FALSE;
1036 2 ES = TRUE;
1037 2 }
1038 1 }
1039
1040 #pragma noaregs
1041
1042 /****************************************************************************
1043 * *
1044 * Function: delay_50us *
1045 * *
1046 * Input: _50us *
1047 * Output: - *
1048 * *
C51 COMPILER V4.01, MAIN 29/08/06 08:02:00 PAGE 17
1049 * Description: *
1050 * *
1051 * Time delay with a resolution of 50 us. *
1052 * *
1053 ****************************************************************************/
1054
1055 void delay_50us (uchar _50us)
1056 {
1057 1
1058 1 RCAP2LH = RCAP2_50us;
1059 1 T2LH = RCAP2_50us;
1060 1 ET2 = 0; // Disable timer2 interrupt
1061 1 T2CON = 0x04; // 16-bit auto-reload, clear TF2, start timer
1062 1
1063 1 while (_50us--)
1064 1 {
1065 2 while (!TF2);
1066 2 TF2 = FALSE;
1067 2 }
1068 1
1069 1 TR2 = FALSE;
1070 1
1071 1 }
1072
1073
1074 /****************************************************************************
1075 * *
1076 * Function: delay_1ms *
1077 * *
1078 * Input: _1ms *
1079 * Output: - *
1080 * *
1081 * Description: *
1082 * *
1083 * Time delay with a resolution of 1 ms. *
1084 * *
1085 ****************************************************************************/
1086
1087 void delay_1ms (uchar _1ms)
1088 {
1089 1
1090 1 RCAP2LH = RCAP2_1ms;
1091 1 T2LH = RCAP2_1ms;
1092 1 ET2 = 0; // Disable timer2 interrupt
1093 1 T2CON = 0x04; // 16-bit auto-reload, clear TF2, start timer
1094 1
1095 1 while (_1ms--)
1096 1 {
1097 2 while (!TF2);
1098 2 TF2 = FALSE;
1099 2 }
1100 1 TR2 = FALSE;
1101 1
1102 1 }
1103
1104
1105 /****************************************************************************
1106 * *
1107 * Function: delay_10ms *
1108 * *
1109 * Input: _10ms *
1110 * Output: - *
1111 * *
1112 * Description: *
1113 * *
1114 * Time delay with a resolution of 10 ms. *
C51 COMPILER V4.01, MAIN 29/08/06 08:02:00 PAGE 18
1115 * *
1116 ****************************************************************************/
1117
1118 void delay_10ms (uint _10ms)
1119 {
1120 1
1121 1 RCAP2LH = RCAP2_10ms;
1122 1 T2LH = RCAP2_10ms;
1123 1 ET2 = 0; // Disable timer2 interrupt
1124 1 T2CON = 0x04; // 16-bit auto-reload, clear TF2, start timer
1125 1
1126 1
1127 1 while (_10ms--)
1128 1 {
1129 2 while (!TF2)
1130 2 {
1131 3 if (CmdValid || CmdReceived)
1132 3 {
1133 4 TR2 = FALSE;
1134 4 TF2 = FALSE;
1135 4 return;
1136 4 }
1137 3 }
1138 2 TF2 = FALSE;
1139 2 }
1140 1 TR2 = FALSE;
1141 1
1142 1 }
1143
1144
1145
1146 void test_10ms(uint n_10ms)
1147 {
1148 1
1149 1 RCAP2LH = RCAP2_10ms;
1150 1 T2LH = RCAP2_10ms;
1151 1 ET2 = 0; // Disable timer2 interrupt
1152 1 T2CON = 0x04; // 16-bit auto-reload, clear TF2, start timer
1153 1
1154 1
1155 1 while (n_10ms--)
1156 1 {
1157 2 while (!TF2)
1158 2 {
1159 3 if (CmdValid || CmdReceived)
1160 3 {
1161 4 TR2 = FALSE;
1162 4 TF2 = FALSE;
1163 4 return;
1164 4 }
1165 3 }
1166 2 TF2 = FALSE;
1167 2 }
1168 1 TR2 = FALSE;
1169 1
1170 1 }
1171
1172
1173
1174
1175
1176
1177
1178 #ifdef NOP_DELAY
/****************************************************************************
C51 COMPILER V4.01, MAIN 29/08/06 08:02:00 PAGE 19
* *
* Function: delay_50us_NOP *
* *
* Input: - *
* Output: - *
* *
* Description: 延时函数 *
* *
* *
* *
****************************************************************************/
void delay_50us_NOP (void)
{
uchar i;
for(i=0; i<81; i++) _nop_();
}
#endif
1201
1202
1203 /****************************************************************************
1204 * *
1205 * Function: delay_8us_NOP *
1206 * *
1207 * Input: - *
1208 * Output: - *
1209 * *
1210 * Description: *
1211 * *
1212 * *
1213 ****************************************************************************/
1214
1215 void delay_8us_NOP (void)
1216 {
1217 1 uchar i;
1218 1
1219 1 for(i=0; i<14; i++) _nop_();
1220 1 }
1221
1222
1223 /*****************************************************
1224
1225
1226 *******************************************************/
1227 void RingOn (void)
1228 {
1229 1 BEEP = 0;
1230 1 delay_10ms(2);
1231 1 BEEP = 1;
1232 1 delay_10ms(2);
1233 1 BEEP = 0;
1234 1 delay_10ms(2);
1235 1 BEEP = 1;
1236 1 delay_10ms(2);
1237 1 BEEP = 0;
1238 1 delay_10ms(2);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -