📄 main.lst
字号:
282 4 switch (CommandNum)
283 4 {
284 4 case 0x46:
285 4 SerBuffer[1] = 0x46; //读卡命令
286 4 SerBuffer[3] = BlockNum ; //卡块号(0-63): =8(8,9,10)
287 4 cmd_execution();
288 4 TransHexAsi(&SerBuffer[3],SendBuffer,16);
289 4 SendDataToPc(SendBuffer,32);
290 4 break;
291 4
292 4 case 0x47:
293 4 SerBuffer[1] = 0x47; //写卡命令
294 4 SerBuffer[3] = BlockNum ; //卡块号
295 4
296 4 memcpy(&SerBuffer[4],CardData,16);// 16字节 写卡数据
297 4
298 4 cmd_execution();
299 4 if(!ErrNum)
300 4 {
301 4 SerBuffer[3] = 0x0;
302 4 TransHexAsi(&SerBuffer[3],SendBuffer,1);
303 4 SendDataToPc(SendBuffer,2);
C51 COMPILER V6.23a MAIN 09/14/2004 14:19:20 PAGE 6
304 4 RingOn();
305 4 }
306 4 break;
307 4
308 4 default:
309 4 break;
310 4
311 4 }
312 4
313 4 }
314 4
315 4 }
316 4
317 4 }
318 4
319 4 */
320 4
321 4 }
322 3
323 3 }
324 2
325 2 // delay_10ms(50);
326 2
327 2
328 2 if(ErrNum)
329 2 {
330 3 delay_10ms(5);
331 3 /*
332 3 SerBuffer[3] = ErrNum ;
333 3 TransHexAsi(&SerBuffer[3],SendBuffer,1);
334 3 SendDataToPc(SendBuffer,2);
335 3 */
336 3 }
337 2
338 2 }
339 1
340 1 }
341
342 /****************************************************************************
343 * *
344 * Function: init *
345 * *
346 * Input: - *
347 * Output: - *
348 * *
349 * Description: *
350 * *
351 * *
352 ****************************************************************************/
353
354 void init (void)
355 {
356 1
357 1 AuthOk = 0xff;
358 1
359 1 AccOk = FALSE;
360 1 //EnOnChipSram(); // Enable w77e58 on chip 1k sram
361 1 #ifdef w77e58
DME0 = TRUE;
PMR = 0x41;
#endif
365 1
C51 COMPILER V6.23a MAIN 09/14/2004 14:19:20 PAGE 7
366 1 #ifdef sst89e554
367 1 AUXR = 0;
368 1 #endif
369 1 LED = ON;
370 1 BEEP = BeepOn;
371 1 BEEP = BeepOff;
372 1 RC500RST = FALSE;
373 1 //RC500_CS = TRUE; // Enable the CS for RC500
374 1
375 1 CmdReceived = FALSE;
376 1 CmdValid = FALSE;
377 1 Quit = FALSE;
378 1 LLfReady = TRUE;
379 1 SendReady = TRUE;
380 1 Idle = TRUE;
381 1
382 1 RepCnt = 0;
383 1
384 1 RecvState = RECV_STX;
385 1
386 1 EnableTransferCmd = FALSE;
387 1
388 1 CheckByteCnt = BCC_CHECKBYTECNT;
389 1
390 1 #ifdef AUTODELAY
391 1 DelayRate = 0;
392 1 DelayRateLocked = TRUE;
393 1 #endif
394 1
395 1 FrameEnd = 0;
396 1 FrameHead = 0;
397 1 FrameOk = 0;
398 1 DataNum = 0;
399 1 ChkSum = 0;
400 1
401 1 PCON = 0x00; // SMOD = 1;
402 1 SCON = 0x50; // Mode 1, 8-bit UART, enable receiption
403 1
404 1 // EIE = 0x0 ;
405 1 // AutoBaud = TRUE;
406 1 TMOD = 0x20; // Timer 1, mode 2, 8-bit auto reload,
407 1 // Timer 0, mode 0, 13-bit counter
408 1 Capt_L = 0;
409 1 Capt_H = 0;
410 1
411 1 TH1 = 0xfd ;
412 1 TL1 = 0xfd ;
413 1
414 1 ES = 1 ;
415 1 TR1 = 1;
416 1
417 1 // LED = 0;
418 1 // delay_10ms(10);
419 1 // LED = 1;
420 1
421 1
422 1 PX1 = 1;
423 1 IT1 = 1; // Config ext1 as edge trigger for RC500
424 1 EX1 = 1; // Enable ext1 interrupt for RC500
425 1 RC500RST = TRUE;
426 1 EIE = 0x0;
427 1 EA = TRUE; // Enable all interrupts
C51 COMPILER V6.23a MAIN 09/14/2004 14:19:20 PAGE 8
428 1 OpenIO();
429 1 }
430
431
432 /****************************************************************************
433 * *
434 * Function: cmd_execution *
435 * *
436 * Input: SerBuffer[] *
437 * Output: SerBuffer[] *
438 * *
439 * Description: *
440 * *
441 * *
442 ****************************************************************************/
443
444 void cmd_execution (void)
445 {
446 1 uchar xdata Status;
447 1 uchar xdata len;
448 1 uchar xdata cmd;
449 1 uchar xdata adr;
450 1 uchar xdata tmp[16];
451 1 //uchar xdata snr[4];
452 1 uchar xdata size;
453 1 uchar xdata tt[2];
454 1 static uchar xdata mode,value[4],addr;
455 1 Temp = SerBuffer;
456 1
457 1 cmd = SerBuffer[COMMAND]; //COMMAND == 1
458 1
459 1 switch (cmd)
460 1 {
461 2 case 0x40: //PICC_REQALL
462 2
463 2 Status = M500PiccRequest(PICC_REQALL, tt); //Get Picc tt[]: Tagtype 2 Byte
464 2 ErrNum = Status;
465 2 if (Status != MI_OK)
466 2 {
467 3 AccOk = 0;
468 3
469 3 }
470 2 else
471 2 {
472 3 // RingOn();
473 3 AccOk = 1;
474 3 }
475 2 ErrNum = Status;
476 2 break;
477 2
478 2
479 2
480 2 case 0x41: // Request
481 2
482 2 if(SerBuffer[MODE]&0X01) SerBuffer[MODE]=PICC_REQALL; // ALL
483 2 else SerBuffer[MODE]=PICC_REQSTD; // IDLE
484 2
485 2 Status = M500PiccRequest(SerBuffer[MODE], &SerBuffer[TAGTYPE]);
486 2
487 2 if (Status == MI_OK)
488 2 {
489 3 SerBuffer[LENGTH] = 2;
C51 COMPILER V6.23a MAIN 09/14/2004 14:19:20 PAGE 9
490 3 }
491 2 ErrNum = Status;
492 2 break;
493 2
494 2
495 2 case 0x42: // Anticoll
496 2
497 2 Status = M500PiccAnticoll(SerBuffer[BCNT], &SerBuffer[SERNR]);
498 2
499 2 if (Status == MI_OK)
500 2 {
501 3 SerBuffer[LENGTH] = 4;
502 3 // RingOn();
503 3 AccOk = 1;
504 3 }
505 2 ErrNum = Status;
506 2 break;
507 2
508 2
509 2 case 0x43: // Select
510 2
511 2 memcpy(card_snr,&SerBuffer[SERNR],4); // store serial number in globle var
512 2
513 2 //输入: 卡片序列号 输出:卡片容量 SIZE = 0X88H
514 2 Status = M500PiccSelect(&SerBuffer[SERNR], &SerBuffer[SIZE]);
515 2 if (Status == MI_OK)
516 2 {
517 3 SerBuffer[LENGTH] = 1;
518 3 }
519 2
520 2 // RingOn();
521 2
522 2 AccOk = 1;
523 2 ErrNum = Status;
524 2
525 2 break;
526 2
527 2
528 2 case 0x44: // Authentication
529 2
530 2 if(SerBuffer[MODE]&0X04) SerBuffer[MODE]=PICC_AUTHENT1B; // keyB
531 2 else SerBuffer[MODE]=PICC_AUTHENT1A; // keyA =0x60 MODE =3 key_sector = SerBuffer[4] block = 9 SerBuf
-fer[SECNR]+1)*4-1 SECNR= 4
532 2
533 2 Status = M500PiccAuth(SerBuffer[MODE], card_snr, SerBuffer[SECNR], (SerBuffer[SECNR]+1)*4-1);
534 2
535 2 // Status = M500PiccAuthE2(SerBuffer[MODE], card_snr, SerBuffer[SECNR], (SerBuffer[SECNR]+1)*4-1);
536 2
537 2 AuthOk = Status;
538 2 ErrNum = Status;
539 2
540 2 break;
541 2
542 2
543 2 case 0x45: // Halt
544 2
545 2 Status = M500PiccHalt();
546 2 break;
547 2
548 2
549 2 case 0x46: // Read
550 2
C51 COMPILER V6.23a MAIN 09/14/2004 14:19:20 PAGE 10
551 2 Status = M500PiccRead(SerBuffer[ADR], &SerBuffer[ADR]);//ADR = 3
552 2 if (Status == MI_OK)
553 2 {
554 3 SerBuffer[LENGTH] = 16;
555 3 }
556 2 ErrNum = Status;
557 2 break;
558 2
559 2
560 2 case 0x47: // Write
561 2
562 2 Status = M500PiccWrite(SerBuffer[ADR], &SerBuffer[DATABYTES]);
563 2 ErrNum = Status;
564 2 break;
565 2
566 2
567 2 case 0x48: // Increment
568 2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -