Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

2*16 lcd dispaly in 4 bit mode using at89s51

Status
Not open for further replies.

debabrta kar

Member level 5
Member level 5
Joined
May 20, 2013
Messages
86
Helped
7
Reputation
16
Reaction score
5
Trophy points
1,288
Location
india
Activity points
1,858
hi m trying to display on lcd in 4 bit mode m interfacing with at89s51... m using P2.4,P2.5,P2.6,P2.7..as data line to lcd...but every time m getting output as 0000...what to do here?
 

ORG 00H
SJMP MAIN
ORG 30H

MAIN: MOV P3,#0FFH
MOV P2,#00H
ACALL DELAY_30MS ; DELAY OF MORE THAN 30 MS AFTER POWER ON THE LCD
ACALL DELAY_30MS
ACALL DELAY_30MS
ACALL DELAY_30MS

ACALL LCD_INTI

CLR P3.0

MOV A,#80H
ACALL LCD_CMD
ACALL DELAY

CLR P3.1

MOV A,#38H
ACALL LCD_CMD
ACALL DELAY

CLR P3.2

MOV A,#0EH
ACALL LCD_CMD
ACALL DELAY

MOV A,#01H
ACALL LCD_CMD
ACALL DELAY

CLR P3.3

MOV A,#'A'
ACALL LCD_DATA
ACALL DELAY

MOV A,#'B'
ACALL LCD_DATA
ACALL DELAY

MOV A,#'C'
ACALL LCD_DATA
ACALL DELAY

MOV A,#'D'
ACALL LCD_DATA
ACALL DELAY

CLR P3.4

STAY: SJMP STAY

;=======================================================================================================

LCD_INTI: ; ACALL DELAY_30MS ; DELAY OF MORE THAN 30 MS AFTER POWER ON THE LCD
; ACALL DELAY_30MS
; ACALL DELAY_30MS
; ACALL DELAY_30MS



; INTIALIZE THE LINE
CLR P0.0 ; MAKE THE ENABLE PIN LOW
CLR P0.2 ; MAKE THE R/W PIN LOW
CLR P0.1 ; MAKE THE RS PIN LOW

MOV P2,#0FFH
SETB P0.0
CLR P0.0



MOV A,#30H ; TO SET ON 4 BIT MODE ONLY FUNCTION SET-2 TO BE SENT
ACALL LCD_CMD ; ONLY THE HIGHER NIBBLE -2 TO BE SENT
; ACALL DELAY_30MS
ACALL DELAY_1MS
ACALL DELAY_1MS
/* CLR P0.1
CLR P0.2
MOV A,#20H ; TO SET 4-BIT MODE, 2 LINE, 5*7 MATRIX
ACALL LCD_NIBBLE ; FUNCTION SET-2 TO THEN 8 TO BE SEND


CLR P0.1
CLR P0.2
MOV A,#20H ; TO SET 4-BIT MODE, 2 LINE, 5*7 MATRIX
ACALL LCD_NIBBLE ; FUNCTION SET-2 TO THEN 8 TO BE SEND */



CLR P0.1
CLR P0.2
MOV A,#30H ; TO SET 4-BIT MODE, 2 LINE , 5*7 MATRIX
ACALL LCD_CMD ; FUNCTION SET-2 THEN 8 TO BE SEND
; ACALL DELAY_30MS
; ACALL DELAY_1MS
ACALL DELAY_1MS
ACALL DELAY_1MS
CLR P0.1
CLR P0.2
MOV A,#30H ; TO SET 4-BIT MODE, 2 LINE , 5*7 MATRIX
ACALL LCD_CMD ; FUNCTION SET-2 THEN 8 TO BE SEND
; ACALL DELAY_30MS
; ACALL DELAY_1MS

ACALL DELAY_1MS
ACALL DELAY_1MS

CLR P0.1
CLR P0.2
MOV A,#20H ; TO SET 4-BIT MODE, 2 LINE , 5*7 MATRIX
ACALL LCD_CMD ; FUNCTION SET-2 THEN 8 TO BE SEND
; ACALL DELAY_30MS
; ACALL DELAY_1MS
ACALL DELAY_1MS
ACALL DELAY_1MS

CLR P0.1
CLR P0.2
MOV A,#28H ; TO SET 4-BIT MODE, 2 LINE , 5*7 MATRIX
ACALL LCD_CMD ; FUNCTION SET-2 THEN 8 TO BE SEND
ACALL DELAY_30MS
ACALL DELAY_30MS

CLR P3.6

/* CLR P0.1
CLR P0.2
MOV A,#28H ; TO SET 4-BIT MODE, 2 LINE , 5*7 MATRIX
ACALL LCD_CMD ; FUNCTION SET-2 THEN 8 TO BE SEND
ACALL DELAY_30MS */










MOV A,#0CH ; TO SET DISPLAY-ON,CRUSHER-OFF,BLINK-OFF
ACALL LCD_CMD ; FUNCTION SET - 0 THEN C TO BE SENT
ACALL DELAY_39us

MOV A,#06H ; TO SET CLEAR DISPLAY
ACALL LCD_CMD ; FUNCTION SET - 0 THEN 1 TO BE SENT
ACALL DELAY_1MS

MOV A,#01H ; INCREAMENT CRUSHER AFTER EACH BYTE(1 CHAR) IS WRITTEN
ACALL LCD_CMD ; FUNCTION SET - 0 THEN 6 TO BE SENT
ACALL DELAY_1MS

CLR P3.7

/* CLR P0.1
CLR P0.2
MOV A,#80H ; TO SET 2-LINE, DISPLAY-OFF
ACALL LCD_CMD ; FUNCTION SET - 8 TO BE SEND
ACALL DELAY_39us
*/


RET
; LCD INTIALIZATION ENDS
;===============================================================================

LCD_CMD: MOV R2,A
CLR P0.0
CLR P0.2
CLR P0.1
ACALL LCD_NIBBLE

CLR P0.0
CLR P0.2
CLR P0.1
MOV A,R2
SWAP A
ACALL LCD_NIBBLE
RET

;===============================================================================

LCD_DATA: MOV R2,A
CLR P0.0
SETB P0.1
CLR P0.2
ACALL LCD_NIBBLE


MOV P2,A
CLR P0.0
SETB P0.1
CLR P0.2
MOV A,R2
SWAP A
ACALL LCD_NIBBLE
RET


;=================================================================================================

LCD_NIBBLE: ; MOV R2,A ; SAVING CONTENTS OF ACCUMULATOR
SWAP A ; SWAP TO GET HIGHER NIBBLES
ANL A,#0FH ; MASKING OF HIGHER NIBBLES IS DONE
SWAP A
MOV P2,A ; SEND THE HIGHER NIBBLES TO PROT P2 THAT IS TO LCD
SETB P0.0
CLR P0.0
RET


;----------------------------------------------------------------------
; LCD delay routine of 39us (assuming 11.0592MHz )
;----------------------------------------------------------------------

DELAY_39us: MOV R4,#17
HERE: DJNZ R4,HERE
RET

;----------------------------------------------------------------------
; LCD delay routine of more than 1.57ms
;----------------------------------------------------------------------
DELAY_1MS:
MOV R3,#30
HERE2: MOV R4,#25
HERE1: DJNZ R4,HERE1
DJNZ R3,HERE2
RET


;----------------------------------------------------------------------
; LCD delay routine of more than 30ms
;----------------------------------------------------------------------

DELAY_30MS:
MOV R3,#200
HERE4: MOV R4,#75
HERE3: DJNZ R4,HERE3
DJNZ R3,HERE4
RET

;----------------------------------------------------------------------------
; LCD GENERAL DELAY ROUTINE
;----------------------------------------------------------------------------


DELAY: MOV R4,#220
HERE111: MOV R3,#220
here22: DJNZ R3,here22
DJNZ R4,HERE111
RET


END
 

port 3 pins used just for led indication ...it has no effect on my code ....
 

-> Firstly, the initial part of the code where you are setting up the LCD for displaying is not in proper order.
The first command sent should be 0x01, 0x02,0x06,0x0E,0x28 (4-bit mode) and the finally 0x80(First line)

-> The 4-bit mode of JHD162A LCD is set using the command 0x28

Check this and reply if the problem persists.
 
  • Like
Reactions: debabrta kar

    V

    Points: 2
    Helpful Answer Positive Rating

    debabrta kar

    Points: 2
    Helpful Answer Positive Rating
hello

Code:
LCD_NIBBLE:	 ;	MOV	 R2,A	 ; SAVING CONTENTS OF ACCUMULATOR
i don't know this microcontroler but
it seems that Mov R2,A is like a comment !
because ";" in front of instruction ?
 
  • Like
Reactions: debabrta kar

    V

    Points: 2
    Helpful Answer Positive Rating

    debabrta kar

    Points: 2
    Helpful Answer Positive Rating
yes its a comment i think no need to excute that ...i also tried to execute that line but result is coming as same 0000....

- - - Updated - - -

an how much delay i will give after each command...n and why to send 0*02 what it means for....plz tell.....
 

ya i think its wrong thats why m not getting the output...plz guide me how to initialize in 4 bit mode....
 

hello


try to compare this LCD init sequence with yours (even written iC , you can compare)

Code:
void LCD_Init(void)
{

//PORT initialization
//4bit mode
//Upper 4-bits of the DATAPORT as output
LCD_DATAPORT_TRIS  &= 0x0f;
LCD_DATAPORT &= 0x0f;
LCD_Delay15ms();
//control port initialization
LCD_RSPIN_TRIS =0;                         //make control ports output
LCD_ENPIN_TRIS =0;
LCD_RSPIN  =0;                             //clear control ports
LCD_ENPIN  =0;

//initialization by instruction
//  envoi 3 fois de suite 0x30 (03 sur le quarter MSB du PORTB)
LCD_Delay15ms();
// Upper nibble interface
LCD_DATAPORT   =LCD_DATAPORT & 0x0f;        // 1ere init
LCD_DATAPORT   =LCD_DATAPORT| 0b00110000;	 // 0x30
Pulse_E() ;
LCD_Delay15ms();


// Upper nibble interface
LCD_DATAPORT   &= 0x0f;        // 2em ini
LCD_DATAPORT   |= 0b00110000;
Pulse_E() ;
LCD_Delay15ms();


// Upper nibble interface
LCD_DATAPORT   &= 0x0f;        // 3em init
LCD_DATAPORT   |= 0b00110000;
LCD_Delay();
Pulse_E() ;
LCD_Delay4ms();


//Force le mode 4 Bits    0x02H sur quartet MSB du PortB
//Function SET Commande 0 0 1 DL N F X X  avec RS=0 RW=0
// Upper nibble interface
LCD_DATAPORT   &= 0x0f;        // Clear upper port
LCD_Delay();
LCD_DATAPORT   |= 0b00100000;
LCD_Delay();
Pulse_E() ;

//Function SET Commande 0 0 1 DL N F X X  avec RS=0 RW=0
//Definit la taille de l'interface (DL=0 pour mode 4 bits, DL=1 pour mode 8 bits),
// le nombre de lignes (NL=0 pour 1 ligne, N=1 pour 2 ou 4 lignes),
// et la taille des fontes (F=0 pour des cars 5x7, F=1 pour des cars 5x10).
LCD_Cde(0b00101000);    // 0x28     2Line 5x8

//Display on/off control  0 0 0 0 1 D C B
// affichage (D), curseur (C), clignotement du curseur (B).
LCD_Cde(0b00001000);    //display off
LCD_Cde(0b00000001);    //display clear  was 0b00000001); 

//Entry mode setting
//Entry mode command " 0 0 0 0 0 1 ID S "
//ID =0 no cursor increment during read and write
//ID =1 cursor increment during read and write
//S =0 no display during read and write
//S =1 display shift

 LCD_Cde(0b00000110);    //0x06 if cursor inc and no display shift

//Display on off ,Blink ,cursor command set
//"0 0 0 0 1 D C B "
//D=1 dislay on, C=1 cursor off, B=1 blink off
LCD_Cde(0b00001100);    //0x0F 0b00001111 =display ON, cursor on, blink ON
LCD_Delay();

// end of initialization
  return;
}
 
please,give me the exact commands that i will send to lcd for initialization purpose and with accurate delay
 

hello

You allready have the Data value to send to initialise the LCD, inside the previous code (in C langage)
Even in C langage, data value is the same to send as in ASM51 ..

Another example in PIC ASM , sorry i don't know ASM51 !
you can easily see what code to send at each step of initialisation !

I hope also, that the code of data value you send is not overwrite by other register !

and for Delay :
you have to calculate how many loop of instructions to do to elaps the needed time.
Delay Example in PIC ASM gives an idea for how to do it...
just adapt the code to your microcontroleur..

you can write a special subroutine to check time calibration
ex: delay1500 -> 15mS
do 200 loops -> 3 secondes put a led On
do 200 loops -> 3 secondes put this led Off
do 200 loops -> 3 secondes put this led On
and use a chronometer to check



Code:
LCD_DATA        	EQU     PORTB
LCD_DATA_TRIS    	EQU     TRISB
LCD_CNTL         	EQU    PORTA
LCD_CNTL_TRIS	EQU	 TRISA
; LCD Display Commands and Control Signal names.
E       			EQU     3       ; LCD Enable control line
R_W     		EQU     1       ; LCD Read/Write control line
RS     			 EQU     2       ; LCD Register Select control line
;

; Initilize the LCD Display Module
;
LCD_Init:

	bcf     LCD_CNTL, E     ; Clear all controll lines
	bcf     LCD_CNTL, RS
	bcf     LCD_CNTL, R_W

	call    Delay15000      ; Wait for 15ms for LCD to get powered up

	movlw   [B]0x0f[/B]
	andwf   LCD_DATA,F      ; Clear the upper nibble
	movlw  [B] 0x030 [/B]          ; Command for 4-bit interface high nibble
	iorwf   LCD_DATA,F      ; Send data to LCD      

	bsf     STATUS, RP0     ; Select Register page 1
	movlw   [B]0x0F[/B]
	andwf   LCD_DATA_TRIS,W
	movwf   LCD_DATA_TRIS   ; Set Port for output
	BCF     STATUS, RP0     ; Select Register page 0

	bsf     LCD_CNTL, E     ; Clock the initalize command to LCD module
	bcf     LCD_CNTL, E

	call    Delay4100       ; Delay for at least 4.1ms before continuing

	bsf     LCD_CNTL, E     ; Clock the initalize command to LCD module
	bcf     LCD_CNTL, E
	
	 
	call    Delay100        ; delay for at least 100usec before continuing

	bsf     LCD_CNTL, E     ; Clock the initalize command to LCD module
	bcf     LCD_CNTL, E


	movlw   [B]0x0f[/B]
	andwf   LCD_DATA,F      ; Clear the upper nibble
	movlw  [B] 0x020[/B]           ; Command for 4-bit interface high nibble (Really an 8bit command but
				;   lower 4 bits are don't care at this point)
	iorwf   LCD_DATA,F      ; Send data to LCD      

	bsf     LCD_CNTL, E     ; Clock the initalize command to LCD module
	bcf     LCD_CNTL, E

	movlw  [B] 0x28[/B]		; FUNCTION_SET     Send the function set command 4-bit I/F, Font, Number of lines
	call    Send_Cmd        ; Can now use the Send_Cmd routine since Busy Bit Valid and in 4bit mode.
	movlw  [B] 0x008[/B]  	 ; Display off
	call    Send_Cmd
	movlw [B] 0x0E  [/B] 	; Display on, Cursor on
	call    Send_Cmd
	movlw [B] 0x06 [/B] 	 ;   ENTRY_INC
	call    Send_Cmd
	return

;
; Delay routines.  These routines need to be modified to work with the particular PIC configuration
; used.  For test purposes, they are instruction count delays based on 4Mhz PIC.  The delays are a 
; little longer than advertised but close enough for testing.
;

Delay4100:
	movlw   d'252'
	movwf   r1
	movlw   4
	movwf   r2
	movlw   1
	movwf   r3
	movlw   1
	movwf   r4
 
delay_loop:
	nop             
	decfsz  r1,f
	goto    delay_loop
	decfsz  r2,f
	goto    delay_loop
	decfsz  r3,f
	goto    delay_loop
	decfsz  r4,f
	goto    delay_loop
	return

Delay100:
	movlw   d'22'
	movwf   r1
	movlw   1
	movwf   r2
	movlw   1
	movwf   r3
	movlw   1
	movwf   r4 
	goto    delay_loop

Delay15000:
	movlw   d'156'
	movwf   r1
	movlw   15
	movwf   r2
	movlw   1
	movwf   r3
	movlw   1
	movwf   r4 
	goto    delay_loop
	
	end
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top