Không up được file chứ không mình up luôn software kiểm soát xử lí data từ bo đọc về pc viết bằng VB6.0 luôn. Củ chuối qua ngay cả file hex cũng không úp được?
D0 EQU P3.2 ;NGAT NGOAI 0
D1 EQU P3.3 ;NGAT NGOAI 1
RX EQU P3.0
TX EQU P3.1
COUNT EQU 40H
DEM EQU 41H
DL_BY1 EQU 42H
DL_BY2 EQU 43H
STACK EQU 4AH
DATA1 EQU 20H
DATA2 EQU 21H
DATA3 EQU 22H
DATA4 EQU 23H
DATA5 EQU 24H
DATA6 EQU 25H
DATA7 EQU 26H
; ;30H->3D LA 14 BYTE LUU MA ACCII CUA CHUOI WIEGAND 52 BIT.CARD READER 5355A-900,REV N.1;
ACI1 EQU 30H
ACI2 EQU 31H
ACI3 EQU 32H
ACI4 EQU 33H
ACI5 EQU 34H
ACI6 EQU 35H
ACI7 EQU 36H
ACI8 EQU 37H
ACI9 EQU 38H
ACI10 EQU 39H
ACI11 EQU 3AH
ACI12 EQU 3BH
ACI13 EQU 3CH
ACI14 EQU 3DH
XLDT_BIT BIT 7FH
INT_SEC BIT 7EH
FIST_BIT BIT 7DH
ERROR_BIT BIT 7CH
LED_D BIT P3.4
LED_X BIT P3.5
ORG 00H
SJMP START
ORG 03H ;VECTOR NGAT NGOAI 0
CLR INT_SEC ;CO CHON NGAT
LJMP RECE_BIT ;NHAY DEN TRINH NGAT
ORG 13H ;------------------1
SETB INT_SEC ;CO CHON NGAT
LJMP RECE_BIT ;;NHAY DEN TRINH NGAT
ORG 23H ;NOI TIEP
ORG 30H ;
START:
MOV SP,#STACK ;CHUYEN NGAN XEP VI TRI KHAC
setb RX ;SET CAC CHAN SERIAL LEN CAO
setb TX
setb D0 ;SET CAC CHAN NGAT NGOAI LEN CAO
setb D1
MOV SCON,#50H ;
MOV TMOD,#20H ;
MOV TH1,#0FDH ;9600
MOV IE,#10000000B ;CHO PHEP NGAT NGOAI 0,1, NOI TIEP
SETB TCON.0 ;NGAT THEO SUON NGAT NGOAI 0
SETB TCON.2 ;NGAT THEO SUON 1
SETB TR1
CLR XLDT_BIT
CLR ERROR_BIT
MOV DEM,#0
CHUKIMOI:
SETB IE.0 ;BAT NGAT NGOAI 0;BAT DAU MOT CHU TRINH DOC MOI
SETB IE.2 ;VA NGAT NGOAI 1
SETB LED_X
SETB LED_D
MOV R1,#ACI1 ;XOA CAC BYTE CHUA ACCII
XOA_TIEP:
MOV @R1,#0
INC R1
CJNE R1,#ACI14+1,XOA_TIEP
MOV DATA1,#0 ;XOA DATA CU CON TON LAI
MOV DATA2,#0
MOV DATA3,#0
MOV DATA4,#0
MOV DATA5,#0
MOV DATA6,#0
MOV DATA7,#0
MOV R1,#0
MOV R2,#0
MOV R3,#0
MOV R4,#0
MOV R5,#0
MOV R6,#0
MOV R7,#0
MOV COUNT,#4 ;NAP 8 BIT CHO BYTE
MOV R0,#DATA7 ;20HBAT DAU CHU KY NHAN ID THE
DKM: JNB RI,GMTD
MOV A,SBUF
CLR RI
CALL MOTUDO
GMTD:
JNB XLDT_BIT,DKM
JNB ERROR_BIT,BT
CLR ERROR_BIT
LJMP CHUKIMOI
BT:
CLR IE.0 ;TAT NGAT NGOAI 0;DE XU LI DATA
CLR IE.2 ;VA NGAT NGOAI 1
CLR XLDT_BIT ;co xlb
;NEU DAT DELAY CHO NAY SE BI LOI NOI DUNG TG R7
MOV R1,DATA7
MOV R2,DATA6
MOV R3,DATA5
MOV R4,DATA4
MOV R5,DATA3
MOV R6,DATA2
MOV R7,DATA1
CALL SITECODE ;ko goi trinh con nay de lay code nguyen thuy(HEX) tu card
CALL LUOMCODE ;ko goi trinh con nay de lay code nguyen thuy (HEX)tu card
CALL Hex3DecConv ;ko goi trinh con nay de lay code nguyen thuy (HEX)tu card
CALL CONVER_BCDACCII
MOV DEM,#14 ;GUI 14 BYTE
MOV R0,#ACI14 ;3DH;DIA CHI BAT DAU TINH THEO CHIEU GIAM DAN 14 BYTE LUU ACCII
GU_TIEP:
MOV SBUF,@R0
JNB TI,$
CLR TI
DEC R0
DJNZ DEM,GU_TIEP ;KHI R0 = ACI1 THI THOAT LOOP
; CALL WAITT
CALL WAITT ;doi de khoi bi loi ngat
CALL WAITT
CALL PHANHOI
LJMP CHUKIMOI
;==========================
;========
PHANHOI:
MOV DL_BY1,#255
CNR: JB RI,N
DJNZ DL_BY1,CNR
CALL WAITT
CALL WAITT
CALL WAITT
CLR LED_D
CLR LED_X
SJMP VEAGAIN ;LOI NHAY VE LAI
N: MOV A,SBUF
CLR RI
CJNE A,#52H,CHECKT1t
CLR LED_X
CALL WAITT ;TRE CHO LED SANG
CALL WAITT
CALL WAITT
CALL WAITT
CALL WAITT
SJMP VEAGAIN
CHECKT1t:
CJNE A,#0BH,CHECKT111
CLR LED_D
CALL WAITT ;TRE CHO LED SANG
CALL WAITT
CALL WAITT
CALL WAITT
CALL WAITT
SJMP VEAGAIN
CHECKT111:
; CLR LED_X
; CLR LED_D
; CALL WAITT ;TRE CHO LED SANG
CALL WAITT
CALL WAITT
CALL WAITT
VEAGAIN:
RET
;=====================
MOTUDO:
CJNE A,#0CH,CHE122
CLR LED_X
SJMP VTD
;mo cua tu do tai day
CHE122:
CJNE A,#0DH,VTD
CLR LED_D
SJMP VTD
VTD: RET
;======================DATA1
RECE_BIT:
CJNE R0,#DATA1,STOGE11
MOV A,DATA1
SJMP LUU_BIT1
STOGE11:
CJNE R0,#DATA2,STOGE12
MOV A,DATA2
SJMP LUU_BIT1
STOGE12:
CJNE R0,#DATA3,STOGE13
MOV A,DATA3
SJMP LUU_BIT1
STOGE13:
CJNE R0,#DATA4,STOGE14
MOV A,DATA4
SJMP LUU_BIT1
STOGE14:
CJNE R0,#DATA5,STOGE15
MOV A,DATA5
SJMP LUU_BIT1
STOGE15:
CJNE R0,#DATA6,STOGE16
MOV A,DATA6
SJMP LUU_BIT1
STOGE16:
CJNE R0,#DATA7,STOGE17
MOV A,DATA7
SJMP LUU_BIT1
STOGE17:
CLR LED_D
;SJMP $
SETB ERROR_BIT
RETI
LUU_BIT1:
JNB INT_SEC,LUU_BIT0
SETB C
SJMP ROTO
LUU_BIT0:
CLR C
ROTO:
RLC A
CJNE R0,#DATA1,STO11
MOV DATA1,A
SJMP LUU_BYTE1
STO11: CJNE R0,#DATA2,STO12
MOV DATA2,A
SJMP LUU_BYTE1
STO12: CJNE R0,#DATA3,STO13
MOV DATA3,A
SJMP LUU_BYTE1
STO13: CJNE R0,#DATA4,STO14
MOV DATA4,A
SJMP LUU_BYTE1
STO14: CJNE R0,#DATA5,STO15
MOV DATA5,A
SJMP LUU_BYTE1
STO15: CJNE R0,#DATA6,STO16
MOV DATA6,A
SJMP LUU_BYTE1
STO16: CJNE R0,#DATA7,STO17
MOV DATA7,A
SJMP LUU_BYTE1
STO17:
CLR LED_X
SETB ERROR_BIT
;SJMP $
RETI
LUU_BYTE1:
DJNZ COUNT,HET_1BYTE ;TT1
CJNE R0,#DATA1,KT_STRING
SETB XLDT_BIT
CALL RORR7DATA
RETI ;THOAT KHOI NGAT VE XU LI CHUOI DATA STRING DA NHAN
KT_STRING:
MOV COUNT,#8 ;NAP LAI 8 BIT CHO BYTE MOI
DEC R0 ;CHUYEN LEN BYTE CAO HON
HET_1BYTE:
RETI
;--------------------
WAITT:
MOV DL_BY1,#250
CCC: MOV DL_BY2,#250
DJNZ DL_BY2,$
DJNZ DL_BY1,CCC
RET
;--------------------------------------------------------------------------
;---------------------------------
CONVER_BCDACCII:
MOV A,R1
SWAP A
CALL BCD_ACCII
MOV ACI14,A
MOV A,R1
CALL BCD_ACCII
MOV ACI13,A
MOV A,R2
SWAP A
CALL BCD_ACCII
MOV ACI12,A
MOV A,R2
CALL BCD_ACCII
MOV ACI11,A
MOV A,R3
SWAP A
CALL BCD_ACCII
MOV ACI10,A
MOV A,R3
CALL BCD_ACCII
MOV ACI9,A
MOV A,R4
SWAP A
CALL BCD_ACCII
MOV ACI8,A
MOV A,R4
CALL BCD_ACCII
MOV ACI7,A
MOV A,R5
SWAP A
CALL BCD_ACCII
MOV ACI6,A
MOV A,R5
CALL BCD_ACCII
MOV ACI5,A
MOV A,R6
SWAP A
CALL BCD_ACCII
MOV ACI4,A
MOV A,R6
CALL BCD_ACCII
MOV ACI3,A
MOV A,R7
SWAP A
CALL BCD_ACCII
MOV ACI2,A
MOV A,R7
CALL BCD_ACCII
MOV ACI1,A
RET
;-----------------------
BCD_ACCII:
ANL A,#0FH
CJNE A,#0,TT1
ADD A,#30H ;CHUYEN RA ACCII NEU 0<A<9
RET
TT1:
CJNE A,#1,TT2
ADD A,#30H ;CHUYEN RA ACCII NEU 0<A<9
RET
TT2:
CJNE A,#2,TT3
ADD A,#30H ;CHUYEN RA ACCII NEU 0<A<9
RET
TT3:
CJNE A,#3,TT4
ADD A,#30H ;CHUYEN RA ACCII NEU 0<A<9
RET
TT4:
CJNE A,#4,TT5
ADD A,#30H ;CHUYEN RA ACCII NEU 0<A<9
RET
TT5:
CJNE A,#5,TT6
ADD A,#30H ;CHUYEN RA ACCII NEU 0<A<9
RET
TT6:
CJNE A,#6,TT7
ADD A,#30H ;CHUYEN RA ACCII NEU 0<A<9
RET
TT7:
CJNE A,#7,TT8
ADD A,#30H ;CHUYEN RA ACCII NEU 0<A<9
RET
TT8:
CJNE A,#8,TT9
ADD A,#30H ;CHUYEN RA ACCII NEU 0<A<9
RET
TT9:
CJNE A,#9,TT10
ADD A,#30H ;CHUYEN RA ACCII NEU 0<A<9
RET
TT10:
CJNE A,#0AH,TT11
ADD A,#37H
TT11:
CJNE A,#0BH,TT12
ADD A,#37H
RET
TT12:
CJNE A,#0CH,TT13
ADD A,#37H
RET
TT13:
CJNE A,#0DH,TT14
ADD A,#37H
RET
TT14:
CJNE A,#0EH,TT15
ADD A,#37H
RET
TT15:
CJNE A,#0FH,TT16
ADD A,#37H
TT16: RET
;=====
;---------------------------------
RORR7DATA:
MOV DL_BY1,#2 ;QUAY 2 LAN
CON_RT:
MOV A,DATA1
MOV C,ACC.0 ;COPY BIT THAP NHAT VAO C
MOV A,DATA7
RRC A
MOV DATA7,A
MOV A,DATA6
RRC A
MOV DATA6,A
MOV A,DATA5
RRC A
MOV DATA5,A
MOV A,DATA4
RRC A
MOV DATA4,A
MOV A,DATA3
RRC A
MOV DATA3,A
MOV A,DATA2
RRC A
MOV DATA2,A
MOV A,DATA1
RRC A
MOV DATA1,A
DJNZ DL_BY1,CON_RT
RET
;-------------------------------
LUOMCODE:
MOV R5,DATA5
MOV R6,DATA4
MOV R7,DATA3
MOV DL_BY1,#4 ;QUAY 4 LAN
CON_LC:
CLR C
MOV A,R5
RRC A
MOV R5,A
MOV A,R6
RRC A
MOV R6,A
MOV A,R7
RRC A
MOV R7,A
DJNZ DL_BY1,CON_LC
RET
;====================
SITECODE:
MOV R7,DATA1
MOV R6,DATA2
MOV R5,#0
CALL Hex3DecConv
MOV A,R7
MOV R3,A
MOV A,R6
MOV R2,A
MOV A,R5
MOV R1,A
RET
;--------------------------------------------------------------------------
;3 bytes of hex number to decimal convertion routine
;number in r5,r6,r7 (r5-msb,..,r7-lsb), result in r4,r5,r6,r7
;the routine counts, how many times you can subtract the 1000000 from numer, then 100000,10000,1000,100,10,1
;each counter equals position of decimal number f.e.:
; 1E74 hex - you can subtract 1000 seven (7) times, 100 seven (7) times, 10 nine (9) times and the rest
;is six (6), so your result of conversion is 7796 (equals 1E74)
;----------------------------------------------------------------
Hex3DecConv: CLR C
MOV R4,#0 ;milion counter clear
Hex3DecLoop1: MOV A,R7 ;how many time we can subtract 10000000 without carry (989680H)
SUBB A,#80H
MOV R7,A
MOV A,R6
SUBB A,#96H
MOV R6,A
MOV A,R5
SUBB A,#98H
MOV R5,A
JC Hex3DecSkip1
INC R4
JMP Hex3DecLoop1
Hex3DecSkip1: MOV A,R4
PUSH ACC ;push counter onto stack
MOV A,R7
ADD A,#80H
MOV R7,A
MOV A,R6
ADDC A,#96H
MOV R6,A
MOV A,R5
ADDC A,#98H
MOV R5,A
CLR C
MOV R4,#0
Hex3DecLoop2: MOV A,R7 ;how many times we can subtract 1000000 (F4240H) without carry
SUBB A,#40H
MOV R7,A
MOV A,R6
SUBB A,#42H
MOV R6,A
MOV A,R5
SUBB A,#0FH
MOV R5,A
JC Hex3DecSkip2
INC R4
JMP Hex3DecLoop2
Hex3DecSkip2: MOV A,R4
PUSH ACC ;push counter onto stack
MOV A,R7
ADD A,#40H
MOV R7,A
MOV A,R6
ADDC A,#42H
MOV R6,A
MOV A,R5
ADDC A,#0FH
MOV R5,A
CLR C
MOV R4,#0
Hex3DecLoop3: MOV A,R7 ;100000 (186A0H)?
SUBB A,#0A0H
MOV R7,A
MOV A,R6
SUBB A,#86H
MOV R6,A
MOV A,R5
SUBB A,#01H
MOV R5,A
JC Hex3DecSkip3
INC R4
JMP Hex3DecLoop3
Hex3DecSkip3: MOV A,R4
PUSH ACC ;onto stack
MOV A,R7
ADD A,#0A0H
MOV R7,A
MOV A,R6
ADDC A,#86H
MOV R6,A
MOV A,R5
ADDC A,#01H
MOV R5,A
Hex2DecConv: MOV R4,#0
CLR C
Hex2DecLoop1: MOV A,R7 ;10000 (2710h)?
SUBB A,#010H
MOV R7,A
MOV A,R6
SUBB A,#27H
MOV R6,A
MOV A,R5
SUBB A,#0
MOV R5,A
JC Hex2DecSkip1
INC R4
JMP Hex2DecLoop1
Hex2DecSkip1: MOV A,R4 ;onto stack
PUSH ACC
MOV A,R7
ADD A,#010H
MOV R7,A
MOV A,R6
ADDC A,#27H
MOV R6,A
CLR C
MOV R4,#0
Hex2DecLoop2: MOV A,R7 ;1000 (3E8h)?
SUBB A,#0E8H
MOV R7,A
MOV A,R6
SUBB A,#03H
MOV R6,A
JC Hex2DecSkip2
INC R4
JMP Hex2DecLoop2
Hex2DecSkip2: MOV A,R4 ;onto satck
PUSH ACC
MOV A,R7
ADD A,#0E8H
MOV R7,A
MOV A,R6
ADDC A,#03H
MOV R6,A
CLR C
MOV R4,#0
Hex2DecLoop3: MOV A,R7 ;100 (64h)?
SUBB A,#064H
MOV R7,A
MOV A,R6
SUBB A,#0H
MOV R6,A
JC Hex2DecSkip3
INC R4
JMP Hex2DecLoop3
Hex2DecSkip3: MOV A,R4 ;onto stack
PUSH ACC
MOV A,R7
ADD A,#064H
MOV R7,A
MOV A,R6
ADDC A,#0H
MOV R6,A
CLR C
MOV R4,#0
Hex2DecLoop4: MOV A,R7 ;10 (0Ah)?
SUBB A,#0AH
MOV R7,A
JC Hex2DecSkip4
INC R4
JMP Hex2DecLoop4
Hex2DecSkip4: MOV A,R4 ;onto stack
PUSH ACC
ADD A,#0AH ;1
MOV A,R7 ;tens & ones in w R7
ADD A,#0AH
MOV R7,A
POP ACC
SWAP A
ADD A,R7
MOV R7,A
POP ACC ;thousands & hundreds in R6
MOV R6,A
POP ACC
SWAP A
ADD A,R6
MOV R6,A
POP ACC ;tens thousands & hundreds thousands in R5
MOV R5,A
POP ACC
SWAP A
ADD A,R5
MOV R5,A
POP ACC ;milins & tens milions in R4
MOV R4,A
POP ACC
SWAP A
ADD A,R4
MOV R4,A
RET
END
D0 EQU P3.2 ;NGAT NGOAI 0
D1 EQU P3.3 ;NGAT NGOAI 1
RX EQU P3.0
TX EQU P3.1
COUNT EQU 40H
DEM EQU 41H
DL_BY1 EQU 42H
DL_BY2 EQU 43H
STACK EQU 4AH
DATA1 EQU 20H
DATA2 EQU 21H
DATA3 EQU 22H
DATA4 EQU 23H
DATA5 EQU 24H
DATA6 EQU 25H
DATA7 EQU 26H
; ;30H->3D LA 14 BYTE LUU MA ACCII CUA CHUOI WIEGAND 52 BIT.CARD READER 5355A-900,REV N.1;
ACI1 EQU 30H
ACI2 EQU 31H
ACI3 EQU 32H
ACI4 EQU 33H
ACI5 EQU 34H
ACI6 EQU 35H
ACI7 EQU 36H
ACI8 EQU 37H
ACI9 EQU 38H
ACI10 EQU 39H
ACI11 EQU 3AH
ACI12 EQU 3BH
ACI13 EQU 3CH
ACI14 EQU 3DH
XLDT_BIT BIT 7FH
INT_SEC BIT 7EH
FIST_BIT BIT 7DH
ERROR_BIT BIT 7CH
LED_D BIT P3.4
LED_X BIT P3.5
ORG 00H
SJMP START
ORG 03H ;VECTOR NGAT NGOAI 0
CLR INT_SEC ;CO CHON NGAT
LJMP RECE_BIT ;NHAY DEN TRINH NGAT
ORG 13H ;------------------1
SETB INT_SEC ;CO CHON NGAT
LJMP RECE_BIT ;;NHAY DEN TRINH NGAT
ORG 23H ;NOI TIEP
ORG 30H ;
START:
MOV SP,#STACK ;CHUYEN NGAN XEP VI TRI KHAC
setb RX ;SET CAC CHAN SERIAL LEN CAO
setb TX
setb D0 ;SET CAC CHAN NGAT NGOAI LEN CAO
setb D1
MOV SCON,#50H ;
MOV TMOD,#20H ;
MOV TH1,#0FDH ;9600
MOV IE,#10000000B ;CHO PHEP NGAT NGOAI 0,1, NOI TIEP
SETB TCON.0 ;NGAT THEO SUON NGAT NGOAI 0
SETB TCON.2 ;NGAT THEO SUON 1
SETB TR1
CLR XLDT_BIT
CLR ERROR_BIT
MOV DEM,#0
CHUKIMOI:
SETB IE.0 ;BAT NGAT NGOAI 0;BAT DAU MOT CHU TRINH DOC MOI
SETB IE.2 ;VA NGAT NGOAI 1
SETB LED_X
SETB LED_D
MOV R1,#ACI1 ;XOA CAC BYTE CHUA ACCII
XOA_TIEP:
MOV @R1,#0
INC R1
CJNE R1,#ACI14+1,XOA_TIEP
MOV DATA1,#0 ;XOA DATA CU CON TON LAI
MOV DATA2,#0
MOV DATA3,#0
MOV DATA4,#0
MOV DATA5,#0
MOV DATA6,#0
MOV DATA7,#0
MOV R1,#0
MOV R2,#0
MOV R3,#0
MOV R4,#0
MOV R5,#0
MOV R6,#0
MOV R7,#0
MOV COUNT,#4 ;NAP 8 BIT CHO BYTE
MOV R0,#DATA7 ;20HBAT DAU CHU KY NHAN ID THE
DKM: JNB RI,GMTD
MOV A,SBUF
CLR RI
CALL MOTUDO
GMTD:
JNB XLDT_BIT,DKM
JNB ERROR_BIT,BT
CLR ERROR_BIT
LJMP CHUKIMOI
BT:
CLR IE.0 ;TAT NGAT NGOAI 0;DE XU LI DATA
CLR IE.2 ;VA NGAT NGOAI 1
CLR XLDT_BIT ;co xlb
;NEU DAT DELAY CHO NAY SE BI LOI NOI DUNG TG R7
MOV R1,DATA7
MOV R2,DATA6
MOV R3,DATA5
MOV R4,DATA4
MOV R5,DATA3
MOV R6,DATA2
MOV R7,DATA1
CALL SITECODE ;ko goi trinh con nay de lay code nguyen thuy(HEX) tu card
CALL LUOMCODE ;ko goi trinh con nay de lay code nguyen thuy (HEX)tu card
CALL Hex3DecConv ;ko goi trinh con nay de lay code nguyen thuy (HEX)tu card
CALL CONVER_BCDACCII
MOV DEM,#14 ;GUI 14 BYTE
MOV R0,#ACI14 ;3DH;DIA CHI BAT DAU TINH THEO CHIEU GIAM DAN 14 BYTE LUU ACCII
GU_TIEP:
MOV SBUF,@R0
JNB TI,$
CLR TI
DEC R0
DJNZ DEM,GU_TIEP ;KHI R0 = ACI1 THI THOAT LOOP
; CALL WAITT
CALL WAITT ;doi de khoi bi loi ngat
CALL WAITT
CALL PHANHOI
LJMP CHUKIMOI
;==========================
;========
PHANHOI:
MOV DL_BY1,#255
CNR: JB RI,N
DJNZ DL_BY1,CNR
CALL WAITT
CALL WAITT
CALL WAITT
CLR LED_D
CLR LED_X
SJMP VEAGAIN ;LOI NHAY VE LAI
N: MOV A,SBUF
CLR RI
CJNE A,#52H,CHECKT1t
CLR LED_X
CALL WAITT ;TRE CHO LED SANG
CALL WAITT
CALL WAITT
CALL WAITT
CALL WAITT
SJMP VEAGAIN
CHECKT1t:
CJNE A,#0BH,CHECKT111
CLR LED_D
CALL WAITT ;TRE CHO LED SANG
CALL WAITT
CALL WAITT
CALL WAITT
CALL WAITT
SJMP VEAGAIN
CHECKT111:
; CLR LED_X
; CLR LED_D
; CALL WAITT ;TRE CHO LED SANG
CALL WAITT
CALL WAITT
CALL WAITT
VEAGAIN:
RET
;=====================
MOTUDO:
CJNE A,#0CH,CHE122
CLR LED_X
SJMP VTD
;mo cua tu do tai day
CHE122:
CJNE A,#0DH,VTD
CLR LED_D
SJMP VTD
VTD: RET
;======================DATA1
RECE_BIT:
CJNE R0,#DATA1,STOGE11
MOV A,DATA1
SJMP LUU_BIT1
STOGE11:
CJNE R0,#DATA2,STOGE12
MOV A,DATA2
SJMP LUU_BIT1
STOGE12:
CJNE R0,#DATA3,STOGE13
MOV A,DATA3
SJMP LUU_BIT1
STOGE13:
CJNE R0,#DATA4,STOGE14
MOV A,DATA4
SJMP LUU_BIT1
STOGE14:
CJNE R0,#DATA5,STOGE15
MOV A,DATA5
SJMP LUU_BIT1
STOGE15:
CJNE R0,#DATA6,STOGE16
MOV A,DATA6
SJMP LUU_BIT1
STOGE16:
CJNE R0,#DATA7,STOGE17
MOV A,DATA7
SJMP LUU_BIT1
STOGE17:
CLR LED_D
;SJMP $
SETB ERROR_BIT
RETI
LUU_BIT1:
JNB INT_SEC,LUU_BIT0
SETB C
SJMP ROTO
LUU_BIT0:
CLR C
ROTO:
RLC A
CJNE R0,#DATA1,STO11
MOV DATA1,A
SJMP LUU_BYTE1
STO11: CJNE R0,#DATA2,STO12
MOV DATA2,A
SJMP LUU_BYTE1
STO12: CJNE R0,#DATA3,STO13
MOV DATA3,A
SJMP LUU_BYTE1
STO13: CJNE R0,#DATA4,STO14
MOV DATA4,A
SJMP LUU_BYTE1
STO14: CJNE R0,#DATA5,STO15
MOV DATA5,A
SJMP LUU_BYTE1
STO15: CJNE R0,#DATA6,STO16
MOV DATA6,A
SJMP LUU_BYTE1
STO16: CJNE R0,#DATA7,STO17
MOV DATA7,A
SJMP LUU_BYTE1
STO17:
CLR LED_X
SETB ERROR_BIT
;SJMP $
RETI
LUU_BYTE1:
DJNZ COUNT,HET_1BYTE ;TT1
CJNE R0,#DATA1,KT_STRING
SETB XLDT_BIT
CALL RORR7DATA
RETI ;THOAT KHOI NGAT VE XU LI CHUOI DATA STRING DA NHAN
KT_STRING:
MOV COUNT,#8 ;NAP LAI 8 BIT CHO BYTE MOI
DEC R0 ;CHUYEN LEN BYTE CAO HON
HET_1BYTE:
RETI
;--------------------
WAITT:
MOV DL_BY1,#250
CCC: MOV DL_BY2,#250
DJNZ DL_BY2,$
DJNZ DL_BY1,CCC
RET
;--------------------------------------------------------------------------
;---------------------------------
CONVER_BCDACCII:
MOV A,R1
SWAP A
CALL BCD_ACCII
MOV ACI14,A
MOV A,R1
CALL BCD_ACCII
MOV ACI13,A
MOV A,R2
SWAP A
CALL BCD_ACCII
MOV ACI12,A
MOV A,R2
CALL BCD_ACCII
MOV ACI11,A
MOV A,R3
SWAP A
CALL BCD_ACCII
MOV ACI10,A
MOV A,R3
CALL BCD_ACCII
MOV ACI9,A
MOV A,R4
SWAP A
CALL BCD_ACCII
MOV ACI8,A
MOV A,R4
CALL BCD_ACCII
MOV ACI7,A
MOV A,R5
SWAP A
CALL BCD_ACCII
MOV ACI6,A
MOV A,R5
CALL BCD_ACCII
MOV ACI5,A
MOV A,R6
SWAP A
CALL BCD_ACCII
MOV ACI4,A
MOV A,R6
CALL BCD_ACCII
MOV ACI3,A
MOV A,R7
SWAP A
CALL BCD_ACCII
MOV ACI2,A
MOV A,R7
CALL BCD_ACCII
MOV ACI1,A
RET
;-----------------------
BCD_ACCII:
ANL A,#0FH
CJNE A,#0,TT1
ADD A,#30H ;CHUYEN RA ACCII NEU 0<A<9
RET
TT1:
CJNE A,#1,TT2
ADD A,#30H ;CHUYEN RA ACCII NEU 0<A<9
RET
TT2:
CJNE A,#2,TT3
ADD A,#30H ;CHUYEN RA ACCII NEU 0<A<9
RET
TT3:
CJNE A,#3,TT4
ADD A,#30H ;CHUYEN RA ACCII NEU 0<A<9
RET
TT4:
CJNE A,#4,TT5
ADD A,#30H ;CHUYEN RA ACCII NEU 0<A<9
RET
TT5:
CJNE A,#5,TT6
ADD A,#30H ;CHUYEN RA ACCII NEU 0<A<9
RET
TT6:
CJNE A,#6,TT7
ADD A,#30H ;CHUYEN RA ACCII NEU 0<A<9
RET
TT7:
CJNE A,#7,TT8
ADD A,#30H ;CHUYEN RA ACCII NEU 0<A<9
RET
TT8:
CJNE A,#8,TT9
ADD A,#30H ;CHUYEN RA ACCII NEU 0<A<9
RET
TT9:
CJNE A,#9,TT10
ADD A,#30H ;CHUYEN RA ACCII NEU 0<A<9
RET
TT10:
CJNE A,#0AH,TT11
ADD A,#37H
TT11:
CJNE A,#0BH,TT12
ADD A,#37H
RET
TT12:
CJNE A,#0CH,TT13
ADD A,#37H
RET
TT13:
CJNE A,#0DH,TT14
ADD A,#37H
RET
TT14:
CJNE A,#0EH,TT15
ADD A,#37H
RET
TT15:
CJNE A,#0FH,TT16
ADD A,#37H
TT16: RET
;=====
;---------------------------------
RORR7DATA:
MOV DL_BY1,#2 ;QUAY 2 LAN
CON_RT:
MOV A,DATA1
MOV C,ACC.0 ;COPY BIT THAP NHAT VAO C
MOV A,DATA7
RRC A
MOV DATA7,A
MOV A,DATA6
RRC A
MOV DATA6,A
MOV A,DATA5
RRC A
MOV DATA5,A
MOV A,DATA4
RRC A
MOV DATA4,A
MOV A,DATA3
RRC A
MOV DATA3,A
MOV A,DATA2
RRC A
MOV DATA2,A
MOV A,DATA1
RRC A
MOV DATA1,A
DJNZ DL_BY1,CON_RT
RET
;-------------------------------
LUOMCODE:
MOV R5,DATA5
MOV R6,DATA4
MOV R7,DATA3
MOV DL_BY1,#4 ;QUAY 4 LAN
CON_LC:
CLR C
MOV A,R5
RRC A
MOV R5,A
MOV A,R6
RRC A
MOV R6,A
MOV A,R7
RRC A
MOV R7,A
DJNZ DL_BY1,CON_LC
RET
;====================
SITECODE:
MOV R7,DATA1
MOV R6,DATA2
MOV R5,#0
CALL Hex3DecConv
MOV A,R7
MOV R3,A
MOV A,R6
MOV R2,A
MOV A,R5
MOV R1,A
RET
;--------------------------------------------------------------------------
;3 bytes of hex number to decimal convertion routine
;number in r5,r6,r7 (r5-msb,..,r7-lsb), result in r4,r5,r6,r7
;the routine counts, how many times you can subtract the 1000000 from numer, then 100000,10000,1000,100,10,1
;each counter equals position of decimal number f.e.:
; 1E74 hex - you can subtract 1000 seven (7) times, 100 seven (7) times, 10 nine (9) times and the rest
;is six (6), so your result of conversion is 7796 (equals 1E74)
;----------------------------------------------------------------
Hex3DecConv: CLR C
MOV R4,#0 ;milion counter clear
Hex3DecLoop1: MOV A,R7 ;how many time we can subtract 10000000 without carry (989680H)
SUBB A,#80H
MOV R7,A
MOV A,R6
SUBB A,#96H
MOV R6,A
MOV A,R5
SUBB A,#98H
MOV R5,A
JC Hex3DecSkip1
INC R4
JMP Hex3DecLoop1
Hex3DecSkip1: MOV A,R4
PUSH ACC ;push counter onto stack
MOV A,R7
ADD A,#80H
MOV R7,A
MOV A,R6
ADDC A,#96H
MOV R6,A
MOV A,R5
ADDC A,#98H
MOV R5,A
CLR C
MOV R4,#0
Hex3DecLoop2: MOV A,R7 ;how many times we can subtract 1000000 (F4240H) without carry
SUBB A,#40H
MOV R7,A
MOV A,R6
SUBB A,#42H
MOV R6,A
MOV A,R5
SUBB A,#0FH
MOV R5,A
JC Hex3DecSkip2
INC R4
JMP Hex3DecLoop2
Hex3DecSkip2: MOV A,R4
PUSH ACC ;push counter onto stack
MOV A,R7
ADD A,#40H
MOV R7,A
MOV A,R6
ADDC A,#42H
MOV R6,A
MOV A,R5
ADDC A,#0FH
MOV R5,A
CLR C
MOV R4,#0
Hex3DecLoop3: MOV A,R7 ;100000 (186A0H)?
SUBB A,#0A0H
MOV R7,A
MOV A,R6
SUBB A,#86H
MOV R6,A
MOV A,R5
SUBB A,#01H
MOV R5,A
JC Hex3DecSkip3
INC R4
JMP Hex3DecLoop3
Hex3DecSkip3: MOV A,R4
PUSH ACC ;onto stack
MOV A,R7
ADD A,#0A0H
MOV R7,A
MOV A,R6
ADDC A,#86H
MOV R6,A
MOV A,R5
ADDC A,#01H
MOV R5,A
Hex2DecConv: MOV R4,#0
CLR C
Hex2DecLoop1: MOV A,R7 ;10000 (2710h)?
SUBB A,#010H
MOV R7,A
MOV A,R6
SUBB A,#27H
MOV R6,A
MOV A,R5
SUBB A,#0
MOV R5,A
JC Hex2DecSkip1
INC R4
JMP Hex2DecLoop1
Hex2DecSkip1: MOV A,R4 ;onto stack
PUSH ACC
MOV A,R7
ADD A,#010H
MOV R7,A
MOV A,R6
ADDC A,#27H
MOV R6,A
CLR C
MOV R4,#0
Hex2DecLoop2: MOV A,R7 ;1000 (3E8h)?
SUBB A,#0E8H
MOV R7,A
MOV A,R6
SUBB A,#03H
MOV R6,A
JC Hex2DecSkip2
INC R4
JMP Hex2DecLoop2
Hex2DecSkip2: MOV A,R4 ;onto satck
PUSH ACC
MOV A,R7
ADD A,#0E8H
MOV R7,A
MOV A,R6
ADDC A,#03H
MOV R6,A
CLR C
MOV R4,#0
Hex2DecLoop3: MOV A,R7 ;100 (64h)?
SUBB A,#064H
MOV R7,A
MOV A,R6
SUBB A,#0H
MOV R6,A
JC Hex2DecSkip3
INC R4
JMP Hex2DecLoop3
Hex2DecSkip3: MOV A,R4 ;onto stack
PUSH ACC
MOV A,R7
ADD A,#064H
MOV R7,A
MOV A,R6
ADDC A,#0H
MOV R6,A
CLR C
MOV R4,#0
Hex2DecLoop4: MOV A,R7 ;10 (0Ah)?
SUBB A,#0AH
MOV R7,A
JC Hex2DecSkip4
INC R4
JMP Hex2DecLoop4
Hex2DecSkip4: MOV A,R4 ;onto stack
PUSH ACC
ADD A,#0AH ;1
MOV A,R7 ;tens & ones in w R7
ADD A,#0AH
MOV R7,A
POP ACC
SWAP A
ADD A,R7
MOV R7,A
POP ACC ;thousands & hundreds in R6
MOV R6,A
POP ACC
SWAP A
ADD A,R6
MOV R6,A
POP ACC ;tens thousands & hundreds thousands in R5
MOV R5,A
POP ACC
SWAP A
ADD A,R5
MOV R5,A
POP ACC ;milins & tens milions in R4
MOV R4,A
POP ACC
SWAP A
ADD A,R4
MOV R4,A
RET
END