debabrta kar
Member level 5
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?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
LCD_NIBBLE: ; MOV R2,A ; SAVING CONTENTS OF ACCUMULATOR
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;
}
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