;Convert BCD decimal to binary decimal (2 digits)
; Entry: R0 (low first address), R7
; Occupied resources: ACC, B, R5
; Stack requirement: 2 bytes
; Exits: R3, R4
PDTB:CLR A
MOV R3,A
MOV R4,A
PDB1:MOV A,R3
MOV B,#9AH
MUL AB
MOV R5,B
XCH A,R4
MOV B,#19H
MUL AB
ADD A,R4
MOV A,R5
ADDC A ,B
MOV R5,A
MOV A,@R0
MOV B,#9AH
MUL AB
ADD A,R5
MOV R4,A
CLR A
ADDC A,B
XCH A,R3
MOV B,#19H
MUL AB
ADD A,R4
MOV R4, A
MOV A,B
ADDC A,R3
MOV R3,A
MOV A,@R0
MOV B,#19H
MUL AB
ADD A,R3
MOV R3,A
DEC R0
DJNZ R7,PDB1
RET
;Convert BCD decimal to binary decimal (N bits)
; Entry: R1 (low first address), M, N
; Occupied resources: ACC, B, R2, R3, R7
; Stack requirement: 2 bytes
; Exit: R0
PDTBMN :MOV A,R0
MOV R2,A
MOV A,R1
MOV R3,A
MOV B,N
CLR A
PDBMN1 :MOV @R0,A
INC R0
DJNZ B,PDBMN1
MOV A,N
SWAP A
RR A
MOV R7,A
PDBMN2 :MOV A,R2
MOV R0,A
MOV A,R3
MOV R1,A
MOV B,M
CLR C
PDBMN3 :MOV A,@R1
ADDC A,@R1
DA A
JNB ACC.4,PDBMN4
SETB C
CLR ACC.4
PDBMN4 :MOV @R1,A
INC R1
DJNZ B,PDBMN3
MOV B,N
PDBMN5 :MOV A,@R0
RLC A
MOV @R0,A
INC R0
DJNZ B,PDBMN5
DJNZ R7,PDBMN2
MOV A,R2
MOV R0,A
RET
;Convert BCD integer to binary integer (1 bit)
; Entry: R0 (high address), R7
; Occupied resources: ACC, B
; Stack requirement: 2 bytes
; Exit: R4
IDTB1 :CLR A
MOV R4,A
IDB11 :MOV A,R4
MOV B,#0AH
MUL AB
ADD A,@R0
INC R0
MOV R4,A
DJNZ R7,IDB11
RET
;Convert BCD integer to binary integer (2 bits)
; Entry: R0 (high address), R7
; Occupied resources: ACC, B
; Stack requirement: 2 bytes
; Exit: R3, R4
IDTB2:CLR A
MOV R3,A
MOV R4,A
IDB21:MOV A,R4
MOV B,#0AH
MUL AB
MOV R4,A
MOV A,B
XCH A,R3
MOV B,#0AH
MUL AB
ADD A,R3
MOV R3 ,A
MOV A,R4
ADD A,@R0
INC R0
MOV R4,A
CLR A
ADDC A,R3
MOV R3,A
DJNZ R7,IDB21
RET
;Convert BCD integer to binary integer (3 bits)
; Entry: R0 (high address), R7
; Occupied resources: ACC, B
; Stack requirement: 2 bytes
; Exit: R2, R3, R4
IDTB3:CLR A
MOV R2,A
MOV R3,A
MOV R4,A
IDB31:MOV A,R4
MOV B,#0AH
MUL AB
MOV R4,A
MOV A,B
XCH A,R3
MOV B,#0AH
MUL AB
ADD A ,R3
MOV R3,A
CLR A
ADDC A,B
XCH A,R2
MOV B,#0AH
MUL AB
ADD A,R2
MOV R2,A
MOV A,R4
ADD A,@R0
INC R0
MOV R4,A
CLR A
ADDC A ,R3
MOV R3,A
CLR A
ADDC A,R2
MOV R2,A
DJNZ R7,IDB31
RET
;Convert BCD integer to binary integer (N bits)
; Entry: R1 (high address), M, N
; Occupied resources: ACC, B, R2, R7, NCNT, F0
; Stack requirement: 2 bytes
; Exit: R0
IDTBMN :MOV A,R0
MOV R2,A
MOV B,N
CLR A
IDBMN1 :MOV @R0,A
INC R0
DJNZ B,IDBMN1
MOV A,R2
MOV R0,A
MOV A,M
MOV NCNT,A
IDBMN2 :MOV R7, N
CLR A
CLR F0
IDBMN3 :XCH A,@R0
MOV B,#0AH
MUL AB
MOV C,F0
ADDC A,@R0
MOV F0,C
MOV @R0,A
INC R0
MOV A,B
DJNZ R7,IDBMN3
MOV A, R2
MOV R0,A
MOV A,@R1
INC R1
ADD A,@R0
MOV @R0,A
DJNZ NCNT,IDBMN2
RET
;Convert binary decimal (2 digits) to decimal decimal (separated BCD code)
; Entry: R3, R4, R7
; Occupied resources: ACC, B
; Stack requirement: 3 bytes
; Exit: R0
PBTD:MOV A,R7
PUSH A
PBD1:MOV A,R4
MOV B,#0AH
MUL AB
MOV R4,A
MOV A,B
XCH A,R3
MOV B,#0AH
MUL AB
ADD A,R3
MOV R3,A
CLR A
ADDC A,B
MOV @R0,A
INC R0
DJNZ R7,PBD1
POP A
MOV R7,A
MOV A,R0
CLR C
SUBB A,R7
MOV R0,A
RET
;Convert binary decimal (M digits) to decimal decimal (separated BCD code)
; Entry: R1, M, N
; Occupied resources: ACC, B, R2, R3, R7, NCNT
; Stack requirement: 2 bytes
; Exit: R0
PBTDMN :MOV A,R0
MOV R2,A
MOV A,R1
MOV R3,A
MOV A,N
MOV NCNT,A
PBDMN1 :MOV R7,M
CLR A
CLR F0
PBDMN2 :XCH A,@R1
MOV B,#0AH
MUL AB
MOV C,F0
ADDC A,@R1
MOV F0,C
MOV @R1,A
INC R1
MOV A,B
DJNZ R7,PBDMN2
ADDC A,#00H
MOV @R0,A
INC R0
MOV A,R3
MOV R1,A
DJNZ NCNT ,PBDMN1
MOV A,R2
MOV R0,A
RET
;Convert binary integer (2 digits) to decimal integer (separated BCD code)
; Entry: R3, R4
; Occupied resources: ACC, R2, NDIV31
; Stack requirement: 5 bytes
; Exit: R0, NCNT
IBTD21 :MOV NCNT,#00H
MOV R2,#00H
IBD211 :MOV R7,#0AH
LCALL NDIV31
MOV A,R7
MOV @R0,A
INC R0
INC NCNT
MOV A,R3
ORL A,R4
JNZ IBD211
MOV A,R0
CLR C
SUBB A,NCNT
MOV R0,A
RET
;Convert binary integer (2 digits) to decimal integer (combined BCD code)
; Entry: R3, R4
; Occupied resources: ACC, B, R7
; Stack requirement: 3 bytes
; Exit: R0
IBTD22 :MOV A,R0
PUSH A
MOV R7,#03H
CLR A
IBD221 :MOV @R0,A
INC R0
DJNZ R7,IBD221
POP A
MOV R0,A
MOV R7,#10H
IBD222 :PUSH A
CLR C
MOV A,R4
RLC A
MOV R4,A
MOV A,R3
RLC A
MOV R3,A
MOV B,#03H
IBD223 :MOV A,@R0
ADDC A,@R0
DA A
MOV @R0,A
INC R0
DJNZ B,IBD223
POP A
MOV R0, A
DJNZ R7,IBD222
RET
;Convert binary integer (3 digits) to decimal integer (separated BCD code)
; Entry: R2, R3, R4
; Occupied resources: ACC, R2, NDIV31
; Stack requirement: 5 bytes
; Exit: R0, NCNT
IBTD31 :CLR A
MOV NCNT,A
IBD311 :MOV R7,#0AH
LCALL NDIV31
MOV A,R7
MOV @R0,A
INC R0
INC NCNT
MOV A,R2
ORL A,R3
ORL A,R4
JNZ IBD311
MOV A,R0
CLR C
SUBB A,NCNT
MOV R0,A
RET
;Convert binary integer (3 digits) to decimal integer (combined BCD code)
; Entry: R2, R3, R4
; Occupied resources: ACC, B, R7
; Stack requirement: 3 bytes
; Exit: R0
IBTD32 :MOV A,R0
PUSH A
MOV R7,#04H
CLR A
IBD321 :MOV @R0,A
INC R0
DJNZ R7,IBD321
POP A
MOV R0,A
MOV R7,#18H
IBD322 :PUSH A
CLR C
MOV A,R4
RLC A
MOV R4,A
MOV A,R3
RLC A
MOV R3,A
MOV A,R2
RLC A
MOV R2,A
MOV B,#04H
IBD323 :MOV A,@R0
ADDC A,@R0
DA A
MOV @R0,A
INC R0
DJNZ B,IBD323
POP A
MOV R0,A
DJNZ R7,IBD322
RET
;Convert binary integer (M bits) to decimal integer (combined BCD code)
; Entry: R1, M, N
; Occupied resources: ACC, B, R2, R3, R7
; Stack requirement: 2 bytes
; Exit: R0
IBTMN:MOV A,R0
MOV R2,A
MOV A,R1
MOV R3,A
MOV B,N
CLR A
IBDMN1:MOV @R0,A
INC R0
DJNZ B,IBDMN1
MOV A,M
SWAP A
RR A
CLR C
MOV R7, A
IBDMN2 :MOV A,R2
MOV R0,A
MOV A,R3
MOV R1,A
MOV B,M
IBDMN3 :MOV A,@R1
RLC A
MOV @R1,A
INC R1
DJNZ B,IBDMN3
MOV B,N
IBDMN4 :MOV A,@R0
ADDC A,@R0
DA A
JNB ACC.4,IBDMN5
SETB C
CLR ACC.4
IBDMN5 :MOV @R0,A
INC R0
DJNZ B,IBDMN4
DJNZ R7,IBDMN2
MOV A,R2
MOV R0,A
RET
Previous article:MCS51 microcontroller search and search program
Next article:Analysis of the structure and principle of 51 microcontroller memory
- Popular Resources
- Popular amplifiers
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Fundamentals and Applications of Single Chip Microcomputers (Edited by Zhang Liguang and Chen Zhongxiao)
- Principles and Applications of Single Chip Microcomputers 3rd Edition (Zhang Yigang)
- Principles and Applications of Single Chip Microcomputers and C51 Programming (3rd Edition) (Xie Weicheng, Yang Jiaguo)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications