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??????
please its very urgent!!!!!!
(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??????
please its very urgent!!!!!!
Replies
-
binu_jiUse 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 ADD A,R3 MOV B,#10 DIV AB MOV R3,B ADD A,#5 ADD A,R4 MOV B,#10 DIV AB MOV R4,B ADD A,#2 ADD A,R5 MOV B,#10 DIV AB MOV R5,B CJNE R6,#00D,ADD_IT SJMP CONTINUE ADD_IT: ADD A,R6 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.
Related Posts
Hello i want the use of delegates especially where exactly they use delegates and how .
i hope it is ok for this forum. may i invite all capricorns to join - it is a forum site for all capricorns. thanks.
i am a crazy CSE student n im in 3rd semester..........๐;-)
I am new here. This forum seems too helpful and the peoples seems helping too. I am doing my Electrical engineering and I hope we all will get benefited from...
Hello dear friends, I am new here so seeking your help. I am making Equivalent circuit of Voltage Controlled Circuit-VCO. If some one has worked on it or can help...