Shopping Cart

0 item(s) - Rs.0.00
Your shopping cart is empty!
Please update your Flash Player to view content.

. . . FOLLOW  US







 
 
12-bit HEX to BCD Convertor
Code Library - 8051 Assembly
Written by Administrator   

This subroutine converts 12 bit hexadecimal number into its equivalent BCD number. Since the number to be converted is 12 bit total two bytes will be required to represent it. And the converted number will be maximum 4 byte but since the output is in BCD two memory locations will be used to store the final result. The number to be converted is stored in R6 (MSB) & R7 (LSB) whereas the converted BCD number is stored in R0 (MSB) & R1 (LSB).

First we work on the HEX LSB (R7) & convert it into BCD as stated in 8-bit HEX to BCD convertor. Then we check if the HEX MSB (R6) is 0 if not zero we add 256 to the BCD & decrement the HEX MSB (R6) until it becomes zero.

Hex to BCD:

mov r0,#00h

mov r1,#00h

clr c

mov a,r7

mov b,#100

//Divide LSB by 100

div ab

mov r0,a

//save the 100th place

mov a,b

mov b,#10

//Divide LSB by 10

clr c

div ab

swap a

orl a,b

mov r1,a

//save the units & tenth place

mov a,r6

cjne a,#00h,c1_hextobcd

//Check if the MSB is 0 if not then continue

ret

 

//Add 256 to the BCD number & decrement the HEX MSB by 1 until it becomes 0

 

c1_hextobcd:

clr c

mov a,r1

add a,#56h

da a

mov r1,a

jnc c2_hextobcd

clr c

mov a,r0

add a,#01h

da a

mov r0,a

c2_hextobcd:

clr c

mov a,r0

add a,#02h

da a

mov r0,a

djnz r6,c1_hextobcd

ret

.

 
 

Featured

Latest

EEPROM 24C64
Rs.35.00
EEPROM 24C512
Rs.90.00
EEPROM 24C32
Rs.25.00
EEPROM 24C256
Rs.75.00
 
 
 
.
 TUTORIALS
.
  8051 Tutorial
 
  Power Supply
 
CODE LIBRARY
.

  8051 Assembly
 
  C Code Library
 

.
 PROJECTS
.
  Project List
 
  Synopsis and Abstract
 
DOWNLOADS
.

  Datasheets
 
  Download
 

.
 POPULAR
.
  About Us
 
  DNA Shop
 
  Totorial
 
  Code Library
 
  Download
 

.
CONTACT US
.

Mr. Amol Shah

DNA Technology Nashik,

Maharashtra 422009 India

Phone : 0253-3023939

Mobile : 09225145135

Email : contact@dnatechindia.com