Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Binary/BCD converter

Status
Not open for further replies.

Ranco_Raider

Newbie
Joined
Aug 2, 2022
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
13
Hey guys, I'm using a pic16F690 and I need assembly code to convert an 8 bit binary to packed bcd and vice versa. I have to use the w register as the input and output. Im using MPLab X. Please can someone help with the code. Thanks for the help
 

Hi,

We will not write code for you, but we will help you.
So show what you have done so far.

Klaus
 



Maybe you could draw from the above to do your task.


Regards, Dana.
 
Last edited:

Hey guys, I'm using a pic16F690 and I need assembly code to convert an 8 bit binary to packed bcd and vice versa. I have to use the w register as the input and output. Im using MPLab X. Please can someone help with the code. Thanks for the help
Careful what you ask for you just might get it.
Code:
;
;   Data space use by binary to BCD convertion
    PSECT   BCD_Data,global,class=RAM,space=1,delta=1,noexec
;
    GLOBAL  BCD_Result
BCD_Result: DS      2
;
    PSECT   MainCode,global,class=CODE,delta=2
;
Bin2BCD:
    movwf   BCD_Result
    clrf    BCD_Result+1
    movlw   200
    subwf   BCD_Result,W
    skipnc
    movwf   BCD_Result
    skipnc
    bsf     BCD_Result+1,1
    movlw   100
    subwf   BCD_Result,W
    skipnc
    movwf   BCD_Result
    skipnc
    bsf     BCD_Result+1,0
    movlw   80
    subwf   BCD_Result,W
    skipnc
    movwf   BCD_Result
    skipnc
    bsf     BCD_Result+1,7
    movlw   40
    subwf   BCD_Result,W
    skipnc
    movwf   BCD_Result
    skipnc
    bsf     BCD_Result+1,6
    movlw   20
    subwf   BCD_Result,W
    skipnc
    movwf   BCD_Result
    skipnc
    bsf     BCD_Result+1,5
    movlw   10
    subwf   BCD_Result,W
    skipnc
    movwf   BCD_Result
    skipnc
    bsf     BCD_Result+1,4
    movf    BCD_Result+1,W
    xorwf   BCD_Result,W
    andlw   0xF0
    xorwf   BCD_Result+1,F
    xorwf   BCD_Result,F
    movf    BCD_Result,W
    return
;
BCD2Bin:
    movlw   0x0F
    andwf   BCD_Result,W
    btfsc   BCD_Result,4
    addlw   10
    btfsc   BCD_Result,5
    addlw   20
    btfsc   BCD_Result,6
    addlw   40
    btfsc   BCD_Result,7
    addlw   80
    btfsc   BCD_Result+1,0
    addlw   100
    btfsc   BCD_Result+1,1
    addlw   200
    return
;
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top