jimbob jones
New Member
I need to convert a 8 bit binary output to 2 bcd numbers for driving 2 seven seg displaysfrom an 8051.If anyone could tell me how to do this as a software solution in the mcs 51 assembler language.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
;********************************************************************
; FUNCTION: BIN2BCD8
; PURPOSE: CONVERTS 8-BIT NUMBER TO TWO BCD DIGITS
; INPUT: A HAS 8-BIT NUMBER TO BE CONVERTED TO BCD
; OUTPUT: BCD1 = HIGH NIBBLE
; BCD0 = LOW NIBBLE
;********************************************************************
BIN2BCD8:
MOV R0,A
ANL A,#0FH
ADD A,#0F6H
JNC BB2
ADD A,#07H
BB2:ADD A,#3AH
XCH A,R0
SWAP A
ANL A,#0FH
ADD A,#0F6H
JNC BB3
ADD A,#07H
BB3:ADD A,#3AH
MOV BCD1, A
MOV BCD0, R0
RET