📄 m500auc.lst
字号:
278 1 return 0x00;
279 1 }
280
281 ///////////////////////////////////////////////////////////////////////
282 ///////////////////////////////////////////////////////////////////////
283 void FlushFIFO(void)
284 {
285 1 SetBitMask(RegControl,0x01);
286 1 }
287
288 ///////////////////////////////////////////////////////////////////////
289 // Value format operations for Mifare Standard card ICs
290 // dd_mode: 选择相关操作:Increment、Decrement、Restore
291 // addr: 卡的块源地址
292 // value: 存放 操作值的地址4Byte
293 // trans_addr: 卡的块目的地址
294 ///////////////////////////////////////////////////////////////////////
295 char M500PiccValue(unsigned char dd_mode,
296 unsigned char addr,
297 unsigned char *value,
298 unsigned char trans_addr)
299 {
300 1 char status = MI_OK;
301 1
302 1 M500PcdSetTmo(1);
303 1 ResetInfo(MInfo);
C51 COMPILER V6.02 M500AUC 02/09/2006 13:25:02 PAGE 6
304 1 SerBuffer[0] = dd_mode;
305 1 SerBuffer[1] = addr;
306 1 MInfo.nBytesToSend = 2;
307 1 status = M500PcdCmd(PCD_TRANSCEIVE,
308 1 SerBuffer,
309 1 &MInfo);
310 1
311 1 if (status != MI_NOTAGERR)
312 1 {
313 2 if (MInfo.nBitsReceived != 4)
314 2 {
315 3 status = MI_BITCOUNTERR;
316 3 }
317 2 else
318 2 {
319 3 SerBuffer[0] &= 0x0f;
320 3 switch(SerBuffer[0])
321 3 {
322 4 case 0x00:
323 4 status = MI_NOTAUTHERR;
324 4 break;
325 4 case 0x0a:
326 4 status = MI_OK;
327 4 break;
328 4 case 0x01:
329 4 status = MI_VALERR;
330 4 break;
331 4 default:
332 4 status = MI_CODEERR;
333 4 break;
334 4 }
335 3 }
336 2 }
337 1
338 1 if ( status == MI_OK)
339 1 {
340 2 M500PcdSetTmo(3);
341 2 ResetInfo(MInfo);
342 2 memcpy(SerBuffer,value,4);
343 2 MInfo.nBytesToSend = 4;
344 2 status = M500PcdCmd(PCD_TRANSCEIVE,
345 2 SerBuffer,
346 2 &MInfo);
347 2
348 2 if (status == MI_OK)
349 2 {
350 3 if (MInfo.nBitsReceived != 4)
351 3 {
352 4 status = MI_BITCOUNTERR;
353 4 }
354 3 else
355 3 {
356 4 SerBuffer[0] &= 0x0f;
357 4 switch(SerBuffer[0])
358 4 {
359 5 case 0x00:
360 5 status = MI_NOTAUTHERR;
361 5 break;
362 5 case 0x01:
363 5 status = MI_VALERR;
364 5 break;
365 5 default:
C51 COMPILER V6.02 M500AUC 02/09/2006 13:25:02 PAGE 7
366 5 status = MI_CODEERR;
367 5 break;
368 5 }
369 4 }
370 3 }
371 2 else
372 2 {
373 3 if (status == MI_NOTAGERR )
374 3 status = MI_OK;
375 3 }
376 2 }
377 1 if (status == MI_OK)
378 1 {
379 2 ResetInfo(MInfo);
380 2 SerBuffer[0] = PICC_TRANSFER;
381 2 SerBuffer[1] = trans_addr;
382 2 MInfo.nBytesToSend = 2;
383 2 status = M500PcdCmd(PCD_TRANSCEIVE,
384 2 SerBuffer,
385 2 &MInfo);
386 2 if (status != MI_NOTAGERR)
387 2 {
388 3 if (MInfo.nBitsReceived != 4)
389 3 {
390 4 status = MI_BITCOUNTERR;
391 4 }
392 3 else
393 3 {
394 4 SerBuffer[0] &= 0x0f;
395 4 switch(SerBuffer[0])
396 4 {
397 5 case 0x00:
398 5 status = MI_NOTAUTHERR;
399 5 break;
400 5 case 0x0a:
401 5 status = MI_OK;
402 5 break;
403 5 case 0x01:
404 5 status = MI_VALERR;
405 5 break;
406 5 default:
407 5 status = MI_CODEERR;
408 5 break;
409 5 }
410 4 }
411 3 }
412 2 }
413 1 return status;
414 1 }
415
416 ///////////////////////////////////////////////////////////////////////
417 // Set card in HALT-state
418 // 终止卡的操作
419 ///////////////////////////////////////////////////////////////////////
420 char M500PiccHalt(void)
421 {
422 1 char idata status = MI_CODEERR;
423 1
424 1 // ************* Cmd Sequence **********************************
425 1 ResetInfo(MInfo);
426 1 SerBuffer[0] = PICC_HALT ; // Halt command code
427 1 SerBuffer[1] = 0x00; // dummy address
C51 COMPILER V6.02 M500AUC 02/09/2006 13:25:02 PAGE 8
428 1 MInfo.nBytesToSend = 2;
429 1 status = M500PcdCmd(PCD_TRANSCEIVE,
430 1 SerBuffer,
431 1 &MInfo);
432 1 if (status)
433 1 {
434 2 // timeout error ==> no NAK received ==> OK
435 2 if (status == MI_NOTAGERR || status == MI_ACCESSTIMEOUT)
436 2 {
437 3 status = MI_OK;
438 3 }
439 2 }
440 1 //reset command register - no response from tag
441 1 WriteIO(RegCommand,PCD_IDLE);
442 1 return status;
443 1 }
444
445 ///////////////////////////////////////////////////////////////////////
446 // Reset the MF RC500
447 ///////////////////////////////////////////////////////////////////////
448 char M500PcdReset(void)
449 {
450 1 char idata status = MI_OK;
451 1 unsigned int idata timecnt=0;
452 1
453 1 RC500RST = 0;
454 1 delay_1ms(25);
455 1 RC500RST = 1;
456 1 delay_50us(200);
457 1 RC500RST = 0;
458 1 delay_50us(50);
459 1 timecnt=1000;
460 1 while ((ReadIO(RegCommand) & 0x3F) && timecnt--);
461 1 if(!timecnt)
462 1 {
463 2 status = MI_RESETERR;
464 2 }
465 1 if (status == MI_OK)
466 1 {
467 2 //WriteIO(RegPage,0x80);
468 2 if (ReadIO(RegCommand) != 0x00)
469 2 {
470 3 status = MI_INTERFACEERR;
471 3 }
472 2 }
473 1 return status;
474 1 }
475
476 ///////////////////////////////////////////////////////////////////////
477 // Configures the MF RC500 配置RC500内部寄存器函数
478 ///////////////////////////////////////////////////////////////////////
479 char M500PcdConfig(void)
480 {
481 1 char idata status;
482 1
483 1 if ((status = M500PcdReset()) == MI_OK)
484 1 {
485 2 WriteIO(RegClockQControl,0x00);
486 2 WriteIO(RegClockQControl,0x40);
487 2 delay_50us(2);
488 2 ClearBitMask(RegClockQControl,0x40);
489 2 WriteIO(RegBitPhase,0xAD);
C51 COMPILER V6.02 M500AUC 02/09/2006 13:25:02 PAGE 9
490 2 WriteIO(RegRxThreshold,0xFF);
491 2 WriteIO(RegRxControl2,0x01);
492 2 WriteIO(RegFIFOLevel,0x1A);
493 2 WriteIO(RegTimerControl,0x02);
494 2 WriteIO(RegIRqPinConfig,0x03);
495 2 M500PcdRfReset(1);
496 2 }
497 1 return status;
498 1 }
499
500 ///////////////////////////////////////////////////////////////
501 // Key loading into the MF RC500's EEPROM
502 // key_type: 选择是keyA 还是kyeB
503 // sector: 选择扇区号(0~15)
504 // uncoded_keys: 6 Bytes Key value
505 ///////////////////////////////////////////////////////////////
506 /*
507 char M500PcdLoadKeyE2(unsigned char key_type,
508 unsigned char sector,
509 unsigned char *uncoded_keys)
510 {
511 signed char status = MI_OK;
512 unsigned int e2addr = 0x80 + sector * 0x18;
513 unsigned char coded_keys[12];
514
515 if (key_type == PICC_AUTHENT1B)
516 {
517 e2addr += 12; // key B offset
518 }
519 if ((status = M500HostCodeKey(uncoded_keys,coded_keys)) == MI_OK)
520 {
521 status = PcdWriteE2(e2addr,12,coded_keys);
522 }
523 return status;
524 }
525 */
526 ///////////////////////////////////////////////////////////////////////
527 // Write the MF RC500's EEPROM
528 // startaddr: RC500 EEPROM 起始地址
529 // length: 所写Byte 长度
530 // _data: 要写入的数据的存放起始地址
531 ///////////////////////////////////////////////////////////////////////
532 /*
533 char PcdWriteE2(unsigned int startaddr,
534 unsigned char length,
535 unsigned char* _data)
536 {
537 char status = MI_OK;
538 ResetInfo(MInfo);
539 SerBuffer[0] = startaddr & 0xFF;
540 SerBuffer[1] = (startaddr >> 8) & 0xFF;
541 memcpy(SerBuffer + 2,_data,length);
542
543 MInfo.nBytesToSend = length + 2;
544
545 status = M500PcdCmd(PCD_WRITEE2,
546 SerBuffer,
547 &MInfo);
548 return status;
549 }
550 */
551
C51 COMPILER V6.02 M500AUC 02/09/2006 13:25:02 PAGE 10
552 ///////////////////////////////////////////////////////////////////////
553 // Select Command defined in ISO14443(MIFARE)
554 // Select the internal signal applied to pin MFOUT
555 // type: select MFOUT type( 0~7 )
556 ///////////////////////////////////////////////////////////////////////
557 char M500PcdMfOutSelect(unsigned char type)
558 {
559 1 WriteIO(RegMfOutSelect,type&0x7);
560 1 return MI_OK;
561 1 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -