Convert a two-byte BCD into a single byte

Status
Not open for further replies.
Code:
;#############################################################################
;#              VAULT INFORMATION SERVICES - 8052 CODE EXAMPLE               #
;#             (C) Copyright 1997 by Vault Information Services              #
;#                                                                           #
;# This code fragment is provided to the public free of charge and WITHOUT   #
;# OF ANY KIND,  NEITHER EXPRESS OR IMPLIED.   This code is offered as  an   #
;# example of  8052  programming.   VIS extends no warranty regarding  its   #
;# functionality or fitness for a specific purpose.;#                        #
;# The user may  utilize this code in  any way he/she sees fit,  including   #
;# using it in his/her own program,  commercial or otherwise.  However, by   #
;# using this  code the  user states his/her  acceptance of the  above and   #
;# holds  VIS indemnified against any and all claims that may arise due to   #
;# the use or misuse of this code.                                           #
;#############################################################################

;********************************************************************
;********************************************************************
;** Function: bcd_to_byte                                          **
;** Purpose:  Convert a two-byte BCD into a single byte            **
;** Input:    A    = Hi byte to convert (ASCII 0x30-0x39,0x41-0x46)**
;**           R0   = Lo byte to convert (ASCII 0x30-0x39,0x41-0x46)**
;** Output:   A    = Converted value (binary 0x00-0xFF)            **
;** Destroyed Registers: None                                      **
;********************************************************************
;********************************************************************
bcd_to_byte:
    XCH     A,R0
    SUBB    A,#30h
    JNB     ACC.4,bcd_to_byte_2
    SUBB    A,#07h
bcd_to_byte_2:
    XCH     A,R0
    SUBB    A,#30h
    JNB     ACC.4,bcd_to_byte_3
    SUBB    A,#07h
bcd_to_byte_3:
    SWAP    A
    ORL     A,R0
    RET

I program in C with the pic16f690... Im confused with the asm code. But i want to use this program Convert a two-byte BCD into a single byte. Could some one explain how to achieve this so i can code it in C please.
 
if you look on the normal Micro forum i posted this in C i think. Just look through my threads. also i think i have this in my C18 Code Sheet below around page 8-9
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…