CE Home
Navigation
Go Back   CrazyEngineers Forum > CE : Technical Discussions > Electrical & Electronics Engineering
Notices


Advertisements
Reply
 
LinkBack Thread Tools Display Modes

  #1 (permalink)
Old 2nd November 2008, 08:13 PM
CE - Newbie
 
Join Date: 2nd November 2008
I'm a Crazy electronics Engineer
Posts: 1
Default 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!!!!!!
pranitamm is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2 (permalink)
Old 3rd November 2008, 12:04 PM
CE - Apprentice
 
Join Date: 13th July 2007
I'm a Crazy Electronics Engineer
Posts: 14
Default Re: hex to bcd?

Use this subroutine to convert HEX to BCD
Hex2BCD:
Code:
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

Last edited by The_Big_K; 3rd November 2008 at 12:10 PM. Reason: Adding [code] ... [/code] tags around the code
binu_ji is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +5.5. The time now is 11:29 AM.
Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
Member comments are owned by the poster. Copyright © 2005-2008 CrazyEngineers.com. All rights reserved.

Advertisements