Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

binary to bcd

Status
Not open for further replies.

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.
 
biary tto bcd

I must apologise for my comment, a friend of mine was messing about and wrote that. I hope no one was offended by those silly remarks. Still is there anyone proficient in mcs 51 assembler language that can help me with the original problem.
 
Here is how you do it:
Code:
;********************************************************************
; 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
 
binary to bcd

Good man. Thanks for the help, i was going to use a binary to bcd converter ,a 74185 but couldnt get one. Much better to do it with software. I am only beginning assembler so i was'nt fully familiar with all the instructions.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top