t_DalayPara_3 DATA 2DH ;Used only by f_delay.
t_DalayPara_2 DATA 2EH ;Used only by f_delay.
t_DalayPara_1 DATA 2FH ;Used only by f_delay.
t_OutputCount DATA 25H ;Used only by f_OutputA
t_Data1HighByte DATA 24H ;Used only by f_Compare16Bit.
t_Data1LowByte DATA 23H ;Used only by f_Compare16Bit.
t_Data2HighByte DATA 22H ;Used only by f_Compare16Bit.
t_Data2LowByte DATA 21H ;Used only by f_Compare16Bit.
i_CompareFlag BIT 01H ;Used only by f_Compare16Bit. It is situated at
;20H byte in bit access area.
i_CurrentLevel BIT 00H ;Saves current level of OutPut pin of U2270B.
p_U2270B_CFE BIT p1.2
p_U2270B_OutPut BIT p1.3
p_75LBC184_REDE BIT p1.4 ;The pin RE and DE of 75LBC184 connect.
p_X5045P_SCK BIT p2.4
p_X5045P_SI BIT p2.3
p_X5045P_WP BIT p2.2
p_X5045P_CS BIT p2.0
p_X5045P_SO BIT p2.1
p_LED_GreenBig BIT p1.0 ;The green led and the big led connect.
p_LED_RED BIT p1.1
p_PNP_B BIT p1.7 ;Voice cue when it equal 0,vanishes when 1.
MOV TMOD,#10001B ;T0 和 T1 都为模式1,16位。
LCALL f_ReadCard ;读取IC卡数据
;----------------------------------------------------------------------------
;子程序功能 : 比较两个16位数据的大小。
;t_Data1HighByte: 第一个数据的高8位。
;t_Data1LowByte : 第一个数据的低8位。
;t_Data2HighByte: 第二个数据的高8位。
;t_Data2LowByte : 第二个数据的低8位。
;i_CompareFlag : 如果 i_CompareFlag = 0,那么第一个数据大于或等于第二个数据。
; 如果 i_CompareFlag = 1,那么第一个数据小于第二个数据。
f_Compare16Bit: MOV A,t_Data1HighByte
CLR C
SUBB A,t_Data2HighByte ;A - t_Data2HighByte - C
JC l_Data1_isSmall
;This time, t_Data1HighByte > = t_Data2HighByte.
MOV A,t_Data2HighByte
CLR C
SUBB A,t_Data1HighByte
JC l_Data1_isGig
;This time, t_Data1HighByte = t_Data2HighByte. then continues
;comparing low byte.
MOV A,t_Data1LowByte
CLR C
SUBB A,t_Data2LowByte
JC l_Data1_isSmall
;This time, t_Data1LowByte > = t_Data2LowByte.
AJMP l_Data1_isGig
l_Data1_isSmall:SETB i_CompareFlag
;This time, t_Data1HighByte < t_Data2HighByte, or
;t_Data1LowByte < t_Data2LowByte.
AJMP l_ExitCompare
l_Data1_isGig: CLR i_CompareFlag
l_ExitCompare: RET
;----------------------------------------------------------------------------
;功能:寻找跳变点。
f_DeteSaltation:JB i_CurrentLevel,l_CurrentIs1
l_CurrentIs0: JNB p_U2270B_OutPut,l_CurrentIs0
JNB p_U2270B_OutPut,l_CurrentIs0
JNB p_U2270B_OutPut,l_CurrentIs0
JNB p_U2270B_OutPut,l_CurrentIs0
JNB p_U2270B_OutPut,l_CurrentIs0
AJMP l_ExitDetect
l_CurrentIs1: JB p_U2270B_OutPut,l_CurrentIs1
JB p_U2270B_OutPut,l_CurrentIs1
JB p_U2270B_OutPut,l_CurrentIs1
JB p_U2270B_OutPut,l_CurrentIs1
JB p_U2270B_OutPut,l_CurrentIs1
l_ExitDetect: MOV C,p_U2270B_OutPut
MOV i_CurrentLevel,C ;保存当前电平
RET
;----------------------------------------------------------------------------
f_ReadCard: CLR C
MOV 00H,C
JB p_U2270B_OutPut,f_ReadCard
JB p_U2270B_OutPut,f_ReadCard
JB p_U2270B_OutPut,f_ReadCard
JB p_U2270B_OutPut,f_ReadCard
JB p_U2270B_OutPut,f_ReadCard
MOV C,p_U2270B_OutPut
MOV i_CurrentLevel,C ;保存当前电平
;A
LCALL f_DeteSaltation
;B
MOV TH0,#0
MOV TL0,#0
SETB TR0
LCALL f_DeteSaltation
CLR TR0
;Current is C. Status is low level.
MOV R6,TH0 ;Saves counter number.
MOV R5,TL0 ;Saves counter number.
MOV TH0,#0
MOV TL0,#0
SETB TR0
MOV 29H,R6
MOV 28H,R5
MOV t_Data1HighByte,R6
MOV t_Data1LowByte, R5
MOV t_Data2HighByte,#01H
MOV t_Data2LowByte, #04H
LCALL f_Compare16Bit ;Affects flag CY and register A.
JB i_CompareFlag,l_ErrorSignal
;At this time, BC > = 0104H, counter number 0104H = 282us.
LCALL f_DeteSaltation
CLR TR0
;Current is D. Status is high level.
MOV R6,TH0 ;Saves counter number.
MOV R5,TL0 ;Saves counter number.
MOV 27,R6
MOV 26,R5
MOV TH0,#0
MOV TL0,#0
MOV t_Data1HighByte,#00H
MOV t_Data1LowByte, #0D4H
MOV t_Data2HighByte,R6
MOV t_Data2LowByte, R5
LCALL f_Compare16Bit ;Affects flag CY and register A.
;#0D4H must > = R6R5
JB i_CompareFlag,l_ErrorSignal
;At this time, 0D4H > = R6R5, namely, 0D4H > = CD
;程序没有写完,暂时写这么多。
CLR p_PNP_B ;声音提示。 ●●●●●●●●●●●●●●●●●●
MOV t_DalayPara_3,#21
MOV t_DalayPara_2,#130
MOV t_DalayPara_1,#1
LCALL f_delay ;Delays 72 ms on 11.0592 MHz crystal.
SETB p_PNP_B ;声音提示。 ●●●●●●●●●●●●●●●●●●
;=====================================
;Output two datas.
MOV A,29H
LCALL f_OutputA ;Affects the CY flag and register A.
MOV A,28H
LCALL f_OutputA ;Affects the CY flag and register A.
MOV A,27H
LCALL f_OutputA ;Affects the CY flag and register A.
MOV A,26H
LCALL f_OutputA ;Affects the CY flag and register A.
;=====================================
AJMP l_ExitReadCard ;●●●●●●●●●●●●●●●●●●
l_ErrorSignal: CLR TR0
CLR C
MOV 00H,C
LJMP f_ReadCard
l_ExitReadCard: RET
;----------------------------------------------------------------------------
;purpose : When you test any program in this file, you can use the
; f_OutputA subprogram to output the value of register A by
; p_LED_GreenBig and p_LED_RED.
;p_LED_GreenBig : space signal.
;p_LED_RED : data signal.
;The communication protocol is as follows.
;p_LED_GreenBig : 4s 4s 4s 4s ......and so on.
;p_LED_RED : 4s 4s 4s 4s ......and so on.
;note : 01,The red led is light, denotes 1. contrariwise denotes 0.
; 02,This subprogram affects the CY bit and register A.
; 03,The X5045P chip must be invalid, namely, let WD1 and WD0
; of X5045P all equal 1.
;for example : MOV A,#37H
; LCALL f_OutputA ;Affects the CY flag and register A.
; MOV A,#38H
; LCALL f_OutputA ;Affects the CY flag and register A.
f_OutputA: MOV t_OutputCount,#8H
l_OutputLoop: CLR p_LED_GreenBig ; The big led is light.
MOV t_DalayPara_3,#221
MOV t_DalayPara_2,#4
MOV t_DalayPara_1,#29
LCALL f_delay ;Delays 4s on 11.0592 MHz crystal.
RLC A
JC l_BitIs_1
SETB p_LED_GreenBig ;The big led is extinguished.
SETB p_LED_RED ;The red led is extinguished.
AJMP l_OutputDetect
l_BitIs_1: SETB p_LED_GreenBig ;The big led is extinguished.
CLR p_LED_RED
l_OutputDetect:
MOV t_DalayPara_3,#221
MOV t_DalayPara_2,#4
MOV t_DalayPara_1,#29
LCALL f_delay ;Delays 4s on 11.0592 MHz crystal.
DJNZ t_OutputCount,l_OutputLoop
CLR p_LED_GreenBig ; The big led is light.
CLR p_PNP_B
MOV t_DalayPara_3,#21
MOV t_DalayPara_2,#130
MOV t_DalayPara_1,#1
LCALL f_delay ;Delays 72 ms on 11.0592 MHz crystal.
SETB p_PNP_B
RET
;----------------------------------------------------------------------------
;purpose : Delays for specified times.
;note : At first, let t_DalayPara_3 and t_DalayPara_2 all equal 1, then
; change t_DalayPara_1. When t_DalayPara_1 is right, change
; t_DalayPara_2, at last, change t_DalayPara_3.
f_delay: DJNZ t_DalayPara_3,f_delay ;decimal parameter range:[1,255]
DJNZ t_DalayPara_2,f_delay ;decimal parameter range:[1,255]
DJNZ t_DalayPara_1,f_delay ;decimal parameter range:[1,255]
RET
;----------------------------------------------------------------------------
;我的邮箱是:jhjbj@sohu.com