PDA

View Full Version : PIC 16f877A LCD problem!



uaf5000
- 19th May 2010, 20:54
Hello Guys,

I have interfaced LCD with my PIC 16f877a. I want to initially display words on my lcd but the problem is only garbage value is being displayed. Please tell me the solution. I have given the code which i used to program the MCU.


Regards.

CLEAR
DEFINE OSC 4
DEFINE LCD_DREG PORTD
DEFINE LCD_RSREG PORTE
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTE
DEFINE LCD_EBIT 1
DEFINE LCD_RWREG PORTE
DEFINE LCD_RWBIT 2
DEFINE LCD_BITS 8
DEFINE LCD_LINES 1
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
PAUSE 500
LOW PORTE.2
TRISD = %00000000
TRISE = %00000000
ADCON1=%00000111
LOOP:
LCDOUT $FE, 1
PAUSE 250
LCDOUT "HELLO"
LCDOUT $FE,$C0
LCDOUT "WORLD"
PAUSE 250
GOTO LOOP
END

BobK
- 19th May 2010, 22:36
Hello uaf5000,

Well at first glance you are missing the line "DEFINE LCD DBIT 0". You also have a line that says you are only using 1 line when the statement "LCDOUT $FE,$C0" is the command to display the following on the second line of the LCD. Make these changes and see how it goes.
Your code can also read--"LCDOUT $FE,1,"Hello"
"LCDOUT $FE,$C0,"World"

I think this also may have been messing things up for you.

HTH,

BobK

uaf5000
- 19th May 2010, 23:07
Still same garbage values =(. I made the changes you told. But in those garbage values letter 'D' is appearing which wasn't before. What shall i do now? =(

mackrackit
- 20th May 2010, 02:42
PORTE is analog on this chip, so you will need to turn that off.
http://www.picbasic.co.uk/forum/showthread.php?t=561

mackrackit
- 20th May 2010, 03:07
Or use this
http://www.picbasic.co.uk/forum/content.php?r=154

uaf5000
- 20th May 2010, 08:59
I've used the command ADCON1=%00000111. Didnt this command make port E digital?

mackrackit
- 20th May 2010, 12:46
I've used the command ADCON1=%00000111. Didnt this command make port E digital?
Yes, I missed that :o


DEFINE LCD_BITS 8
Can you post how the LCD is connected?

uaf5000
- 21st May 2010, 07:13
LCD----------->PIC

RS-------------->RE0
R/W-------------->RE2
E--------------->RE1
Datapin0 --------->RD0
Datapin1 -------->RD1
Datapin2 ---------->RD2
datapin3 ------------->RD3
datapin4 ----------->RD4
datapin5----------->RD5
datapin6------------RD6
datapin7----------->RD7

mackrackit
- 21st May 2010, 07:50
I see a couple of problems.
R/W from the LCD should go to ground(zero).
Looking at your defines again the following is not a define.


DEFINE LCD_RWREG PORTE
DEFINE LCD_RWBIT 2

Take a look at this page and connect the LCD that way, 8 bit bus setup does not gain you much, but cost four pins, so go with 4 bit bus.
http://www.rentron.com/PICX1.htm

Then go here to see how the defines should be setup.
http://www.rentron.com/PICX2.htm

Let us know how it goes.

uaf5000
- 21st May 2010, 21:32
Thanks alot for the advices guys. =) But i found what the problem was. Actually the connections in my board were disturbed. LCD is working fine now =). Will post in case of any problem.


THANKS AGAIN =).