Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

LCD Interfacing with PIC Microcontroller

Task-1

write a program that will display ‘Institute of space technology’ on LCD.

Code:

;EQUATESECTION
TRISB EQU 86H
PORTB EQU 06H
TRISD EQU 88H
PORTD EQU 08H

COUNT1 EQU 22H


COUNT2 EQU 23H
;***************************************
;METACONFIG
LIST P=16F877A
ORG 0
GOTO START

__CONFIG H'3F72'
;***************************************
DELAY
MOVLW .255
MOVWF COUNT1
MOVLW .255
MOVWF COUNT2

A DECFSZ COUNT1,1
GOTO A
DECFSZ COUNT2,1
GOTO A
RETLW 0
;****************************************
;LCD SUBROUTINES
LCD_CMD ;COMMAND MODE
MOVWF PORTB
BCF PORTD,0 ;RS :Telling the RS pin of the LCD, that the
data being sent is a command(for configuration)
BSF PORTD,1; EN :As the data has to be taken as a command and for
that the EN(Enable bit) has to have transition from logic 1 to logic 0
NOP
BCF PORTD,1; Over here Postive to Negative Edge triggered
signal is given to the EN pin of the LCD
CALL DELAY ; Delay so that the LCD finishes its internal operations
RETLW 0
LCD_DIS ;DISPLAY MODE
MOVWF PORTB
BSF PORTD,0 ;RS: Telling the RS pin of the LCD, that the
data being sent is a Data(for display)
BSF PORTD,1 ;EN: As the data has to be taken as a
command and for that the EN(Enable bit) has to have transition from logic 1 to logic 0
NOP
BCF PORTD,1 ;Over here Postive to Negative Edge triggered
signal is given to the EN pin of the LCD
CALL DELAY ;Delay so that the LCD finishes its internal operations
RETLW 0
LCD_INT
MOVLW 38H ;This code i.e. 0011 1000 selects (8 bit
interface) + (2 line mode) + (5x7 dot format)
CALL LCD_CMD

MOVLW 0EH ;This code i.e. 0000 1110 selects


(Display on) + (Cursor Underline on) + (Cursor Blink off)
CALL LCD_CMD

MOVLW 06H ;This code i.e. 0000 0110 selects


(Inrement Cursor) + (Display Shift off)
CALL LCD_CMD

CALL DELAY
RETLW 0
LCD_CLR
MOVLW 01H ;This code i.e. 0000 0001 selects Clear
Display
CALL LCD_CMD
CALL DELAY
RETLW 0
;****************************************
;CONFIG
START
BANKSEL TRISD
CLRF TRISD
CLRF TRISB
BANKSEL PORTD
CLRF PORTD
CLRF PORTB
;*****************************************
;PROGRAM
BEGIN
CALL LCD_INT
CALL LCD_CLR

MOVLW 80H ;This code 80H i.e. the address of the


first bit of the first line of the 2x16 LCD from where it has to start
CALL LCD_CMD

MOVLW 'I'
CALL LCD_DIS
MOVLW 'N'
CALL LCD_DIS
MOVLW 'S'
CALL LCD_DIS
MOVLW 'T'
CALL LCD_DIS
MOVLW 'I'
CALL LCD_DIS
MOVLW 'T'
CALL LCD_DIS
MOVLW 'U'
CALL LCD_DIS
MOVLW 'T'
CALL LCD_DIS
MOVLW 'E'
CALL LCD_DIS
MOVLW ''
CALL LCD_DIS
MOVLW 'O'
CALL LCD_DIS
MOVLW 'F'
CALL LCD_DIS
MOVLW ''
CALL LCD_DIS
MOVLW 'S'
CALL LCD_DIS
MOVLW 'P'
CALL LCD_DIS
MOVLW 'A'
CALL LCD_DIS

MOVLW 0C0H ;This code OC0H i.e. the address of the


first bit of the second line of the 2x16 LCD from where it has to start
CALL LCD_CMD

MOVLW 'C'
CALL LCD_DIS
MOVLW 'E'
CALL LCD_DIS
MOVLW ''
CALL LCD_DIS
MOVLW 'T'
CALL LCD_DIS
MOVLW 'E'
CALL LCD_DIS
MOVLW 'C'
CALL LCD_DIS
MOVLW 'H'
CALL LCD_DIS
MOVLW 'N'
CALL LCD_DIS
MOVLW 'O'
CALL LCD_DIS
MOVLW 'L'
CALL LCD_DIS
MOVLW 'O'
CALL LCD_DIS
MOVLW 'G'
CALL LCD_DIS
MOVLW 'Y'
CALL LCD_DIS
GOTO BEGIN
END
Task-2

Write an assembly language code to show a character on LCD in 4_bit mode.

Code:

PORTB EQU 06H


PORTD EQU 08H

TRISB EQU 86H


TRISD EQU 88H

count1 EQU 20H


count2 EQU 21H

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

LIST P=16F877A
ORG 0
GOTO START

__CONFIG H'3F72'
;DELAYS

DELAY movlw .255


movwf count1
movlw .255
movwf count2

a decfsz count1,1
goto a

decfsz count2,1
goto a

RETLW 0

;LCD SUBROUTINES

LCD_CMD
MOVWF PORTB
BCF PORTD,0 ;RS
BSF PORTD,1 ;EN
NOP
BCF PORTD,1
CALL DELAY
RETLW 0

LCD_DATA
MOVWF PORTB
BSF PORTD,0 ;RS
BSF PORTD,1 ;EN
NOP
BCF PORTD,1
CALL DELAY
RETLW 0
LCD_CLR
MOVLW 0H
CALL LCD_CMD

MOVLW 1H
CALL LCD_CMD
CALL DELAY
RETLW 0

LCD_INT

MOVLW 3H
CALL LCD_CMD

MOVLW 2H
CALL LCD_CMD

MOVLW 2H
CALL LCD_CMD

MOVLW 8H
CALL LCD_CMD

MOVLW 0H
CALL LCD_CMD

MOVLW 6H
CALL LCD_CMD

MOVLW 0H
CALL LCD_CMD

MOVLW 0EH
CALL LCD_CMD

CALL DELAY
RETLW 0
;CONFIG SECTION

START
BANKSEL TRISD

MOVLW B'00000000'
MOVWF TRISD
MOVWF TRISB
BANKSEL PORTD

CLRF PORTB
CLRF PORTD
;PROGRAM STARTS NOW
CALL LCD_INT
BEGIN CALL LCD_CLR

MOVLW 8H
CALL LCD_CMD

MOVLW 0H
CALL LCD_CMD

MOVLW 4H
CALL LCD_DATA

MOVLW 1H
CALL LCD_DATA

MOVLW 4H
CALL LCD_DATA

MOVLW 0CH
CALL LCD_DATA

MOVLW 4H
CALL LCD_DATA

MOVLW 0CH
CALL LCD_DATA

MOVLW 4H
CALL LCD_DATA

MOVLW 1H
CALL LCD_DATA

MOVLW 4H
CALL LCD_DATA

MOVLW 8H
CALL LCD_DATA

CALL DELAY
GOTO BEGIN

END

You might also like