Saturday, April 30, 2016

8051 Program – ascii to bcd

; ASCII to BCD
; To convert ASCII to packed BCD,
; it is first converted to unpacked BCD(to mask 3) and
; then combined to make packed BCD.
; 40H = 34H ascii
; 41H = 35H ascii
; 42H = 45H bcd
ORG 0H
ADDR EQU 40H
ASCII_1 EQU 34H
ASCII_2 EQU 35H
MAIN:
MOV A, #ASCII_1 ; fill memory with ascii
MOV R0,#ADDR
MOV @R0, A
INC R0
MOV A, #ASCII_2
MOV @R0, A
LCALL CONV
SJMP MAIN
CONV:
MOV R0,#ADDR ;R0=40h,Internal memory adress
MOV A,@R0 ;a=hex value of Ist ASCII number
ANL A,#0FH ;mask upper nibble
SWAP A ;swap upper and lower nibble of a
MOV B,A ;save the number in B
INC R0 ;increment R0
MOV A,@R0 ;get the next number from memory
ANL A,#0FH;mask Higher nibble
ORL A,B ;or a & B
INC R0 ;increment memory address to store the result
MOV @R0,A ;move the content of A to internal RAM location
RET
END



Related topics:
8051 Program - decimal to hex   |   8051 Program - hex to decimal 8bit   |   8051 Program - decimal to ascii   |   8051 Program - ascii to decimal   |   8051 Program - hex to ascii   |   8051 Program - ascii to hex   |   8051 Program - bcd to ascii   |   8051 Program - bcd to hex 8bit   |   8051 Program - hex to bcd 8bit   |   8051 Program - hex to bcd 12bit   |   8051 Program - memory subroutines   |   8051 Program - math subroutines   |   8051 Program - conversion subroutines

List of topics: 8051

No comments:

Post a Comment