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.

ascii to binary and binary to ascii

Status
Not open for further replies.

umutguncan

Junior Member level 1
Joined
Nov 23, 2005
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,458
ascii in to binary

how can I do this with assemble? (ı use 8051 )
 

conversion from binary to ascii in 8051

Code:
;*******************************************************************************
;           Returns the ASCII codes from the nibbles of a byte stored in the Acc.
;           After being called the high nibble is in the Acc and the low nibble 
;           is in the B register.
;
;
;          ;usage:
;
;          mov a, #byte
;          CALL nibble
;
;          ;returns
;          ;A= high nibble
;          ;B= low nibble
;*******************************************************************************

nibble:
            mov   b,a          ; b=a        ; stores Acc in B
            anl   a,#0f0h      ; a=xxxx0000    ; A && #f0h (get the high nibble)
            swap  a            ; a=0000xxxx    ; swap nibbles
            orl   a,#30h       ; a=0011xxxx    ; add #30h, if nibble is
            push acc           ; 0-9 we have the ASCII value
            push b             ; stores A and B
            mov b, #3ah        ; stores #3ah in B
            div ab             ; divide A/#3ah
            jz, recupera1      ; if zero, nibble < #0Ah
nibble1_ok:
            pop b              ; recover B
            pop acc            ; recover A
            add a, #07h        ; adds #07h to get ASCII of A-F
            xch a,b
            jmp nibble2
recupera1:
            pop b            ; stores B
            pop acc            ; stores A
            xch a,b
nibble2:
            anl   a,#0fh        ; a=0000xxxx    ; A && #0fh (get low nibble)
            orl   a,#30h        ; a=0011xxxx    ; add #30h, if nibble is
            push acc            ; 0-9 we have the ASCII value
            push b            ; stores A and B
            mov b, #3ah            ; stores #3ah in B
            div ab            ; divide A/#3ah
            jz, recupera2        ; if zero, nibble < #0Ah
            pop b            ; recover B
            pop acc            ; recover A
            add a, #07h        ; adds #07h to get ASCII of A-F
            xch a,b
            ret                ; return to main routine
recupera2:
            pop b            ; recover B
            pop acc            ; recover A
            xch a,b
            ret                ; return to main routine

;*******************************************************************************

Code:
; ===============================================================
; ASC_HEX - 	See if character in ACC is number and if so convert to a hex nibble...

A_H:
			CJNE	A, #'0', A_H1

A_H1:			JC	AH_Bad		; Is character less than a '0'?
			CJNE	A, #'9'+1, A_H2		; Test value range

A_H2:			JC	AH_Val_09		; Is character between '0' and '9'?
			LJMP	AH_Bad

AH_Val_09:		CLR	C
			SUBB	A, #'0'
			CLR	HexFlag
AH_Exit:		RET

AH_Bad:		SETB	HexFlag
			LJMP	AH_Exit	

; ===============================================================

Regards,
IanP
 

ascii #07h

hey please clear ur question , would u like to assemble the code on actual 8051 or the simulator that support 8051 ?
 

how to convert from binary to ascii in 8051

next time place it in to microcontroller section
search it on 8052.com

by the way it is not possible to convert ascii in to binary and vice-versa.
but some symbol you can convert
for ex
hex no '0' represent into bin is '0000' and in ascii '30'
you just add/sub 30 in to bin/ascii you will get ascii/bin.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top