ID-0_DATA0: EQU P1.7 ;P1.7 CONNECT TO DATA0
ID-0_DATA1: EQU P1.6 ;P1.6 CONNECT TO DATA1
ADDR_1: EQU 30H ;6 BYTES DATA SAVE IN INRAM 30-35H
EVEN_CHECK EQU 00H ;20H_BIT0 SAVE AS EVEN PARITY
ODD_CHECK EQU 01H ;20H_BIT1 SAVE AS ODD PARITY
EVEN_FLAG EQU 02H ;20H_BIT2
TIME_OUT_FLAG EQU 03H ;20H_BIT3
ORG 000BH
LJMP TIMER0_IN
ORG 30H
WIEGAND_START: TMOD,#01H ;
SETB EA
SETB EVEN_FLAG ;SET EVEN CHECK FLAG
CLR TIME_OUT_FLAG
MOV R2,#6 ;TOTAL 6 BYTES DATA
MOV R3,#4 ;4 BITS PER BYTE
MOV R0,#ADDR_1 ;START ADDRESS OF DATA
WIEGAND1: JNB ID-0_DATA0,WIEGAND2 ;DATA0 IS LOW THEN START TO OUTPUT DATA
JB ID-0_DATA1,WIEGAND1 ;DATA0 AND DATA1 IS HIGH THEN WAIT DATA
JB TIME_OUT_FLAG,ERR
MOV TH0,#0F8H ;2000US INTERRUPT
MOV TL0,#30H
CLR TIME_OUT_FLAG
SETB TR0 ;TIMER0 START
LCALL DELAY25US
MOV C,ID-0-DATA0
LCALL DELAY175US
JNB ID-0-DATA1,ERR
LJMP WIEGAND3
WIEGAND2: NOP
JB TIME_OUT_FLAG,ERR
MOV TH0,#0F8H ;2000US INTERRUPT
MOV TL0,#30H ;
CLR TIME_OUT_FLAG
SETB TR0 ;TIMER0 START
LCALL DELAY25US ;DELAY 25 μS
MOV C,ID-0_DATA0 ;MOVE DATA IN C REGISTER
LCALL DELAY175US
JNB ID-0-DATA,ERR
WIEGAND3: JNB EVEN_FLAG,WIEGAND_DATA ;EVEN IS 0 THEN OUTPUT IS DATA
MOV EVEN_CHECK,C ;OUTPUT IS EVEN CHECK BIT
CLR EVEN_FLAG ;CLR EVEN CHECK BIT
LJMP WIEGAND1 ;RECEIVE DATA
WIEGAND_DATA: RLC A ;
DJNZ R3,WIEGAND1 ;BYTE IS NOT OVER
ANL A,#00001111B ;BYTE OVER
MOV @R0,A ;SAVE DATA TO INRAM
INC R0 ;INCREASE INRAM ADDRESS
MOV R3,#4 ;4 BITS PER BYTE
DJNZ R2,WIEGAND1 ; READ DATA AGAIN
ODD: JNB ID-0_DATA0,ODD_BIT ;WAIT ODD CHECK BIT
JB ID-0_DATA1,ODD ;
ODD_BIT: NOP ;
LCALL DELAY25US ;DELAY 25 μS
MOV C,ID-0_DATA0 ;ODD CHECK BIT
MOV ODD_CHECK,C ;SAVE ODD CHECK BIT
NOP
LJMP OTHER_PROGRAM ;READ CARD OVER
DELAY25US: MOV R4,#11 ;DELAY 25μS
DELAY25US_A: DJNZ R4,DELAY25US_A
NOP
RET
DELAY175US: MOV R4,#86 ;DELAY 175 μS
DELAY175US_A: DJNZ R4,DELAY175US_A
NOP
RET
TIMER0_IN: SETB TIME_OUT_FLAG
CLR TR0
RETI
ERR: NOP ;ERR EXECEL
. ;
. ;
. ;
LJMP WIEGAND_START ;READ DATA AGAIN
5.2 ASCⅡ模式
在ASCⅡ模式下,ID-0/10/15引腳接法如下﹕
PIN1﹕ 地 PIN2﹕Reset Bar PIN5 ﹕接地
PIN3,4 ﹕Antenna
PIN6: CMOS
PIN7: TTL Data
PIN8: Beeper/Led
PIN9: +4.6V~+5.5V
在ASCⅡ模式下,ID-0/10/15與MCS51單片機的連接如下圖﹕
ID-0/10/15 PIN7 80C51 UART
80C51 I/O波形如下﹕
在c模式下,ID-0/10/15輸出數據為9600波特率,8位數據位,1位停止位,無奇偶校驗位。
此模式下輸出數據格式如下﹕
STX(02H) DATA CHSUM CR LF ETX(03H)
The checksum is the result of the ‘exclusive or ‘ of the 5 Binary Data bytes
eg: DATA=0000001164(Hex)
CHECKSUM=75H
STX(02 HEX)是數據啟示位,DATA是10位卡片號碼,CR (0D HEX)是計算器回車符,LF(0A HEX)是計算器換行符,ETX(03 HEX)是數據停止位。
此模式下與MCS51單片機接口的程序如下﹕
ID-0/10/15_DATA: EQU P1.7 ;P1.7 CONNECT TO DATA
ADDR_1: EQU 30H ;6 BYTES DATA SAVE IN INRAM 30-35H
MAIN: MOV SP,#60H ;
MAIN_1: MOV R2,#14 ;TOTAL 14 BYTES
MOV R0,#ADDR_1 ;
LOOP_BYTE_READ:MOV R3,#8 ;8 BITS PER BYTES
WAIT_DATA1: JB ID-0_DATA,WAIT_DATA1 ;DATA IS HIGH THEN WAIT
WAIT_DATA2: JNB ID-0_DATA,WAIT_DATA2 ;
LCALL DELAY_BIT_2 ;DELAY 45μS
LOOP_BIT_READ: LCALL DELAY_BIT_1 ;DELAY 95 μS
CLR EA ;INTERRUPT DISABLE
MOV C,ID-0_DATA ;MOVE DATA IN C RESIGTER
RRC A ;
DJNZ R3,LOOP_BIT_READ ;8 BITS PER BYTE
CPL A ;
MOV @R0,A ;SAVE DATA IN NRAM
INC R0 ;INCREADE INRAM ADDRESS
LCALL DELAY_BIT_1 ;DELAY 95μS
DJNZ R2,LOOP_BYTE_READ ;14 BYTE IS NOT OVER THEN AGAIN
SETB EA ;INTERRUPT ENABLE
LJMP OTHER_PROGRAM ;READ CARD END
DELAY_BIT_1: MOV R4,#46 ;DELAY 95μS
DELAY_BIT_1_A: DJNZ R4,DELAY_BIT_1_A
NOP
RET
DELAY_BIT_2: MOV R4,#21 ;DELAY 45μS
DELAY_BIT_2_A: DJNZ R4,DELAY_BIT_2_A
NOP
RET
評論
查看更多