关于非接触式IC智能(射频)卡及其读写设备内核技术的研究与应用开发(连载10)
文章出处:http://www.singbon.com 作者:张敏 人气: 发表时间:2011年11月01日
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 Authenticate() ++++++++++++++++++
;mov 7fh,#04h
;7EH:for future use!
MOV 7EH, #80H ;(7EH) = 80H-->SELECT KEYSET0 (KS1=0;KS0=0)
MOV 7DH,#82H ;(7DH): 1)SELECT KEYA or KEYB (for auth_)
; 2)SELECT sector ADDRESS :0-15 (for auth_)
MOV 7CH,#60H ;Select: Auth_ instruction code
;=========================================================
ACALL AUTHENTICATION ;MCM AUTHENTICATE 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 Write() ++++++++++++++++++
; MOV 7EH, #00H ;(7EH):The first_address(MSB) storing the data which
;7EH:for future use!; you want to write the data to the MCM/CARD
; MOV 7DH,#50h ;(7DH): The first_address(LSB) storing the data which
; you want to write the data to the MCM/CARD
; MOV 7CH,#0BH ;Select: written address(block no.):0~~63
; LCALL WRITE_KEY_A
;=========================================================
; ACALL write ;MCM write 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 Read() ++++++++++++++++++
;MOV 7EH, #00H ;(7EH):The first address(HIGH_byte) which you want to
;7EH:for future use! ;read the data from the MCM/CARD into cpu_ram
MOV 7DH,#50h ;(7DH):The first address(LOW_byte) which you want to
; read the data from the MCM/CARD into cpu_ram
MOV 7CH,#08h ;Select:The address(block no.) you want to read:0-63
;==========================================================
LCALL READ ;MCM READ OPERATION
;=========================================================
ACALL DISPLAY
ACALL H_DISPLAY
ACALL D500ms
CLR P2.6 ;CLEAR OKLAMP P2.3
ACALL INIT_DISP_BUF
ACALL DISPLAY
ACALL H_DISPLAY
;==========================================================
LCALL HALT ;MCM HALT OPERATION
;=========================================================
ACALL DISPLAY
ACALL H_DISPLAY
ACALL D500MS
CLR P2.6 ;CLEAR OKLAMP P2.3
ACALL INIT_DISP_BUF
ACALL DISPLAY
ACALL H_DISPLAY
;==========================================================
LCALL DISP_RD_BLK ;DISPLAY JUST READ BLOCK VALUES
;=========================================================
LCALL CLEAR_DISP_RD_BLK_IN_CPU ;CLEAR :FILL WITH #11H
;=========================================================
CLR P2.6 ;CLEAR OKLAMP P2.3
ACALL INIT_DISP_BUF
ACALL DISPLAY
ACALL H_DISPLAY
;CLR P2.5 ;RESET MCM (-RST=0) P1.4
;SETB P2.4 ;RESET MCM (-CS=1) P1.5
MOV A,#80H ;SOFTWARE_RESET MCM
MOV R0,#01H
MOVX @R0,A
;LJMP REPEAT
RET
;----------------------------------------------------
D500US:
D500US_LOOP1:
MOV R6,#05H
D500US_LOOP2:
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
DJNZ R6,D500US_LOOP2
DJNZ R7,D500US_LOOP1
RET
;----------------------------------------------------
D500MS:
setb psw.3
setb psw.4
MOV R3,#19H
LOOP_1: MOV R4,#32H
LOOP_2: MOV R5,#64H
LOOP_3: DJNZ R5,LOOP_3
DJNZ R4,LOOP_2
DJNZ R3,LOOP_1
clr psw.3
clr psw.4
RET
;--------------------------
D2S:
setb psw.3
setb psw.4
MOV R6,#06H
LOOP: ACALL D500MS
DJNZ R6,LOOP
clr psw.3
clr psw.4
RET
;--------------------------
SPK_ON:
setb psw.3
setb psw.4
CLR P2.7
ACALL D500MS
SETB P2.7
clr psw.3
clr psw.4
RET
;--------------------------
DISPLAY:
SETB PSW.3
SETB PSW.4
CLR P2.2 ;SELECT MC14499'S -ENB
MOV R0,#36H ;DISPLAY BUF FIRST ADDRESS
MOV R1,#05H ;R1 AS A COUNTER
NEXT_CHAR: MOV A , @R0
SWAP A
ACALL DISP_ONE
INC R0
DJNZ R1,NEXT_CHAR
SETB P2.2 ;RELEASE MC14499'S -ENB
CLR PSW.3
CLR PSW.4
RET
;--------------------------
DISP_ONE:
MOV R2,#04H
NEXT_BIT:SETB P2.1 ;SELECT MC14499'S CLK=1
RLC A ;ONE BIT MOVE TO PSW.C
MOV P2.0, C
CLR P2.1 ;CLK=0
DJNZ R2, NEXT_BIT
RET
;--------------------------
H_DISPLAY:
SETB PSW.3
SETB PSW.4
CLR P2.3 ; -ENB
MOV R0,#31H
MOV R1,#05H
NOP
NOP
H_NEXT_CHAR: MOV A, @R0
SWAP A
ACALL H_DISP_ONE
INC R0
DJNZ R1,H_NEXT_CHAR
SETB P2.3 ; -ENB
CLR PSW.3
CLR PSW.4
RET
;----------------------------
H_DISP_ONE:
MOV R2,#04H
H_NEXT_BIT: SETB P2.1 ; CLK
RLC A
MOV P2.0, C ; DATA
CLR P2.1 ; CLK
DJNZ R2, H_NEXT_BIT
RET
;===========================
INIT_DISP_BUF:
SETB PSW.3
SETB PSW.4
MOV R0,#0AH
MOV R1,#31H
INIT_AGAIN: MOV @R1,#00H ;SET 31H--40H UNITS AS 00H
INC R1
DJNZ R0, INIT_AGAIN
CLR PSW.3
CLR PSW.4
RET
;--------------------------
SEND_TO_BUF01:
SETB PSW.3
SETB PSW.4
MOV B,A
MOV 3AH,A ;(3AH)
SWAP A
MOV 39H,A ;(39H)
MOV A,B
CLR PSW.3
CLR PSW.4
RET
;--------------------------
SEND_TO_BUF23:
SETB PSW.3
SETB PSW.4
MOV B,A
MOV 38H,A ;(38H)
SWAP A
MOV 37H,A ;(37H)
MOV A,B
CLR PSW.3
CLR PSW.4
RET
;--------------------------
SET_POINT0:
SETB PSW.4
SETB PSW.3
MOV R1,#36H ;(36H)
MOV @R1,#01H
MOV R1,#31H ;(31H)
MOV @R1,#02H
CLR PSW.3
CLR PSW.4
RET
;--------------------------
INDICATE:
CLR P2.6 ;INDICATE P2.6 AS 0-1-0
SETB P2.6
ACALL D500MS
CLR P2.6
RET
;-----------------------------
;====================MCM REQUEST OPERATION====================
request:
RET
;--------------------------------------------------------------------
;===============MCM ANTICOLLISION OPERTION=============
anticollision:
RET
;--------------------------------------------------------------------
;====================MCM SELECT OPERATION=====================
select:
RET
;--------------------------------------------------------------------
;========================= AUTHENTICATION ========================
authentication:
RET
;--------------------------------------------------------------------
;========================= LOAD KEY =========================
LOAD_KEY:
RET
;--------------------------------------------------------------------
;====================MCM WRITE OPERATION=====================
write:
RET
;--------------------------------------------------------------------
;====================MCM read OPERATION=====================
read:
RET
;--------------------------------------------------------------------
;========================= HALT OPERATION==============================
halt:
MOV A,#10H
MOV R0,#03H
MOVX @R0,A
MOV A,#04H
MOV R0,#04H
MOVX @R0,A
MOV A,#50H
MOV R0,#00H
MOVX @R0,A
MOV A,#00H
MOV R0,#00H
MOVX @R0,A
;------------------------- SET TOC()= 0AH --------------------------
MOV A,#0AH
MOV R0,#06H
MOVX @R0,A ;TOC() = 0AH
;--------------------------- READ STACON() -------------------------
HALT_RD_STACON_AGAIN:
MOV R0,#01H
MOVX A,@R0 ;READ STACON()
;-------------------JUDGE DV FLAG ----------------------------------
JNB ACC.7,HALT_RD_STACON_AGAIN
;------------------- CLOSE TOC() -----------------------------------
MOV B,A
MOV A,#00AH
MOV R0,#06H
MOVX @R0,A ;TOC() = 00H
MOV A,B
;-------------------------JUDG ANY ERRORS --------------------------
JB ACC.6, HALT_OK_EXIT ;TE=1 IS HALT OK FLAG
;-----------------------HAVE ANY ERRORS ----------------------------
MOV B,#06H
LJMP HALT_ERR_EXIT
;-------------------------- EXIT -----------------------------------
HALT_OK_EXIT:
MOV B,#66H ;“ok”disp_flag
SETB P2.6 ;OK LAMP NOW WORKING P2.3
ACALL SPK_ON ;if ok then spk on
HALT_ERR_EXIT:
MOV A,B
ACALL SEND_TO_BUF01 ;SEND RETURN_VALE TO DISP_BUF_LOW
RET
;========================= End of MCM HALT OPERATION =======================
;-------------------- DISPLY READ BLOCK VALUE(16 BYTES) ---------------
DISP_RD_BLK:
MOV R0,#50H
MOV R7,#04H
DISP_RD_BLK_LOOP:
MOV A,@R0
LCALL H_SEND_TO_BUF23 ;SEND RETURN_VALE TO DISP_BUF_LOW
INC R0
MOV A,@R0
LCALL H_SEND_TO_BUF01 ;SEND RETURN_VALE TO DISP_BUF_HIGH
INC R0
MOV A,@R0
LCALL SEND_TO_BUF23 ;SEND RETURN_VALE TO H_DISP_BUF_LOW
INC R0
MOV A,@R0
LCALL SEND_TO_BUF01 ;SEND RETURN_VALE TO H_DISP_BUF_HIGH
INC R0
LCALL DISPLAY
LCALL H_DISPLAY
LCALL D500MS
LCALL D500MS
DJNZ R7,DISP_RD_BLK_LOOP
RET
;-------------CLEAR DISPLY_READ_BLOCK VALUE(16 BYTES) IN CPU RAM ----------
CLEAR_DISP_RD_BLK_IN_CPU:
MOV R0,#50H
MOV R7,#10H
CLEAR_DISP_RD_BLK_LOOP:
MOV @R0,#11H ;SEND #11H TO DISP_RD_BLK_IN_CPU
INC R0
DJNZ R7,CLEAR_DISP_RD_BLK_LOOP
RET
;---------------------KB SCANNING ----------------------------
KB_SCAN:
MOV A,#11110000B
mov p1,a ;send line value:0000 <---P1.0~~P1.3
CLR P2.0 ;enable KB scan function
mov a,p1 ;if there is a key_pad pressing?
orl a,#00001111b ;if no keypressing, A should be = 1111 1111b
cpl a
jz KB_nothing ;if A = 00h, then no key is pressed
lcall kb_look_pad ;if A <> 00h,then one key is pressed
SETB P2.6
LCALL SPK_ON
KB_nothing:
setb p2.0
RET
;========================= KB LOOK ONE PAD ========================