anh em nao giải thích đoạn code này với. xin giải thích từng dòng từng câu lệnh giúp mình với.thanks anh em nhé.
LachCK bit p3.0
ShiftCK bit p3.1
SData bit p3.2
H1 bit p2.0
H2 bit p2.1
H3 bit p2.2
H4 bit p2.3
H5 bit p2.4
H6 bit p2.5
H7 bit p2.6
H8 bit p2.7
PortCT equ p2
AdcData equ p0
AdcCs bit p1.0
AdcRd bit p1.1
AdcWr bit p1.2
AdcIntr bit p1.3
MaxVolt equ 20 ;max 99V
DataBuff equ 80h
MatrixBuff equ 90h
org 0h
org 30h
mainf:
mov r7,#01h
mov PortCT,#0ffh
mov p3,#0
mov p1,#0ffh
call Resetdata
call LoadData
mov 60h,#5
main:
call scanmt
mov a,r7
rl a
mov r7,a
call delay
cjne a,#80h,main
djnz 60h,main
mov 60h,#20
call ReadAdc
call VoltConvert
call LoadData
jmp main
;################################################# ##############
;data return in Acc
ReadAdc:
push 0
clr AdcCs
clr AdcWr
nop
setb AdcWr
setb AdcWr
jb AdcIntr,$
mov r0,#10
djnz r0,$
clr AdcCs
clr AdcRd
nop
mov a,AdcData
setb AdcRd
setb AdcCs
pop 0
ret
;################################################# ##############
;volt = data* Maxvolt/255
VoltConvert:
push 0
push 5
push 6
push 7
mov r0,#DataBuff
mov b,#MaxVolt
mul ab
mov r7,b
mov r6,a
mov b,#255
call DIV_16_8
mov r5,b
mov a,r6
mov b,#10
div ab
mov @r0,a
inc r0
mov @r0,b
mov a,r5
mov b,#10
mul ab
mov r7,b
mov r6,a
mov b,#255
call DIV_16_8
inc r0
mov a,r6
mov @r0,a
pop 7
pop 6
pop 5
pop 0
ret
;################################################# #######
;so chia trong r7,r6
;so bi chia trong b
;ket qua trong r7,r6
;so du trong b
DIV_16_8: push 02h
push acc
mov r2,#16
clr a
_div001: xch a,r6
clr c
rlc a
xch a,r6
xch a,r7
rlc a
xch a,r7
rlc a
jnc _div002
clr c
sjmp _div004
_div002: cjne a,b,_div003
jmp _div004
_div003: jc _div005
_div004: subb a,b
xch a,r6
orl a,#1
xch A,R6
_div005: djnz r2,_div001
xch a,b
pop acc
pop 02h
RET
;################################################# ##############
scanmt:
push acc
push 0
push 6
mov r0,#MatrixBuff+31
mov r6,#32
mov PortCT,#0h
rescan:
mov a,@r0
anl a,r7
cjne a,#0,scdtset
clr SData
jmp scdtshift
scdtset:
setb SData
scdtshift:
setb ShiftCK
clr ShiftCK
dec r0
djnz r6,rescan
setb LachCK
clr LachCK
mov PortCT,r7
pop 6
pop 0
pop acc
ret
;################################################# ##############
delay:
mov 51h,#10
dl1: mov 50h,#100
djnz 50h,$
djnz 51h,dl1
ret
;################################################# ##############
ResetData:
mov r0,#MatrixBuff
mov a,#0ffh
mov r1,#24
Resetdt:
mov @r0,a
inc r0
djnz r1,Resetdt
ret
;################################################# ##############
LoadData:
mov r0,#MatrixBuff
mov r1,#DataBuff
Loaddt2:
mov r2,#8
mov a,@r1
call LoadDptr
mov r3,a
Loaddt1:
movc a,@a+dptr
mov @r0,a
inc r3
inc r0
mov a,r3
djnz r2,Loaddt1
inc r1
cjne r1,#DataBuff+3,Loaddt2
mov r2,#8
mov dptr,#LTV
mov r3,#0
Loaddt3:
mov a,r3
movc a,@a+dptr
mov @r0,a
inc r3
inc r0
djnz r2,Loaddt3
mov r0,#MatrixBuff+15
mov a,@r0
anl a,#0feh
mov @r0,a
ret
;################################################# ##############
;in a = 0-->9
;out a+dptr -> 0--9 of dptr
LoadDptr:
mov dptr,#LetterCode
mov b,#8
mul ab
ret
LetterCode:
DB 0FFh,0C1H,0BEH,0BEH,0BEH,0C1H,0FFH,0FFH
DB 0ffh,0FEH,0DEH,80H,0FEH,0FEH,0FFH,0FFH
DB 0ffh,0DEH,0BCH,0BAH,0B6H,0CEH,0FFH,0FFH
DB 0ffh,0DDH,0BEH,0B6H,0B6H,0C9H,0FFH,0FFH
DB 0ffh,0F3H,0EBH,0DBH,80H,0FBH,0FFH,0FFH
DB 0FFH,8DH,0AEH,0AEH,0AEH,0B1H,0FFH,0FFH
DB 0ffh,0C1H,0B6H,0B6H,0B6H,0D9H,0FFH,0FFH
DB 0ffh,9FH,0BFH,0B0H,0AFH,9FH,0FFH,0FFH
DB 0ffh,0C9H,0B6H,0B6H,0B6H,0C9H,0FFH,0FFH
DB 0ffh,0CDH,0B6H,0B6H,0B6H,0C1H,0FFH,0FFH
LTV: DB 0ffh,83H,0FDH,0FEH,0FDH,83H,0FFH,0FFH
end
LachCK bit p3.0
ShiftCK bit p3.1
SData bit p3.2
H1 bit p2.0
H2 bit p2.1
H3 bit p2.2
H4 bit p2.3
H5 bit p2.4
H6 bit p2.5
H7 bit p2.6
H8 bit p2.7
PortCT equ p2
AdcData equ p0
AdcCs bit p1.0
AdcRd bit p1.1
AdcWr bit p1.2
AdcIntr bit p1.3
MaxVolt equ 20 ;max 99V
DataBuff equ 80h
MatrixBuff equ 90h
org 0h
org 30h
mainf:
mov r7,#01h
mov PortCT,#0ffh
mov p3,#0
mov p1,#0ffh
call Resetdata
call LoadData
mov 60h,#5
main:
call scanmt
mov a,r7
rl a
mov r7,a
call delay
cjne a,#80h,main
djnz 60h,main
mov 60h,#20
call ReadAdc
call VoltConvert
call LoadData
jmp main
;################################################# ##############
;data return in Acc
ReadAdc:
push 0
clr AdcCs
clr AdcWr
nop
setb AdcWr
setb AdcWr
jb AdcIntr,$
mov r0,#10
djnz r0,$
clr AdcCs
clr AdcRd
nop
mov a,AdcData
setb AdcRd
setb AdcCs
pop 0
ret
;################################################# ##############
;volt = data* Maxvolt/255
VoltConvert:
push 0
push 5
push 6
push 7
mov r0,#DataBuff
mov b,#MaxVolt
mul ab
mov r7,b
mov r6,a
mov b,#255
call DIV_16_8
mov r5,b
mov a,r6
mov b,#10
div ab
mov @r0,a
inc r0
mov @r0,b
mov a,r5
mov b,#10
mul ab
mov r7,b
mov r6,a
mov b,#255
call DIV_16_8
inc r0
mov a,r6
mov @r0,a
pop 7
pop 6
pop 5
pop 0
ret
;################################################# #######
;so chia trong r7,r6
;so bi chia trong b
;ket qua trong r7,r6
;so du trong b
DIV_16_8: push 02h
push acc
mov r2,#16
clr a
_div001: xch a,r6
clr c
rlc a
xch a,r6
xch a,r7
rlc a
xch a,r7
rlc a
jnc _div002
clr c
sjmp _div004
_div002: cjne a,b,_div003
jmp _div004
_div003: jc _div005
_div004: subb a,b
xch a,r6
orl a,#1
xch A,R6
_div005: djnz r2,_div001
xch a,b
pop acc
pop 02h
RET
;################################################# ##############
scanmt:
push acc
push 0
push 6
mov r0,#MatrixBuff+31
mov r6,#32
mov PortCT,#0h
rescan:
mov a,@r0
anl a,r7
cjne a,#0,scdtset
clr SData
jmp scdtshift
scdtset:
setb SData
scdtshift:
setb ShiftCK
clr ShiftCK
dec r0
djnz r6,rescan
setb LachCK
clr LachCK
mov PortCT,r7
pop 6
pop 0
pop acc
ret
;################################################# ##############
delay:
mov 51h,#10
dl1: mov 50h,#100
djnz 50h,$
djnz 51h,dl1
ret
;################################################# ##############
ResetData:
mov r0,#MatrixBuff
mov a,#0ffh
mov r1,#24
Resetdt:
mov @r0,a
inc r0
djnz r1,Resetdt
ret
;################################################# ##############
LoadData:
mov r0,#MatrixBuff
mov r1,#DataBuff
Loaddt2:
mov r2,#8
mov a,@r1
call LoadDptr
mov r3,a
Loaddt1:
movc a,@a+dptr
mov @r0,a
inc r3
inc r0
mov a,r3
djnz r2,Loaddt1
inc r1
cjne r1,#DataBuff+3,Loaddt2
mov r2,#8
mov dptr,#LTV
mov r3,#0
Loaddt3:
mov a,r3
movc a,@a+dptr
mov @r0,a
inc r3
inc r0
djnz r2,Loaddt3
mov r0,#MatrixBuff+15
mov a,@r0
anl a,#0feh
mov @r0,a
ret
;################################################# ##############
;in a = 0-->9
;out a+dptr -> 0--9 of dptr
LoadDptr:
mov dptr,#LetterCode
mov b,#8
mul ab
ret
LetterCode:
DB 0FFh,0C1H,0BEH,0BEH,0BEH,0C1H,0FFH,0FFH
DB 0ffh,0FEH,0DEH,80H,0FEH,0FEH,0FFH,0FFH
DB 0ffh,0DEH,0BCH,0BAH,0B6H,0CEH,0FFH,0FFH
DB 0ffh,0DDH,0BEH,0B6H,0B6H,0C9H,0FFH,0FFH
DB 0ffh,0F3H,0EBH,0DBH,80H,0FBH,0FFH,0FFH
DB 0FFH,8DH,0AEH,0AEH,0AEH,0B1H,0FFH,0FFH
DB 0ffh,0C1H,0B6H,0B6H,0B6H,0D9H,0FFH,0FFH
DB 0ffh,9FH,0BFH,0B0H,0AFH,9FH,0FFH,0FFH
DB 0ffh,0C9H,0B6H,0B6H,0B6H,0C9H,0FFH,0FFH
DB 0ffh,0CDH,0B6H,0B6H,0B6H,0C1H,0FFH,0FFH
LTV: DB 0ffh,83H,0FDH,0FEH,0FDH,83H,0FFH,0FFH
end
Comment