• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

lcd using pic18f452

Status
Not open for further replies.

einton

New Member
Hi everyone

i have started pic hardware two weeks ago , before it i gone through much of it programming in assembly , since three days i m working on interfacing 14 pin lcd with ribbon connection , i m using sipmle program which is downloaded well into ic and progrm is burnt well ,with proper setting of configuration bits , when i interface the lcd it just giving some bullets which shows lcd is fine i m sending u my code and hope 4 ur reply since i m finding no way at there. thanx



LIST p=18F452 , F=INHX32, MM=OFF, N=0, ST=OFF , R=HEX
#Include P18F452.INC
CONFIG OSC=HS , OSCS=OFF
CONFIG WDT=OFF
CONFIG BORV=45, PWRT=ON, BOR=ON
CONFIG DEBUG=OFF, LVP=OFF, STVR=OFF
ORG 00h
LCD_DATA EQU PORTB
LCD_CTRL EQU PORTD
R2 EQU 0*2
R3 EQU 0*3
MYREG EQU 0*4
MTREG EQU 0*5
RS EQU RD0
RW EQU RD1
EN EQU RD2
CLRF TRISD
CLRF TRISB
BCF LCD_CTRL,EN
CALL LDELAY
MOVLW 0*38
CALL COMNWRT
CALL DELAY
MOVLW 0*0E
CALL COMNWRT
CALL DELAY
MOVLW 0*01
CALL COMNWRT
CALL DELAY
MOVLW 0*06
CALL COMNWRT
CALL DELAY
MOVLW 0*84
CALL COMNWRT
CALL DELAY
MOVLW A'P'
CALL DATAWRT
CALL DELAY
MOVLW A'A'
CALL DATAWRT
AGA BTG LCD_CTRL,0
BRA AGA
COMNWRT
MOVWF LCD_DATA
BCF LCD_CTRL,RS
BCF LCD_CTRL,RW
BCF LCD_CTRL,EN
CALL DELAY
BCF LCD_CTRL,EN
RETURN
DATAWRT
MOVWF LCD_DATA
BSF LCD_CTRL,RS
BSF LCD_CTRL,RW
BSF LCD_CTRL,EN
CALL SDELAY
BCF LCD_CTRL,EN
RETURN
SDELAY
MOVLW 0FF
MOVWF MYREG
ADAIN NOP
NOP
DECF MYREG,F
BNZ ADAIN
RETURN
LDELAY
MOVLW D'200'
MOVWF R2
AJAIN MOVLW D'250'
MOVWF R3
HERE NOP
NOP
DECF R3,F
BNZ HERE
DECF R2,F
BNZ AJAIN
RETURN
DELAY
MOVLW D'200'
MOVWF MTREG
AHAIN
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
DECF MTREG,F
BNZ AHAIN
RETURN
END
 

Attachments

silvarblade

Member
What is your oscillator frequency? An LCD requires a delay of about 5 to 10 ms for every command and a little more for data.What i do is use a longer delay and use one delay loop for all.
 

Pommie

Well-Known Member
Most Helpful Member
You have a couple of errors in your data and command write routines,

Code:
COMNWRT			 
		movwf	LCD_DATA 
		bcf	LCD_CTRL,RS
		bcf	LCD_CTRL,RW
		b[COLOR="Red"]s[/COLOR]f	LCD_CTRL,EN	;was bcf
		call	DELAY
		bcf	LCD_CTRL,EN
		return
DATAWRT
		movwf	LCD_DATA
		bsf	LCD_CTRL,RS
		b[COLOR="red"]c[/COLOR]f	LCD_CTRL,RW	;was bsf
		bsf	LCD_CTRL,EN
		call	SDELAY
		bcf	LCD_CTRL,EN
		return
Mike.
 

einton

New Member
thanx pommie
I did what u pointed , but still the things are not working at all , interestingly i m also gettting no any display when i m trying to simulate it on proteas , im using 10 Mhz crystal, i have also used it using single delay of 25 msec but it is also not working . i got blank this time , i think i have used correct config setting .
 
Last edited:

Pommie

Well-Known Member
Most Helpful Member
You should try and find some working code that you can test your hardware with. If you post a schematic then people may be able to provide working code.

Mike.
 

Chippie

Member
It may be the contrast pin is not at the correct voltage, hence the blank screen...

As suggested load some working code to test your hardware..
 

Wond3rboy

Member
Hi, here is the code, the problem is that the delay is very small due to you using HS mode of the 18F452. Another problem is that you used PORTx for output when you should be using LATx registers.Here is the code and the attached simulation in Proteus.

Code:
LIST p=18F452;This ones for a 10MHz crystal.When you start        ;proteusD.C on the device and change the crystal to 10Mhz.
#Include P18F452.INC
CONFIG OSC=HS , OSCS=OFF
CONFIG WDT=OFF, LVP=OFF
ORG 00h
MOVLW 07
MOVWF T0CON
LCD_DATA EQU LATB
LCD_CTRL EQU LATD
RS EQU RD0
RW EQU RD1
EN EQU RD2
CLRF TRISD
CLRF TRISB
BCF LCD_CTRL,EN 
CALL DELAY 
MOVLW 0X38
CALL COMNWRT
CALL DELAY 
MOVLW 0X0E
CALL COMNWRT
CALL DELAY 
MOVLW 0X01
CALL COMNWRT
CALL DELAY 
MOVLW 0X06
CALL COMNWRT
CALL DELAY 
MOVLW 0X84
CALL COMNWRT
CALL DELAY 
MOVLW A'P'
CALL DATAWRT
CALL DELAY 
MOVLW A'A'
CALL DATAWRT
AGA BTG LCD_CTRL,3
BRA AGA


COMNWRT			 
		movwf	LCD_DATA 
		bcf	LCD_CTRL,RS
		bcf	LCD_CTRL,RW
		bsf	LCD_CTRL,EN	;was bcf
		call	DELAY
		bcf	LCD_CTRL,EN
		return
DATAWRT
		movwf	LCD_DATA
		bsf	LCD_CTRL,RS
		bcf	LCD_CTRL,RW	;was bsf
		bsf	LCD_CTRL,EN
		call	DELAY
		bcf	LCD_CTRL,EN
		return

DELAY:
MOVLW 4
MOVWF 0X20

AGAIN:

MOVLW 0FF
MOVWF TMR0H
MOVWF TMR0L
BCF INTCON,TMR0IF
BSF T0CON,TMR0ON

DELAY1:

BTFSS INTCON,TMR0IF
BRA DELAY1
BCF T0CON,TMR0ON
DECFSZ 0X20
BRA AGAIN
RETURN
END
 

Attachments

Last edited:
Status
Not open for further replies.

EE World Online Articles

Loading
Top