關(guān)于非接觸式IC智能(射頻)卡及其讀寫設(shè)備內(nèi)核技術(shù)的研究與應(yīng)用開發(fā)(連載9)
文章出處:http://www.mjagi.com 作者:張敏 人氣: 發(fā)表時(shí)間:2011年11月01日
3. 對(duì)MCM200(SB201)“Select”(選卡片) 指令的匯編語言應(yīng)用程序的設(shè)計(jì)
功能:調(diào)用該匯編語言子程序,將執(zhí)行MCM “Select”(選卡片) 指令操作。如果卡片讀寫器的天線之有效工作距離內(nèi)有多張重疊的Mifare 1 非接觸式IC射頻卡,則該指令在程序員成功完成“AntiCollision”操作之后,將幫助程序員正式選擇其中指定的一張卡片進(jìn)行操作(包括密碼存取,密碼認(rèn)證,卡片上指定扇區(qū)的讀寫,等等。)“Select”(選卡片) 指令操作將讀取卡片的SIZE字節(jié)。
程序說明:
1.)在以下的匯編語言程序中,用到了一些其他的子程序(和上述的“Request std和Request all”指令操作中的相同),分別為:
D500US: (與上述功能相同);
H_SEND_TO_BUF01:(與上述功能相同);
H_SEND_TO_BUF23:(與上述功能相同);
SEND_TO_BUF01:(與上述功能相同);
SEND_TO_BUF23:(與上述功能相同);
DISPLAY:(與上述功能相同);
H_DISPLAY:(與上述功能相同);
等等。
2.)在以下的匯編語言程序中,讀者可能會(huì)碰到一些寄存器變量,或其他應(yīng)用子程序,這些可能是用于主控程序或是調(diào)試而用。特加以說明。
程序清單如下:
;====================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 -----------------
通過以上對(duì)MCM的幾個(gè)指令的軟件設(shè)計(jì),讀者應(yīng)該能有較大的信心,將MCM其他的一些指令也能設(shè)計(jì)成功。以供主控程序隨時(shí)調(diào)用。
(二). 對(duì)MCM200(SB201)組成的DEMO電路的主控應(yīng)用程序設(shè)計(jì)和開發(fā)
1. 硬件電路請(qǐng)參照所附的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
;=========================================================