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.

[SOLVED] Simple pic and lcd interface

Status
Not open for further replies.

neo_one

Junior Member level 2
Joined
Oct 26, 2011
Messages
22
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,445
CAN ANYONE TELL ME WHAT IS WRONG WITH THIS ROUTINE?
I just want to initialize a jhd 161a lcd display using pic 18f4550 to display some message. All i see when i run this is solid pixels. checked so may sites and did everything i could. please let me know if you see anything wrong in this code.

Code:
LCDInit:    BCF PORTA,0; CONTROL SIGNAL TO RS
		BCF PORTA,1; CONTROL SIGNAL TO R/W
		BSF PORTA,2; CONTROL SIGNAL TO 'E'
		MOVLW 0x0F
		MOVWF PORTB
		CALL DISPLAY
		MOVLW 'H'
		CALL DISPLAY
		MOVLW 'E'
		CALL DISPLAY
		MOVLW 'L'
		CALL DISPLAY
		MOVLW 'L'
		CALL DISPLAY
		MOVLW 'O'
		CALL DISPLAY
		MOVLW ' '
		CALL DISPLAY
		MOVLW 'W'
		CALL DISPLAY
		MOVLW 'E'
		CALL DISPLAY
		MOVLW 'L'
		CALL DISPLAY
		MOVLW 'C'
		CALL DISPLAY
		MOVLW 'O'
		CALL DISPLAY
		MOVLW 'M'
		CALL DISPLAY
		MOVLW 'E'
		CALL DISPLAY
		MOVLW ' '
		CALL DISPLAY
		BCF PORTA,0;LCD INPUT=>INSTRUCTION
 		MOVLW 0x01
 		MOVWF PORTB
		CALL DISPLAY
		RETURN
DISPLAY:   
   		MOVWF PORTB
		BCF PORTA,2
		BSF PORTA,2
		CALL DELY
		BSF PORTA,0
		RETURN

DELY	MOVLW D'13'
		MOVWF T1
		MOVLW D'251'
		MOVWF T2
LP		DECFSZ	T2,1
  		GOTO	LP
  		DECFSZ	T1,1
  		GOTO	LP
  		RETURN

I THINK THE PROBLEM IS SOME SIMPLE INITIALIZATION MISTAKE. I AM USING INTERNAL RC OSCILLATOR INSTEAD OF CRYSTAL OSCILLATOR.
 
Last edited:

You have to initialize the display before you can use it.
There is an initialization sequence that has to be followed to put the display in 4-bit/8-bit mode.
Just google 'lcd initialization' and you should get the required info.
 

How different is it from 18f4550?
 

Hi,

Only a little providing you are not using the USB functions,which I assume you are not.

Its mainly the Config and oscillator that may need changing slightly, what oscillator and frequency are you using ?

If you post your full code including the config I will check things, might be useful to show your wiring diagram of the 4550 and lcd.
 

I am using the internal RC oscillator. I am not using the USB function. I want to reduce the overall size of the circuit. That is why I am not using

Code:
; RECEIVER LOGIC PROGRAM

	LIST P=18F4550, F=INHX32	;directive to define processor
	#include <P18F4550.INC>		;processor specific variable definitions

		T1 EQU 0X057
		T2 EQU 0X59

		CONFIG WDT=OFF				; disable watchdog timer
		CONFIG MCLRE = ON				; MCLEAR Pin on
		CONFIG DEBUG = OFF				; Enable Debug Mode
		CONFIG LVP = OFF				; Disable low voltage programming
		CONFIG FOSC = INTOSCIO_EC		; internal oscillator
		CONFIG PBADEN = OFF             ; PORTB all digital

		


;Reset vector
; This code will start executing when a reset occurs.

	RESET_VECTOR CODE 0x0000
	goto Start


Start:

	CLRF WREG
	CLRF RCSTA
	CLRF PORTA
	CLRF TRISA
	CLRF PORTB
	CLRF TRISB

	MOVLW 0X06
	MOVWF ADCON1
	CALL LCDInit ; LCD Display Initialization


LCDInit:    BCF PORTA,0; CONTROL SIGNAL TO RS
		BCF PORTA,1; CONTROL SIGNAL TO R/W
		BSF PORTA,2; CONTROL SIGNAL TO 'E'
		MOVLW 0x0F
		MOVWF PORTB
		CALL DISPLAY
		MOVLW 'H'
		CALL DISPLAY
		MOVLW 'E'
		CALL DISPLAY
		MOVLW 'L'
		CALL DISPLAY
		MOVLW 'L'
		CALL DISPLAY
		MOVLW 'O'
		CALL DISPLAY
		MOVLW ' '
		CALL DISPLAY
		MOVLW 'W'
		CALL DISPLAY
		MOVLW 'E'
		CALL DISPLAY
		MOVLW 'L'
		CALL DISPLAY
		MOVLW 'C'
		CALL DISPLAY
		MOVLW 'O'
		CALL DISPLAY
		MOVLW 'M'
		CALL DISPLAY
		MOVLW 'E'
		CALL DISPLAY
		MOVLW ' '
		CALL DISPLAY
		BCF PORTA,0;LCD INPUT=>INSTRUCTION
 		MOVLW 0x01
 		MOVWF PORTB
		CALL DISPLAY
		RETURN
DISPLAY:   
   		MOVWF PORTB
		BCF PORTA,2
		BSF PORTA,2
		CALL DELY
		BSF PORTA,0
		RETURN

DELY	MOVLW D'13'
		MOVWF T1
		MOVLW D'251'
		MOVWF T2
LP		DECFSZ	T2,1
  		GOTO	LP
  		DECFSZ	T1,1
  		GOTO	LP
  		RETURN

END

I want to use the LCD in 8 bit mode. Wiring is as follows

Port B is connected to Data pins of LCD. Port A bits 0, 1 and 2 are connected to RS, R/W, and E respectively. Vss to GND, Vdd to 5V and Vee through pot.

My simulation is working in Proteus. I think i have not done the initialization properly. I am not sure about the delay calculations with internal RC oscillator.
 
Last edited:

Hi,

You are using the internal Osc but do you know at what speed ..? its using the Default 1 mhz setting.

See the OSCCON settings.

4 or 8 mhz is more ususal but changing the speed does affect all your software delay timings.

That code I refered to should work with your config statements but would need the delays changing to siut your internal osc speed.
It used 4 bit mode so is much more compact than the 11 ports you are using.

You can use this calculator for the delays **broken link removed**


On your hardware are you using the USB cap ( simulation probably would assume it for you)
 

My OSCCON register is 44, which means 1MHz stable frequency. What is the difference with 8 bit mode? is it more difficult? Can you suggest any site which gives exact initialization routine for 8 bit mode? I tried many but all failed.

I didn't understand this
On your hardware are you using the USB cap ( simulation probably would assume it for you)
 

My OSCCON register is 44, which means 1MHz stable frequency. What is the difference with 8 bit mode? is it more difficult? Can you suggest any site which gives exact initialization routine for 8 bit mode? I tried many but all failed.

I didn't understand this

These pdfs should help you http://www.epemag.wimborne.co.uk/resources.htm

8 bit mode is easier to set up but once 4 bit mode is done it is virtually the same, but uses 4 ports less.

Stongly suggest you use 4mhz as the osc, its much more compatible with other software examples on the web.

The 4550 is not a chip I use regularly but seem to remember pin 18 Vusb must had a cap fitted even though you are not using usb.
470nf to ground should do it.

If you are still stuck by the end of tonight leave a message and I will try and sort a working example for you.
 

I still can't get it right. I was following the instructions in to interface the LCD. It says just give the command 0x0F and the cursor will start blinking. Then we can give any character to be displayed and the LCD will display it. All I see is solid boxes and I cannot vary the contrast also.
 

I still can't get it right. I was following the instructions in to interface the LCD. It says just give the command 0x0F and the cursor will start blinking. Then we can give any character to be displayed and the LCD will display it. All I see is solid boxes and I cannot vary the contrast also.


Hi,

Attached is a proven routine I have just simulated ok using your config lines and the circuit shown.

It uses 4 bit mode with a 4 mhz internal oscillator.


If nothing still works, have you made anything to actually run on the 4550 chip, like a flashing led ?

Let me know how if the lcd works...
 

Attachments

  • lcd4550.rar
    143 KB · Views: 84

Hi,

Attached is a proven routine I have just simulated ok using your config lines and the circuit shown.

It uses 4 bit mode with a 4 mhz internal oscillator.


Hi,

Got hold of a 4550 chip at work today and ran that code on it to the lcd without any problem.

Seems you do not need a cap on Pin 18 after all.


Have you got your hardware working ok ?
 

Hi wp100. Thanks a lot for your help. It works fine :cool: :cool: I tried your program successfully. In my application, I am using UART also. So I had to change the baud rate settings of UART for 4Mhz.
And I found one problem with my code.
Code:
MOVLW 0X06
MOVWF ADCON1
This will set a few pins of portB as analog input. So some configuration commands will not work properly. ADCON1 should have been 0x0F to set all port B pins as digital output!!
The resources you shared were very useful. Especially the one to generate delay codes :idea:.
Thanks once again.
 

Hi,

That good the hear the lcd is working, the lcd routine is very basic and needs changing a bit to become more handy for displaying data

The 06 to ADCON1 should be 0x0F, though it was acually not needed as the Cofig statement had already set PortB to digital
PBADEN = OFF PORTB<4:0> pins are configured as digital I/O on Reset.
When you used the 06 to ADCON1 you were actually turning PortB back to Analogue.. :-D
 

Hi,

Here are some examples of different ways to output data to the LCD.
 

Attachments

  • lcd18F.rar
    17 KB · Views: 61

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top