Continue to Site

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.

  • 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.

Initialize LCD

Status
Not open for further replies.

SneaKSz

Member
I'm having a hard time with initialising my ST7066U .It doesn't even light up.

I've checked al the connections , Vss and Vdd are also connected.

Code:
;******************************************************************************
 ;                             
 ;******************************************************************************
 ;                                                                             *
 ;    Filename: LCD                                                            *
 ;    Date: 15/08/10                                                                   *
 ;    File Version:                                                            *
 ;                                                                             *
 ;    Author: CJ                                                              *
 ;    Company:                                                                 *
 ;                                                                             * 
 ;******************************************************************************
 ;                                                                             *
 ;    Files required: P18F14K50.INC     //1330.INC                                             *
 ;                                                                             *
 ;******************************************************************************
     LIST P=18F14K50, F=INHX32 ;directive to define processor and file format
     #include <P18F14K50.INC>     ;processor specific variable definitions
 
 ;******************************************************************************

 CONFIG    CPUDIV = NOCLKDIV; 
 CONFIG    USBDIV = OFF ; 
 CONFIG    FOSC = HS; 
 CONFIG    PLLEN = OFF; 
 CONFIG    FCMEN = OFF; 
 CONFIG    IESO = OFF; 
 CONFIG    PWRTEN = ON; 
 CONFIG    BOREN = ON; 
 CONFIG    BORV = 30; 
 CONFIG    WDTEN = OFF; 
 CONFIG    WDTPS = 1; 
 CONFIG    MCLRE = ON; 
 CONFIG    HFOFST = ON; 
 CONFIG    STVREN = ON; 
 CONFIG    LVP = OFF; 
 CONFIG    BBSIZ = OFF; 
 CONFIG    XINST = OFF; 
 CONFIG    CP0 = ON; 
 CONFIG    CPB = ON; 
 CONFIG    CPD = ON; 
 CONFIG    WRT1= ON; 
 CONFIG    WRTB = ON; 
 CONFIG    WRTC = ON; 
 CONFIG    WRTD = ON; 
 CONFIG    EBTRB = ON; 
 
 
 
 ;------------------------------------------------------------------------------
 ; MAIN PROGRAM
 ;------------------------------------------------------------------------------
;1	  2	   3	4	5	6	 7	10   11	  14	15	16
;VSS  VDD  VO	RS	R/W	E   DB0-DB3  DB4 -DB7    NC	NC
;               RB7 GND RB6 RC0-RC3  RC4-RC7  


	cblock  0x20  
	r1 			; delay
	r2 			
	r3 		
	delay2	; amount of delay
	endc 


; R/W\ ==> GND write always 

#define  EN   PORTB,6
#define  RS   PORTB,7
#define  DB0  PORTC,0
#define  DB1  PORTC,1
#define  DB2  PORTC,2
#define  DB3  PORTC,3
#define  DB4  PORTC,4
#define  DB5  PORTC,5
#define  DB6  PORTC,6
#define  DB7  PORTC,7



          ORG	0x00	
		  call init 
start     call initlcd
		
 
init 	clrf TRISC 
        clrf PORTC 
	    bcf ADCON0,ADON ; disable ana input
 		MOVLW 0F0h
		movwf TRISB
		clrf PORTB
		clrf r1
		clrf r2
		clrf r3
		clrf delay2
		clrf WPUB ; disable weak pull-up
		

		return
 		      
initlcd  ; wait 15ms to start the LCD
		movlw 0x96 ;( 150 dec) 150*100µs=15ms
		movwf delay2
		call delay
		bcf RS ; RS low
		bcf EN ; EN low	
	;=================Set Function==================

; DL = interface 8 bits  , NL = 2 , F = 5*11		


		MOVLW 38h 
		movwf PORTC
		call enwait ; 1,5 ms wachten

	; wait 15ms to start the next instruction 
		movlw 0x96 ;( 150 dec) 150*100µs=15ms
		movwf delay2
		call delay
	;==========================shift=======================
	
	;	 14h   cursor move, shift right

		movlw 14h
		movwf PORTC
		call enwait

	;===========Display On/Off control======================

		;MOVLW 0Fh           ;display ON, cursor ON, cursor flash
		; MOVLW 0Ch		     ; display ON, cursor OFF, cursor flash

		movlw 0x0f
		movwf PORTC 
		call enwait

;Clear display	

	;	bcf RS ; RS low
	;	bcf RW ; R/W low

	;	MOVLW 0x96 ; Clear commando
	;	movwf PORTC
	;	call enwait		

; return home 
		MOVLW 0x02
		movf  PORTC
		call enwait		


		call figure
		return

figure	bsf RS
		MOVLW 40h
		movwf PORTC
		call enwait
		goto figure
		return

enwait
		bsf  EN ; EN high
		movlw 0x0f ; wait 1,5 ms  
		movwf delay2
		call delay
		bcf  EN ; EN low
		return

delay   movlw   0x0A  ; delay2*10²*3*333ns=100µs*delay= delay2*100µs
	    movwf	r1			
D3		movlw	0x0A
		movwf	r2			
D4		movff   delay2,r3
D5		decfsz   r3,f ; 333ns	        		             
		goto	 D5   ; 666ns
		decfsz   r2,f	        		          
		goto	 D4				 
		decfsz   r1,f				
		goto	 D3	
		return		     
 ;******************************************************************************
 ;End of program
 
         END


So i first use the function set ,then the cursor / display shift and finally turn the display on and clear it. But nothing happens , very strange :s.

Datasheet LCD : https://www.electro-tech-online.com/custompdfs/2010/08/40247.pdf

Could someone please look at the code and hopefully tell me what I do wrong?

Maybe the initialisation progress?

Thanks
 
Last edited:
im not too clued up on this code, but i notice a couple of things,

it appears your using 8bit connections and also you have r/w connected.

in my experience these arent required, 4 bit works fine and r/w is disconnected.

also if the backlight isnt coming on straight away it would indicate a power problem

do you have a schematic you could post??
 
I've updated the code .

r/w is grouned now and the backlight isn't connected, I think that isnt needed . Vss , Vdd and Vo are of course connected .

**broken link removed**

Greetings
 
Last edited:
hi SneaK,
On the LCD, what is connected to pin #3 [VO], it should be a 'contrast' voltage'.
Connect a 10K pot across +V and 0V with the wiper of the pot connected to pin#3, by varying the pot you should see the 'pixel' blocks.
 
Hello Eric,

Thats exactly what I've done , a 10k pot between Vdd and Vss en connected it to Vo ( contrast input ) .

I also changed the resistance of the pot , but no succes .
 
when you turn the contrast up fully do you get anything on screen. you should have a row of blocks on the top row even if the screen isnt initialised.
 
Thats for the tip corbra . I get nothing :s . Not even a blink when turning on. Checked Vdd en Vss connection.

It's a new LCD , just ordered it online . I'll check the connections again.

Thanks !
 
when making your connections, which way up do you have the screen, if i remember correctly the screen needs to be face down to get the pins in the right order, if you ake the connections with the screen face up everything is backwards.
 
Well on the bottom of the print , you have marked 1 ,2 and 14, 16 . I've soldered it by looking at those numbers. I think it's connected correct.

**broken link removed**
**broken link removed**

Thanks !
 
Last edited:
Hello Eric,

Thats exactly what I've done , a 10k pot between Vdd and Vss en connected it to Vo ( contrast input ) .

I also changed the resistance of the pot , but no succes .

Hi,
Your LCD d/s says a neg V to the bottom of the contrast pot, not 0V

You should see the pixel blocks.???
 

Attachments

  • AAesp01.gif
    AAesp01.gif
    6.8 KB · Views: 222
hi Sneak.
Your code sticks in this loop.!!!
Code:
[B]figure[/B]        bsf RS
        MOVLW 40h
        movwf PORTC
   [B]     call enwait ;  calls enwait
        goto figure; keep doing it for ever!!![/B]
        return
enwait
        bsf  EN ; EN high
        movlw 0x0f ; wait 1,5 ms  
        movwf delay2
        call delay
        nop
        nop
        bcf  EN ; EN low
        return
 
Hello Eric ,

I only have a +5V here. Hmm I'm going to look if I can make a negative voltage. I picked 2 battery's and checked it , the first row changed black :D
 
Last edited:
hi Sneak.
Your code sticks in this loop.!!!
Code:
[B]figure[/B]        bsf RS
        MOVLW 40h
        movwf PORTC
   [B]     call enwait ;  calls enwait
        goto figure; keep doing it for ever!!![/B]
        return
enwait
        bsf  EN ; EN high
        movlw 0x0f ; wait 1,5 ms  
        movwf delay2
        call delay
        nop
        nop
        bcf  EN ; EN low
        return

Yes , you're right , I made this infinite loop because I want to display some kind of character on the display and keep doing it . I did this because i didnt even get a thing on the display. Thats why I made that infinite loop !

Thanks for noticing.
 
hi SneaK,
Look at this LCD program written for the 18F452, I dont have a 18F14K model so there will some minor differences in the PIC set up, but the LCD routines may give you some ideas. The PIC to LCD pin out uses the the same pin designations. ie PORTC = LCD data etc....
 

Attachments

  • Emu18F14k1.asm
    3.3 KB · Views: 126
Last edited:
Hello Eric,

thanks for the ASM code , I'm having some difficulties with the instructions like " bcf 0xF81,6" , "movwf 0xF82" , weird instructions are used in that asm code :D.
 
Hello Eric,

thanks for the ASM code , I'm having some difficulties with the instructions like " bcf 0xF81,6" , "movwf 0xF82" , weird instructions are used in that asm code :D.

hi,
They are SFR's special function register addresses, look at these two clips in order to get any conversion needed.
 

Attachments

  • AAesp05.gif
    AAesp05.gif
    58.1 KB · Views: 161
  • AAesp06.gif
    AAesp06.gif
    70.7 KB · Views: 163
Hello Eric,

thanks for the clip , but that's a lot of work , I've got a pearson's education book of microcontrollers laying arround here. The code that is used there is almoust the same as my code . I've used the initialisation of the PDF for my ST7066 : https://www.electro-tech-online.com/custompdfs/2010/08/ST7066.pdf , page 20.

I applied this in my code. I think it's weird that I have to turn the display OFF ??? thats at the initialisation step on page 20 .

Code:
;******************************************************************************
 ;                             
 ;******************************************************************************
 ;                                                                             *
 ;    Filename: LCD                                                            *
 ;    Date: 15/08/10                                                                   *
 ;    File Version:                                                            *
 ;                                                                             *
 ;    Author: CJ                                                              *
 ;    Company:                                                                 *
 ;                                                                             * 
 ;******************************************************************************
 ;                                                                             *
 ;    Files required: P18F14K50.INC     //1330.INC                                             *
 ;                                                                             *
 ;******************************************************************************
     LIST P=18F14K50, F=INHX32 ;directive to define processor and file format
     #include <P18F14K50.INC>     ;processor specific variable definitions
 
 ;******************************************************************************

 CONFIG    CPUDIV = NOCLKDIV; 
 CONFIG    USBDIV = OFF ; 
 CONFIG    FOSC = HS; 
 CONFIG    PLLEN = OFF; 
 CONFIG    FCMEN = OFF; 
 CONFIG    IESO = OFF; 
 CONFIG    PWRTEN = ON; 
 CONFIG    BOREN = ON; 
 CONFIG    BORV = 30; 
 CONFIG    WDTEN = OFF; 
 CONFIG    WDTPS = 1; 
 CONFIG    MCLRE = ON; 
 CONFIG    HFOFST = ON; 
 CONFIG    STVREN = ON; 
 CONFIG    LVP = OFF; 
 CONFIG    BBSIZ = OFF; 
 CONFIG    XINST = OFF; 
 CONFIG    CP0 = ON; 
 CONFIG    CPB = ON; 
 CONFIG    CPD = ON; 
 CONFIG    WRT1= ON; 
 CONFIG    WRTB = ON; 
 CONFIG    WRTC = ON; 
 CONFIG    WRTD = ON; 
 CONFIG    EBTRB = ON; 
 
 
 
 ;------------------------------------------------------------------------------
 ; MAIN PROGRAM
 ;------------------------------------------------------------------------------


	cblock  0x20  
	r1 			; delay
	r2 			
	r3 		
	delay2	; amount of delay
	fourt   ; 4 times execute a loop
	ctemp
	endc 


; R/W\ ==> GND write always 

#define  EN   PORTB,6
#define  RS   PORTB,7
#define  DB0  PORTC,0
#define  DB1  PORTC,1
#define  DB2  PORTC,2
#define  DB3  PORTC,3
#define  DB4  PORTC,4
#define  DB5  PORTC,5
#define  DB6  PORTC,6
#define  DB7  PORTC,7



          ORG	0x00	
		  call init 
start     call initlcd
		;  call figure
		
 
init 	clrf TRISC 
        clrf PORTC 
	    bcf ADCON0,ADON
 		MOVLW 0F0h
		movwf TRISB
		clrf PORTB
		clrf r1
		clrf r2
		clrf r3
		clrf delay2
		clrf WPUB
		movlw 0x04
		movwf fourt 
		clrf ctemp ; temp register to send data to PORTC
		

		return
 		      
initlcd  ; wait 150ms to start the LCD
		movlw 0x0f ;( 15 dec) 15*10ms=150ms
		movwf delay2
		call delaylong
		bcf RS ; RS low
		bcf EN ; EN low	
	;=================Set Function==================
; execute 4 times with equal delay

; DL = interface 8 bits  , NL = 2 , F = 5*11		
again 	MOVLW 38h ;
		movwf ctemp
		call enwait ; 5ms wait

	; wait 15ms to start the next instruction 
		movlw 0x96 ;( 150 dec) 150*100µs=15ms
		movwf delay2
		call delay
		decfsz fourt,f
		goto again 
; display off 
		movlw b'00111000'
		movwf ctemp
		call enwait	
		movlw 0x01 ; 1*100µs=100µs
		movwf delay2
		call delay		
;Clear display	
		MOVLW 0x01 ; Clear commando
		movwf ctemp
		call enwait		
		movlw 0x01 ; 1*100µs=100µs
		movwf delay2
		call delay
; entry mode set 
		MOVLW 0x07 ; I/D high and shift on
		movwf ctemp
		call enwait				
		movlw 0x01 ; 1*100µs=100µs
		movwf delay2
		call delay	
		return
; display on , cursur on , blinking
		MOVLW 0x0F ; 
		movwf ctemp
		call enwait				
		movlw 0x01 ; 1*100µs=100µs
		movwf delay2
		call delay	
		return
; return home 
		MOVLW 0x02 ; 
		movwf ctemp
		call enwait				
		movlw 0x01 ; 1*100µs=100µs
		movwf delay2
		call delay	
		loop	goto loop
		return
		

figure	bsf RS
		MOVLW 40h
		movwf ctemp
		call enwait
		return


enwait
		bsf  EN ; EN high
		call endelay
		movf ctemp,w
		movwf PORTC
		bcf  EN ; EN low
		call endelay
		return

endelay movlw 0x32 ; wait 5 ms  
		movwf delay2

delay   movlw   0x0A  ; delay2*10²*3*333ns=100µs*delay= delay2*100µs
	    movwf	r1			
D3		movlw	0x0A
		movwf	r2			
D4		movff   delay2,r3
D5		decfsz   r3,f ; 333ns	        		             
		goto	 D5   ; 666ns
		decfsz   r2,f	        		          
		goto	 D4				 
		decfsz   r1,f				
		goto	 D3	
		return		

delaylong  movlw   0x64  ; delay2*100²*3*333ns=100µs*delay= delay2*10ms
	    movwf	r1			
C3		movlw	0x64
		movwf	r2			
C4		movff   delay2,r3
C5		decfsz   r3,f ; 333ns	        		             
		goto	 C5   ; 666ns
		decfsz   r2,f	        		          
		goto	 C4				 
		decfsz   r1,f				
		goto	 C3	
		return	

     
 ;******************************************************************************
 ;End of program
 
         END

Maybe you can help me out??

Thanks in advance.
 
Last edited:
hi,
The LCD initialise sequence on page #20 of your pdf, is exactly the same as the Hitachi LCD manual..

I will look thru your latest code.

EDIT2:
Look at this asm file, it took about 5 minutes to to convert.

Run it thru your assembler, try it in a PIC.:)
 

Attachments

  • Emu18F14k2m.asm
    5.2 KB · Views: 129
Last edited:
Hello Eric,

I've got it working after all ! I know the controllers are the same , I just had trouble with the enable . The display works fine.

Thanks for the effort !!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top