8051 Lcd16x2 Interfacing In 4 Bit Mode With 8051 |Using Keil C – AT89C51| Assembly Language|

 Write a program to get 8 bits data from port 3.The microcontroller will receive 8 bits data from Port 3 by the Switches. Port 1 (Data Pins) and 2 (RS , RW, EN ) of microcontroller will show the value of corresponding input on LCD as shown in fig below. (Initialize Port 3 with Zero)

Source code

ORG 00H

MOV A,#38H // 5x7 matrix

ACALL COMNWRT

MOV A,#0EH //Display ON, Cursor ON

ACALL COMNWRT

MOV A,#01H  //Clear screen display

MOV A,#80H //Force the cursor to the beginning of the 1st line

MOV DPTR,#200H

MOV R1,#05

AGAIN:

MOV A,#0

MOVC A,@A+DPTR

ACALL DATAWRT

INC DPTR

DJNZ R1,AGAIN

MOV P3,#0

STRAT:

MOV A,#0C8H

ACALL COMNWRT

MOV A,P3

MOV B,#10

DIV AB

MOV R1,B

MOV B,#10

DIV AB

MOV R2,B

MOV R3,A

ADD A,#48

ACALL DATAWRT

MOV A,R2

ADD A,#48

ACALL DATAWRT

MOV A,R1

ADD A,#48

ACALL DATAWRT

SJMP STRAT

ORG 200H

DB"VALUE"

DELAY:

MOV R0,#255

WAIT:

DJNZ R0,WAIT

RET

COMNWRT:

MOV P1,A

CLR P2.0   // RS=1 for command

CLR P2.1   //R/W=0 for write

SETB P2.2  //E=1 for HIGH pulse

ACALL DELAY

CLR P2.2   //E=1 for LOW pulse

RET

DATAWRT:

MOV P1,A

SETB P2.0 // RS=1 for command

CLR  P2.1 //R/W=0 for write

SETB P2.2 //E=1 for HIGH pulse

ACALL DELAY

CLR P2.2 //E=0 for LOW pulse

RET

 

END

Result:

Source code

ORG 00H

MOV A,#38H // 5x7 matrix

ACALL COMNWRT

MOV A,#0EH //Display ON, Cursor ON

ACALL COMNWRT

MOV A,#01H  //Clear screen display

MOV A,#80H //Force the cursor to the beginning of the 1st line

MOV DPTR,#200H

MOV R1,#05

AGAIN:

MOV A,#0

MOVC A,@A+DPTR

ACALL DATAWRT

INC DPTR

DJNZ R1,AGAIN

MOV P3,#0

STRAT:

MOV A,#0C8H

ACALL COMNWRT

MOV A,P3

MOV B,#10

DIV AB

MOV R1,B

MOV B,#10

DIV AB

MOV R2,B

MOV R3,A

ADD A,#48

ACALL DATAWRT

MOV A,R2

ADD A,#48

ACALL DATAWRT

MOV A,R1

ADD A,#48

ACALL DATAWRT

SJMP STRAT

ORG 200H

DB"VALUE"

DELAY:

MOV R0,#255

WAIT:

DJNZ R0,WAIT

RET

COMNWRT:

MOV P1,A

CLR P2.0   // RS=1 for command

CLR P2.1   //R/W=0 for write

SETB P2.2  //E=1 for HIGH pulse

ACALL DELAY

CLR P2.2   //E=1 for LOW pulse

RET

DATAWRT:

MOV P1,A

SETB P2.0 // RS=1 for command

CLR  P2.1 //R/W=0 for write

SETB P2.2 //E=1 for HIGH pulse

ACALL DELAY

CLR P2.2 //E=0 for LOW pulse

RET

END

Result:



Post a Comment

0 Comments