物联传媒 旗下网站
登录 注册
RFID世界网 >  技术文章  >  其他  >  正文

关于非接触式IC智能(射频)卡及其读写设备内核技术的研究与应用开发(连载9)

作者:张敏
来源:RFID世界网
日期:2005-05-19 10:18:28
摘要:关于非接触式IC智能(射频)卡及其读写设备内核技术的研究与应用开发(连载9)

3. 对MCM200(SB201)“Select”(选卡片) 指令的汇编语言应用程序的设计
功能:调用该汇编语言子程序,将执行MCM “Select”(选卡片) 指令操作。如果卡片读写器的天线之有效工作距离内有多张重叠的Mifare 1 非接触式IC射频卡,则该指令在程序员成功完成“AntiCollision”操作之后,将帮助程序员正式选择其中指定的一张卡片进行操作(包括密码存取,密码认证,卡片上指定扇区的读写,等等。)“Select”(选卡片) 指令操作将读取卡片的SIZE字节。
程序说明:
1.)在以下的汇编语言程序中,用到了一些其他的子程序(和上述的“Request std和Request all”指令操作中的相同),分别为:
D500US: (与上述功能相同);
H_SEND_TO_BUF01:(与上述功能相同);
H_SEND_TO_BUF23:(与上述功能相同);
SEND_TO_BUF01:(与上述功能相同);
SEND_TO_BUF23:(与上述功能相同);
DISPLAY:(与上述功能相同);
H_DISPLAY:(与上述功能相同);
等等。
2.)在以下的汇编语言程序中,读者可能会碰到一些寄存器变量,或其他应用子程序,这些可能是用于主控程序或是调试而用。特加以说明。

程序清单如下:
;====================MCM SELECT OPERATION=====================
select:
    ;SETB PSW.3
    ;SETB PSW.4
    MOV A,#0CH
    MOV R0,#01H
    MOVX @R0,A        ;STACON() = 0CH
    MOV A,#0F0H
    MOV R0,#02H
    MOVX @R0,A        ;ENABLE() = F0H
    MOV A,#38H
    MOV R0,#03H
    MOVX @R0,A        ;BCNTS() = 38H =56 D
    MOV A,#08H
    MOV R0,#04H
    MOVX @R0,A        ;BCNTR() = 08H <--RECEIVE ONE BYTE:SIZEBYTE
    MOV A,#93H
    MOV R0,#00H
    MOVX @R0,A        ;DATA() = 93H -->SELECT INSTRACTION CODE
    MOV A,#70H
    MOV R0,#00H
    MOVX @R0,A        ;IMPORTANT: DATA()=70H--BITCOUNT=70Hbits
;-----------------------------------------------------------------------
    MOV R7,#04H       ;R7 IS A COUNTER,FOR WRITING 04H BYTES TO DATA
    MOV B,#00H
    MOV R0,#00H
    MOV R1,#40H       ;THE FIRST ADDRESS OF SNR. 40H---43H
SELECT_WRT_LOOP:
    MOV A,@R1
    MOVX @R0,A
    XRL B,A
    INC R1
    DJNZ R7, SELECT_WRT_LOOP
    MOV A,B
    MOVX @R0,A       ;SEND THE 5th CHK_SUM_VALUE
    MOV A,#0AH
    MOV R0,#06H
    MOVX @R0,A       ;TOC() = 0AH
SEL_RD_STACON_AGAIN:
    MOV R0,#01H
    MOVX A,@R0       ;READ STACON() ==> A
    MOV B,A
    JNB ACC.7, SEL_RD_STACON_AGAIN ;IF DV=1? IF NOT,REPEAT READ
    MOV B,A
;------------- NOW DV=1, DATA VALID ----------------------
    MOV A,#00H
    MOV R0,#06H
    MOVX @R0,A       ;TOC() = 00H
;------------- NOW JUDGE ANY DATA ERRORS --------------------
    MOV A,B
    JB ACC.6, SEL_TE_ERR  ;TE ERR
    JB ACC.5, SEL_PE_ERR  ;PE ERR
    JB ACC.3, SEL_BE_ERR  ;BE ERR
    JB ACC.4, SEL_CE_ERR  ;CE ERR
;------------- NOW NO ERRORS,READING CARD SIZE -----------------
    MOV R0,#00H
    MOVX A, @R0      ;READ SIZE: DATA() ==> A
    MOV 44H,A       ;STORE SIZE IN 44H
    ACALL SEND_TO_BUF01  ;SEND SIZE TO DISP_BUF_LOW
    SETB P2.6        ;OK LAMP NOW WORKING P2.3
    ACALL SPK_ON      ;if ok then spk on

    MOV B,#00H       ;SELECT OPERATION'S OK RETURN_VALUE=00H
    MOV A,B        ;READY FOR DISSPLAY IN DISP_BUF_HIGH(23)
    LJMP SEL_OK_EXIT    ;IF OK, EXIT SELECT OPERATION
;-------------------ERRORS PROCESS-------------------------------    
SEL_TE_ERR:
    MOV B,#01H       
    LJMP SEL_ERR_EXIT
SEL_PE_ERR:
    MOV B,#05H       
    LJMP SEL_ERR_EXIT
SEL_CE_ERR:
    MOV B,#02H       
    LJMP SEL_ERR_EXIT
SEL_BE_ERR:
    MOV R7,#0AH
    ACALL D500US
    MOV B,#0BH
    LJMP SEL_ERR_EXIT
;----------------------EXIT------------------------
SEL_ERR_EXIT:
    MOV A,B
SEL_OK_EXIT:
    ACALL SEND_TO_BUF23  ;SEND ERR_RETURN_VALE TO DISP_BUF_HIGH
    RET
;------------------------ End of MCM AntiCollision Operation -----------------


通过以上对MCM的几个指令的软件设计,读者应该能有较大的信心,将MCM其他的一些指令也能设计成功。以供主控程序随时调用。

(二). 对MCM200(SB201)组成的DEMO电路的主控应用程序设计和开发

1. 硬件电路请参照所附的DEMO电路图纸

2. 软件清单如下

程序清单如下:
;====================================================================
;         WRITTEN BY ROCKY, OCT'1999
;====================================================================
    ORG 0000H
start:
    LJMP MAIN
    NOP
    NOP
;--------------------------
    ;ORG 001BH
    ;LJMP 0500H
;--------------------------
    ORG 0080H
MAIN:
    MOV SP,#0E1H
    NOP
    CLR EA         ;CLOSE CPU INT
    CLR P2.5        ;RESET MCM (-RST=0)
    SETB P2.4        ;RESET MCM (-CS =1)
    NOP
    ACALL INIT_DISP_BUF   
    ACALL DISPLAY
    ACALL H_DISPLAY
    NOP
    CLR P2.6        ;CLOSE OK LAMP 
    setb p2.0        ;disenable KB function
    mov p1,#11110000b    ;init P1 port:P1.0~~P1.3-->out (line)
                ;       P1.4~~P1.7-->in (colum)
    SETB P2.5    ;RESET MCM (-RST=1)
    CLR P2.4    ;SELECT MCM (-CS=0)
    ACALL D500MS
    MOV A,#80H   ;SOFTWARE_RESET MCM
    MOV R0,#01H
    MOVX @R0,A
    ACALL D500MS
    ACALL SPK_ON      ;SPEAK ON
    ;MOV 21H,#01H       ;THE kb_TEST_CHAR
KB_LOOKING:
    LCALL KB_SCAN
    ACALL DISPLAY
    ACALL H_DISPLAY
    CLR P2.6        ;CLOSE OK LAMP P2.3
    AJMP KB_LOOKING
KB_ALL_EXIT:
    MOV R2,#00H       ;SET RQT_STD
    SETB P2.5    ;RESET: MCM ON (-RST=1) P1.4
    CLR P2.4    ;SELECT MCM ON (-CS=0) P1.5
;------------------------------------
REPEAT:
    SETB P2.5    ;RESET: MCM ON (-RST=1)P1.4
    CLR P2.4    ;SELECT MCM ON (-CS=0) P1.5
;==================================================
    ACALL REQUEST  ;MCM REQUEST OPERATION
;==================================================
    ACALL DISPLAY
    ACALL H_DISPLAY
    ACALL D500MS
    CLR P2.6    ;CLEAR OKLAMP P2.3
    ACALL INIT_DISP_BUF
    ACALL DISPLAY
    ACALL H_DISPLAY
;=========================================================
    ACALL ANTICOLLISION  ;MCM ANTICOLLISION OPERATION
;=========================================================
    ACALL DISPLAY
    ACALL H_DISPLAY
    ACALL D500MS
    CLR P2.6    ;CLEAR OKLAMP  P2.3
    ACALL INIT_DISP_BUF
    ACALL DISPLAY
    ACALL H_DISPLAY
;=========================================================
    ACALL SELECT  ;MCM SELECT OPERATION
;=========================================================
    ACALL DISPLAY
    ACALL H_DISPLAY
    ACALL D500MS
    CLR P2.6    ;CLEAR OKLAMP  P2.3
    ACALL INIT_DISP_BUF
    ACALL DISPLAY
    ACALL H_DISPLAY
         
;+++++++++++++++++++++ set up register/ram for load_key()++++++++++++++++++
    mov 7FH,#0ABH     
    MOV 7EH, #00H      ;(7EH) = 00H-->SELECT KEYSET0 (KS1=0;KS0=0)
    MOV 7DH,#02H      ;(7DH): 1)SELECT KEYA or KEYB
                ;    2)SELECT sector_ADDRESS :0-15
    MOV 7CH,#60H      ;(7CH) = 47H-->TKey(1) FIRST ADDRESS
;=========================================================
    ACALL LOAD_KEY ;MCM LOAD_KEY OPERATION
;=========================================================