|

8051 LCD interfacing for sending string

8051 LCD interfacing, sometimes  becomes difficult in assembly. Unless and you give it a try your self you wont be able to do it. Following is the code for 8051 lcd interfacing experimentally tested on lcd and verified in all respects. So there is  no doubt about the working of this code. This is not a hi-fi code but this code is sufficient for the beginners working with 8051 lcd interfacing.

;OBJECTIVE:


;THIS PROGRAM DISPLAYS THE STRING "TEMPERATURE" ON LCD AND CONVERT HEX NUMBER(WHICH IS WRITTEN '1EH' IN THE

;PROGRAM) IN DECIMAL.HEX NUMBERS HAVE RANGE(0AH-64H) BECAUSE THIS PROGRAM IS ABLE TO SHOW DECIMAL NUMBER

;FROM (10-100)

;PROGRAMER: JAMAL

;University : NUST

;PROGRAM NAME: LCD DISPLAY HEX TO DECIMAL CONVERSION

;MICROCONTROLLER: ATMEL AT89S52

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

;........DEFINING VARIABLES..........
ORG 00H

RS_LCD BIT P1.5 ; pins 1.5,1.6,1.7 of microcontroller

RW_LCD BIT P1.6 ; is connected with register select,

EN_LCD BIT P1.7 ; write and enable pin of lcd

OUTPUT_LCD EQU P3 ; port3 is connected with data pins of

OUTPUT_ADC EQU P2 ; lcd

STR_PTR EQU 35H ; STR_PTR is a memory location

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

;................MAIN PROGRAM.......................

CLR EN_LCD ; make en=0

CALL SEND_STRING ; call subroutine

CALL SEND_HEX_TO_DEC

HERE: SJMP HERE


;**************************************************************************************
;.........ROUTINE FOR DISPLAYING STRING..............

SEND_STRING: CALL INIT_LCD

MOV OUTPUT_LCD,#01h ; clear lcd screen

CALL WR_LCD_COMMAND

CALL WAIT_LCD

MOV OUTPUT_LCD,#80H ; address for the first line of lcd

CALL WR_LCD_COMMAND ; call routines to initalize lcd

CALL WAIT_LCD ; call routine to check busy flag

MOV DPTR,#STRING ; move 16 bit string to data pointer

MOV STR_PTR,#0FFH ; make str_ptr an input

STRING_ROUTINE: INC STR_PTR

MOV A,STR_PTR

MOVC A,@A+DPTR ; move string to A

CJNE A,#'$',STRING_ROUTINE ; check the condition

JMP EXIT_LCD_MSG

DISP_AGN: MOV OUTPUT_LCD,A ; move data of A to lcd

SETB RS_LCD ; make rs=1

CLR RW_LCD ; make rw=0

SETB EN_LCD ; apply high to low pulse for writing data

CLR EN_LCD

CALL WAIT_LCD

JMP STRING_ROUTINE

EXIT_LCD_MSG:

RET

;**************************************************************************************
;..........ROUTINE TO CONVERT HEXADECIMAL NUMBER TO DECIMAL NUMBER...........



SEND_HEX_TO_DEC:CALL INIT_LCD

MOV OUTPUT_ADC,#0FFH ; make port2 an input port

MOV A,#1EH ;'1EH 'can be any number which we want to convert into

; decimal(10-100) for display on lcd



CJNE A,#01100100B,CONVERSION ; jump occurs if A is not equal to 100

MOV B,#10 ; move 10 in B

DIV AB ; process to convert hexadecimal number

MOV R7,B ; into decimal number by dividing by 10

MOV B,#10 ; store the result in registers

DIV AB

MOV R6,B

MOV R5,A

CALL DISPLAY

BACK:

RET



CONVERSION: MOV B,#10

DIV AB

ADD A,#30H

CALL WR_LCD_DATA ; call subroutine to send data to lcd

MOV A,B

ADD A,#30H ; subtract 30H from A to convert from ascii

CALL WR_LCD_DATA ; character

JMP BACK



DISPLAY: MOV A,R5 ; most significant digit

ADD A,#30H

CALL WR_LCD_DATA

mov A,R6

ADD A,#30H

CALL WR_LCD_DATA

mov A,R7 ; least significant digit

ADD A,#30H

CALL WR_LCD_DATA

RET



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



;...........ROUTINE FOR INITALIZATION OF LCD.............



INIT_LCD: MOV R0,#04H ; loop to initalize to lines of lcd

MOV OUTPUT_LCD,#38H ; by sending 38H

AGAIN: CALL WR_LCD_COMMAND

DJNZ R0,AGAIN

CALL WAIT_LCD

MOV OUTPUT_LCD,#0Eh ; display on,cursor on

CALL WR_LCD_COMMAND

CALL WAIT_LCD

RET

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

;.......... ROUTINE FOR SENDING COMMANDS TO LCD.............

WR_LCD_COMMAND: CLR RS_LCD ; commands are sent by making rs=0,

CLR RW_LCD ; rw=0, and high to low pulse on

SETB EN_LCD ; enable pin

CLR EN_LCD

RET

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

;..........ROUTINE FOR SENDING DATA TO LCD..................

WR_LCD_DATA: MOV OUTPUT_LCD,A

SETB RS_LCD ; commands are sent by making rs=1,

CLR RW_LCD ; rw=0, and high to low pulse on

SETB EN_LCD ; enable pin

CLR EN_LCD

CALL WAIT_LCD

RET

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

;..........ROUTINE FOR CHECKING BUSY FLAG OF LCD.............

WAIT_LCD: MOV OUTPUT_LCD,#0FFH ; make port 3 an input port

CLR EN_LCD

CLR RS_LCD

SETB RW_LCD

SETB EN_LCD

MOV A,OUTPUT_LCD

JB ACC.7,WAIT_LCD

CLR EN_LCD ; clear the enable for other commands

ret

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

;........... STRING TO BE DISPALYED ON LCD.....................
ORG 100H

STRING: DB 'TEMPERATURE=$' ; string end with a null character

; $ sign shows end of string

;*************************************************************************************
END ; end of program

Posted by Unknown on 08:52. Filed under , . You can follow any responses to this entry through the RSS 2.0. Feel free to leave a response

Labels

Recently Commented

Recently Added