Showing posts with label Binary to hex conversion using 8051. Show all posts

Assembly language program for Binary to hex conversion



org 00h
rs equ p1.0
rw equ p1.1
en equ p1.2
lcd equ p0
MOV LCD,#38H
ACALL CMD
ACALL DELAY
MOV LCD,#06H
ACALL CMD
ACALL DELAY
MOV LCD,#01H
ACALL CMD
ACALL DELAY
MOV LCD,#0EH
ACALL CMD
ACALL DELAY
MOV LCD,#80H
ACALL CMD
ACALL DELAY
CLR A
MOV P2,#0FFH

MOV R0,#08
H2: ACALL KEYBOARD
DJNZ R0,H2
MOV A,R3
MOV B,#08
MUL AB
MOV R3,A

MOV A,R4
MOV B,#04
MUL AB
MOV R4,A

MOV A,R5
MOV B,#02
MUL AB
MOV R5,A

MOV A,R6
MOV B,#01
MUL AB
MOV R6,A

CLR A

ADD A,R3
ADD A,R4
ADD A,R5
ADD A,R6
MOV LCD,#'='
ACALL DISP
ACALL DELAY
MOV DPTR,#MSG
MOVC A,@A+DPTR
MOV LCD,A
ACALL DISP
ACALL DELAY
CLR A
CLR PSW.3
SETB PSW.4
MOV A,R0
MOV B,#08
MUL AB
MOV R0,A

MOV A,R1
MOV B,#04
MUL AB
MOV R1,A

MOV A,R2
MOV B,#02
MUL AB
MOV R2,A

MOV A,R7
MOV B,#01
MUL AB
MOV R7,A

CLR A

ADD A,R0
ADD A,R1
ADD A,R2
ADD A,R7
CLR PSW.3
CLR PSW.4
MOV DPTR,#MSG
MOVC A,@A+DPTR
MOV LCD,A
ACALL DISP
ACALL DELAY
MOV LCD,#'H'
ACALL DISP
ACALL DELAY
MOV LCD,#0CH
ACALL CMD
ACALL DELAY
ALT: SJMP ALT






KEYBOARD: MOV A,P2
CJNE A,#0FEH,S1
MOV A,#00
CJNE R0,#08,L1
MOV R3,A
L1: CJNE R0,#07,L2
MOV R4,A
L2: CJNE R0,#06,L3
MOV R5,A
L3: CJNE R0,#05,L4
MOV R6,A
L4: CJNE R0,#04,L5
CLR PSW.3
SETB PSW.4
MOV R0,A
CLR PSW.3
CLR PSW.4
L5: CJNE R0,#03,L6
CLR PSW.3
SETB PSW.4
MOV R1,A
CLR PSW.3
CLR PSW.4
L6: CJNE R0,#02,L7
CLR PSW.3
SETB PSW.4
MOV R2,A
CLR PSW.3
CLR PSW.4
L7: CJNE R0,#01,L8
CLR PSW.3
SETB PSW.4
MOV R7,A
CLR PSW.3
CLR PSW.4
L8: SJMP RAM

S1: CJNE A,#0FDH,KEYBOARD
MOV A,#01
CJNE R0,#08,M1
MOV R3,A
M1: CJNE R0,#07,M2
MOV R4,A
M2: CJNE R0,#06,M3
MOV R5,A
M3: CJNE R0,#05,M4
MOV R6,A
M4: CJNE R0,#04,M5
CLR PSW.3
SETB PSW.4
MOV R0,A
CLR PSW.3
CLR PSW.4
M5: CJNE R0,#03,M6
CLR PSW.3
SETB PSW.4
MOV R1,A
CLR PSW.3
CLR PSW.4
M6: CJNE R0,#02,M7
CLR PSW.3
SETB PSW.4
MOV R2,A
CLR PSW.3
CLR PSW.4
M7: CJNE R0,#01,RAM
CLR PSW.3
SETB PSW.4
MOV R7,A
CLR PSW.3
CLR PSW.4

RAM: MOV DPTR,#MSG
MOVC A,@A+DPTR
MOV LCD,A
ACALL DISP
ACALL DELAY
RET

CMD: CLR RS
     CLR RW
                 SETB EN
                 ACALL DELAY
                 CLR EN
                 RET

DISP: SETB RS
      CLR RW
                  SETB EN
                  ACALL DELAY
                  CLR EN
                  RET

DELAY: MOV R1,#0F0H
HERE2: MOV R2,#0FFH
HERE:  DJNZ R2,HERE
       DJNZ R1,HERE2
                   RET

MSG: DB '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
END


 If you have any problem then comment!!!!!!!!!!

Binary to hex conversion using 8051

                              

                              

This is the circuit diagram of binary to hex conversion using 8051 microcontroller. Result will be displayed on LCD. We can enter binary number of 8 digit to get the result in hexadecimal. I have connected two switches with the pin p2.0 and p2.1. 
You are required to know about LCD and keypad interfacing. When we press the first switch that is connected to p2.0 then 0 will be displayed on LCD and when we press the switch connected to P2.1 then 1 will be displayed on LCD. 
We just have to enter the 8 binary digit, then result will be automatically displayed on LCD after pressing 8th digit.
 
 
CLICK HERE TO SEE THE ASSEMBLY LANGUAGE PROGRAM FOR BINARY TO HEX CONVERSION

- Copyright © Microcontroller Projects -Metrominimalist- Powered by Blogger - Designed by Johanes Djogan -