# hex to bcd?

in my project i require bcd at port 0 and 3 of microcontroller 89s52 since there are three 7447 connected
(i.e p0.0-p0.3 to 7447(1) lsb,
p0.4-p0.7 to7447(1),
p3.0-p3.3 to7447(3)msb)
which drive three 7 segment displays
now suppose i want to display (240)d then in the accumulator there is its hex equivalent i.e (F0)h which is proper but now when i convert it to bcd using the instruction DA A i get 50 in the accumulator with a carry.now this is the problem instead of having 240 at the o/p there comes 150
please can anybody help me to splve this problem??????

## Replies

• binu_ji
Use this subroutine to convert HEX to BCD
Hex2BCD:
MOV R1,#00H        ;  MSByte
MOV R2,#0F0H       ;  LSByte

MOV R3,#00D
MOV R4,#00D
MOV R5,#00D
MOV R6,#00D
MOV R7,#00D
CALL H2B
RET

H2B:        MOV B,#10D
MOV A,R2
DIV AB
MOV   R3,B              ;
MOV   B,#10             ; R7,R6,R5,R4,R3
DIV   AB
MOV   R4,B
MOV   R5,A
CJNE R1,#0H,HIGH_BYTE   ; CHECK FOR HIGH BYTE
SJMP ENDD

HIGH_BYTE:
MOV   A,#6
MOV   B,#10
DIV   AB
MOV   R3,B
MOV   B,#10
DIV   AB
MOV   R4,B
MOV   B,#10
DIV   AB
MOV   R5,B
SJMP CONTINUE
CONTINUE:
MOV R6,A
DJNZ R1,HIGH_BYTE
MOV B, #10D
MOV A,R6
DIV AB
MOV R6,B
MOV R7,A
ENDD:   RET
Just call this routine by loading the value into the R2 and you will get the result like this
R3=0
R4=4
R5=2

You are reading an archived discussion.

## Delegates in c#

Hello i want the use of delegates especially where exactly they use delegates and how .

## Attention All Capricorns

i hope it is ok for this forum. may i invite all capricorns to join - it is a forum site for all capricorns. thanks.