| |
| Are you searching for "i want lcd16*2 interface with at89c51 please give me the circuit diagram and programming code????The program code for LCD initilisation & LCD interfacing with 89c52 microcontroller..how can i program lcd 8bit with at89s52 to display a 'LCD Programming' word ".....You will find it here.Now a days Electronics Projects without LCD look incomplete.Interfacing LCD with Atmel microcontroller is very easy task.You just have to know the proper lcd programming algorithm.Lcd used here has HD44780u dot matrix lcd controller.LCD module have 8-bit data interface and control pins.One can send data as 8-bit or in pair of two 4-bit nibbles. |
To display any character on LCD micro controller has to send its ASCII value to the data bus of LCD.For e.g. to display 'AB' microcontroller has to send two hex bytes 41h and 42h respectively.LCD display used here is having 16x2 size. It means 2 lines each with 16 character.
Circuit DiagramPin Information of LCD:
Algorithm to send data to LCD:1.Make R/W low 2.Make RS=0 ;if data byte is command RS=1 ;if data byte is data (ASCII value) 3.Place data byte on data register 4.Pulse E (HIGH to LOW) 5.Repeat the steps to send another data byte LCD Initialization:This is the pit fall for beginners.Proper working of LCD depend on the how the LCD is initialized. We have to send few command bytes to initialize the lcd. Simple steps to initialize the LCD 1.Specify function set: Send 38H for 8-bit,double line and 5x7 dot character format. 2.Display On-Off control: Send 0FH for display and blink cursor on. 3.Entry mode set: Send 06H for cursor in increment position and shift is invisible. 4. Clear display: Send 01H to clear display and return cursor to home position.
Addresses of cursor position for 16x2 HD44780 LCD
| line1 |
80H |
81H |
82H |
83H |
84H |
85H |
86H |
87H |
88H |
89H |
8AH |
8BH |
8CH |
8DH |
8EH |
8FH |
| line2 |
C0H |
C1H |
C2H |
C3H |
C4H |
C5H |
C6H |
C7H |
C8H |
C9H |
CAH |
CBH |
CCH |
CDH |
CEH |
CFH |
Assembly Language Code; Interfacing LCD 16x2 in 4-bit mode. ; Port0 to higher nibble data pins of LCD ; Crystal 3.579545 MHz ; AT89C51 ;P2.0 to RS pin ;P2.1 to Enable Pin
ORG 0000H AJMP MAIN ORG 0030H MAIN: MOV SP,#60H ;STACK POINTER ACALL LCD_INIT ;Initialize lcd MOV DPTR,#MESSAGE1 CALL LCD_STRING ;Display message on LCD CALL NEXT_LINE ;Place cursor to;second Line MOV DPTR,#MESSAGE2 CALL LCD_STRING ;Display message on LCD HERE: AJMP HERE
LCD_INIT: ;initialize LCD in 4-bit mode ANL P0,#0F0H CALL LOOP MOV DPTR,#LCDCODE MOV A,#0H MOV R6,#0H MOV R7,#0H CLR P2.0 ;RS COMMAND NEXT: ;8-bit code is split into two 4-bit nibbles. INC R6 MOVC A,@A+DPTR MOV R7,A ANL A,#0F0H SWAP A ANL P0,#0F0H ORL P0,A ACALL ENABLE ;PULSE E sending first nibble MOV A,R7 ANL A,#0FH ANL P0,#0F0H ORL P0,A ACALL ENABLE ;PULSE E sending second nibble MOV A,R6 CJNE R6,#09H,NEXT RET
LCD_STRING: MOV P0,#00H SETB P2.0 ;RS DATA MOV A,#00H MOV R6,#00H NC: ;checks the end of message string MOVC A,@A+DPTR CJNE A,#2FH,NC1 RET NC1: LCALL LCD_WRITE INC R6 MOV A,R6 AJMP NC
LCD_WRITE: SETB P2.0 ;RS DATA CALL LO RET
NEXT_LINE: MOV P0,#00H CLR P2.0 ;RS COMMAND MOV A,#0C0H CALL LO RET
LCD_CLEAR: ;This Subroutine is used to clear LCD CALL DELAYL ANL P0,#00H MOV A,#01H CLR P2.0 ; RS command LO: ;8-bit code is split into two 4-bit nibbles. MOV R7,A ANL A,#0F0H SWAP A ANL P0,#0F0H ORL P0,A CALL ENABLE MOV A,R7 ANL A,#0FH ANL P0,#0F0H ORL P0,A CALL ENABLE RET
ENABLE: ;Give High-to-low pulse at enable pin SETB P2.1 CALL DELAYL CLR P2.1 CALL DELAYL RET
;With respect to crystal frequency 3.579 MHz DELAYL: ; 5ms DELAY SETB PSW.4 ; SELECT BANK 2 MOV R7,#25 HDH: MOV R6,#60 DJNZ R6,$ DJNZ R7,HDH CLR PSW.4 ;DEFAULT BANK RET
LOOP: ;1 SEC DELAY MOV R7,#100 LOOP1: CALL DELAYL CALL DELAYL DJNZ R7,LOOP1 RET
;LCD INITIALIZING CODE (DO NOT DISTURB THIS)
LCDCODE: DB 02H DB 02H DB 02H DB 28H DB 28H DB 28H DB 0CH DB 06H DB 01H
;DATA TO BE DISPLAYED ;Maximum message length = 16 characters. ;To notify end of message place '/' at the end.
MESSAGE1: DB "LCD INTERFACING /" ;Change Message1
MESSAGE2: DB " IT IS EASY /" ;Change Message2
END
|