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.

HELP with 4 bit LCD interfacing

Status
Not open for further replies.

3BABY

Member level 5
Joined
Jan 14, 2011
Messages
91
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
New Zealand
Activity points
2,252
Hi All,

i have an EasyPIC6 and the 2X16 LCD that i purchased with the board will only work in 4 bit mode, i am pulling my hair out trying to get it to work and cant find much documentation on 4 bit mode interfacing.. and NO examples in Assembily for this board,, any help would be much appreciated.. the setup is:

Description Connected to



Vss
Vdd
VO Contrast adjust

RS Register Select RB4
R/W Read/Write GND
E Enable RB5
DB0 Data Bit 0 GND
DB1 Data Bit 1 GND
DB2 Data Bit 2 GND
DB3 Data Bit 3 GND
DB4 Data Bit 4 RB0
DB5 Data Bit 5 RB1
DB6 Data Bit 6 RB2
DB7 Data Bit 7 RB3

A(+) Backlit
K(-) Backlit
0v
 

send the make of the LCD and code so others can help u

before that u can look at

**broken link removed**
 

send the make of the LCD and code so others can help u

before that u can look at

**broken link removed**

Thanks for the quick reply,

i have been looking over the webpage you linked, please find below links to data sheets and a schematic of how the LCD unit is connected on my board

**broken link removed**

Winstar WH1602B 2x16 LCD display - Support Center


**broken link removed**

Here is the code i have thus far.. look correct? the test write routine at the bottom is just supposed to display "K" on screen.. but i get nothing

thanks in advance!

Code:
LCD_DISP

		;LCD_DATA	EQU PORTB 	;LCD Data Pins RB0-RB3   - 4bit mode???


		DATA0	EQU RB0 	;LCD Data Pins RB0-RB3   - 4bit mode???
		DATA1	EQU RB1
		DATA2	EQU RB2
		DATA3	EQU RB3

		RS    EQU RB4
		;RW	  EQU GND - set low - 	R/W input allows the user to write information to the LCD or read information from it. R/W = 1 when reading; R/W =0 when writing.
		EN    EQU RB5		;E pin of LCD


			BCF PORTB, EN





;------------------------------------------------------------------------------------------------------------------------
; Initialize the LCD.


INITLCD		


			MOVLW	d'230'		; Call for 46ms delay
			CALL 	NDELAY		; Wait for VCC of the LCD to reach 5V
			
			BCF		PORTB, RS	; Clear RS to select Instruction Reg.
								; Clear R/W to write (is already set to Ground = logic 0 = Write )
		

			BCF		PORTB, RS
			MOVLW b'00000011'			; 
			MOVWF PORTB
			CALL	ENABLEPULSE
				MOVLW d'25'			; 5.18mS delay @ 8MHz
				CALL	NDELAY


			BCF		PORTB, RS
			MOVLW b'00000011'			; 
			MOVWF PORTB
			CALL	ENABLEPULSE
				CALL	DELAY200		; 


			BCF		PORTB, RS
			MOVLW b'00000011'			; 
			MOVWF PORTB
			CALL	ENABLEPULSE
				CALL	DELAY200		; 


			MOVLW b'00000010'		    ; enable 4 bit mode
			MOVWF PORTB
			CALL	ENABLEPULSE
				MOVLW d'25'
				CALL	NDELAY






			BCF		PORTB, RS
	
				;..FUNCTION SET..
		MOVLW	B'00000010'
		MOVWF	PORTB
	;	CALL	ENABLEPULSE	

			
				;CLEAR DISPLAY AND HOME CURSOR
			BCF		PORTB, RS
		MOVLW	B'00000000'
		MOVWF	PORTB
	;	CALL	ENABLEPULSE

		MOVLW	B'00000001'
		MOVWF	PORTB
	;	CALL	ENABLEPULSE
		


				;ENTRY MODE - 
					; BIT_E=1,BIT_RW=0,BIT_RS=0
			BCF		PORTB, RS
		MOVLW	B'00000000'
		MOVWF	PORTB
	;	CALL	ENABLEPULSE	

				;ENTRY SET - INCREMENT,NO DISP SHIFT(CUR SHIFT),BIT_E=1,BIT_RW=0,BIT_RS=0
			BCF		PORTB, RS
		MOVLW	B'00000110'
		MOVWF	PORTB
	;	CALL	ENABLEPULSE	

				;TESTING Turns on the LCD display and Sets a BLINKING CURSOR
			BCF		PORTB, RS
		MOVLW	B'00001111'
		MOVWF	PORTB
	;	CALL	ENABLEPULSE	

				;TURN ON DISPLAY - 
			BCF		PORTB, RS
		MOVLW	B'0001100'
		MOVWF	PORTB
	;	CALL	ENABLEPULSE


NOP




;test write
HERE33
			BCF	PORTB, EN
			BSF	PORTB, RS

			;BSF	PORTB, EN
			MOVLW b'00010100'			; High nibble 0100XXXX
			MOVWF PORTB
			CALL	ENABLEPULSE


			MOVLW d'55'
			CALL	NDELAY

			;BSF	PORTB, EN
			MOVLW b'00011011'			; Low nibble XXXX1011
			MOVWF PORTB
			CALL	ENABLEPULSE
	

			CALL	DELAY50
			BCF	PORTB, EN
			MOVLW d'55'
			CALL	NDELAY
			
			

			GOTO HERE33
 
Last edited:

So, looks like initiation goes correct.

But what are you trying to display?


I'm using this codes for initiation:
delay_ms(17);
LCD_Write(0x30);
delay_ms(1);
LCD_Write(0x30);
delay_ms(1);
LCD_Write(0x30);
delay_ms(1);
LCD_Write(0x20); //4 bit wide bus

LCD_Send_Cmd(0x28); //4bit wide bus 2 rows
LCD_Send_Cmd(0x10);
LCD_Send_Cmd(0x01);
LCD_Send_Cmd(0x0F);

---------- Post added at 10:33 ---------- Previous post was at 10:32 ----------

 

So, looks like initiation goes correct.


But what are you trying to display?


I'm using this codes for initiation:
delay_ms(17);
LCD_Write(0x30);
delay_ms(1);
LCD_Write(0x30);
delay_ms(1);
LCD_Write(0x30);
delay_ms(1);
LCD_Write(0x20); //4 bit wide bus

LCD_Send_Cmd(0x28); //4bit wide bus 2 rows
LCD_Send_Cmd(0x10);
LCD_Send_Cmd(0x01);
LCD_Send_Cmd(0x0F);

---------- Post added at 10:33 ---------- Previous post was at 10:32 ----------


thats a cool compilers.. what is the name of it?

so i have worked through the code a little more, what i didnt understand was that after you put the LCD into 4 bit mode everything from there forward, commands and data had to be in 2 x4 bits with their respective RS bit high or low, what i was wanting to send was the letter "K" - this was ok.. but i was confused by people sending initializing commands like LCD_Send_Cmd(0x28//4bit wide bus 2 rows, because i didnt have a routine to chop up 0x28 into two nibbles.. so i was just sending the high nibble 0x02 and forgot the low nibble 0x8.. after i had worked this out.. and that RS needed to be low for commands and high for data.. then it was ok.. so i adjusted some of the initialization code (after putting the LCD into 4 bit mode).. as you can see below


Code:
			BCF		PORTB, RS
		MOVLW	0x02
		MOVWF	PORTB
		CALL	ENABLEPULSE	
		;	MOVLW d'5'			; 1mS delay @ 8MHz
		;	CALL	NDELAY
			CALL DELAY50

			BCF		PORTB, RS
		MOVLW	0x08
		MOVWF	PORTB
		CALL	ENABLEPULSE	
			MOVLW d'5'			; 1mS delay @ 8MHz
			CALL	NDELAY



				;Display ON cursor OFF
			BCF		PORTB, RS
		MOVLW	B'0000000'
		MOVWF	PORTB
		CALL	ENABLEPULSE
		;	MOVLW d'5'
		;	CALL	NDELAY
			CALL DELAY50

			BCF		PORTB, RS
		MOVLW	B'0001100'
		MOVWF	PORTB
		CALL	ENABLEPULSE
			MOVLW d'5'
			CALL	NDELAY




				;Set entry mode (Auto increment)
			BCF		PORTB, RS
		MOVLW	B'0000000'
		MOVWF	PORTB
		CALL	ENABLEPULSE
		;	MOVLW d'5'
		;	CALL	NDELAY
			CALL DELAY50

			BCF		PORTB, RS
		MOVLW	B'0000110'
		MOVWF	PORTB
		CALL	ENABLEPULSE
			MOVLW d'5'
			CALL	NDELAY


			
				;Bring cursor to line 1
			BCF		PORTB, RS
		MOVLW	B'1000000'
		MOVWF	PORTB
		CALL	ENABLEPULSE
		;	MOVLW d'5'
		;	CALL	NDELAY
			CALL DELAY50

			BCF		PORTB, RS
		MOVLW	B'0000000'
		MOVWF	PORTB
		CALL	ENABLEPULSE
			MOVLW d'5'
			CALL	NDELAY

thanks for the help :)

now i have to work out how to write say a word from a table

data = 'HELLO'

instead of writing H, then E, then L etc etc.. and picking them all out of a huge table separately..
 

So, now everything working fine?
This simulator names Labcenter Proteus VSM 7.8 SP2
If you need it, try to find it by google. There are many cracked versions in web available.
 

So, now everything working fine?
This simulator names Labcenter Proteus VSM 7.8 SP2
If you need it, try to find it by google. There are many cracked versions in web available.

Yes have everything working now over the 4bit buss, MANY THANKS for all your help! i appreciate it! :)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top