;############################################################################# ;# 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 ;******************************************************************** ;******************************************************************** ;** Function: byte_to_bcd ** ;** Purpose: Convert a single byte into two BCD digits ** ;** Input: A = Byte to convert (0x00-0xFF) ** ;** Output: A = High nibble (ASCII 0x30-0x39,0x41-0x46) ** ;** R0 = Low nibble (ASCII 0x30-0x39, 0x41-0x46) ** ;** Destroyed Registers: None ** ;******************************************************************** ;******************************************************************** byte_to_bcd: MOV R0,A ANL A,#0Fh ADD A,#0F6h JNC byte_to_bcd_2 ADD A,#07h byte_to_bcd_2: ADD A,#3Ah XCH A,R0 SWAP A ANL A,#0Fh ADD A,#0F6h JNC byte_to_bcd_3 ADD A,#07h byte_to_bcd_3: ADD A,#3Ah RET END