PDA

View Full Version : Problems with LCD in pic 18f8520



JAVEHE
- 15th January 2012, 22:34
Hello! I have been trying to run the LCD example that comes with de Microcode studio, but is not working!
I'm use the BIGPIC5 that uses pic 18f8520 and i use basic lenguaje.
This is the code that i try to run:

DEFINE OSC 4
DEFINE LCD_DREG PORTB
DEFINE LCD_RSREG PORTA
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTA
DEFINE LCD_EBIT 2
DEFINE LCD_BITS 8
DEFINE LCD_LINES 2




Pause 500 ' Wait for LCD to startup


mainloop: Lcdout $fe, 1 ' Clear LCD screen
Lcdout "Hello" ' Display Hello
Pause 5000 ' Wait .5 second


Lcdout $fe, 1 ' Clear LCD screen
Lcdout "World"
Pause 500 ' Wait .5 second


Goto mainloop ' Do it forever


The only thing that i get is some leds blinking, but in the lcd not appear anything.
Please could you help me?

spcw1234
- 16th January 2012, 00:23
Hello! I have been trying to run the LCD example that comes with de Microcode studio, but is not working!
I'm use the BIGPIC5 that uses pic 18f8520 and i use basic lenguaje.
This is the code that i try to run:

DEFINE OSC 4
DEFINE LCD_DREG PORTB
DEFINE LCD_RSREG PORTA
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTA
DEFINE LCD_EBIT 2
DEFINE LCD_BITS 8
DEFINE LCD_LINES 2




Pause 500 ' Wait for LCD to startup


mainloop: Lcdout $fe, 1 ' Clear LCD screen
Lcdout $fe, "Hello" ' Display Hello
Pause 5000 ' Wait .5 second this is actually 5 seconds


Lcdout $fe, 1 ' Clear LCD screen
Lcdout $fe, "World"
Pause 500 ' Wait .5 second


Goto mainloop ' Do it forever


The only thing that i get is some leds blinking, but in the lcd not appear anything.
Please could you help me?

Make sure you have a 10K potentiometer set up so you can change the voltage on the VL pin to adjust the contrast. Not the change above in your code, whenever you use the lcdout command you need the $fe as shown in red above.

JAVEHE
- 16th January 2012, 01:35
Thanks 4 your answer. I did that but still not working, my lcd doesnt show anything...I see the lcd turn on and i can change the contrast but doesnt appear anything Also I see some leds blinking.

I've been thinking if the problems is something with the lcd connector, because i've been trying everything but nothing.....How can i check that?

spcw1234
- 16th January 2012, 02:06
You have it configured for 8bit, do you have all 8 data lines connected to the pic? LVP disabled? Extended instructions disabled? I/O's set to digital?

Try adding to your code


adcon1=15
cmcon=7

Demon
- 16th January 2012, 03:41
Moved from Code Examples.

Robert

HenrikOlsson
- 16th January 2012, 06:42
Hi,
Shawn said what I was going to regarding setting the pins to digital, however....

I took a quick look in the BIGPIC5 manual (http://www.mikroe.com/eng/downloads/get/14/bigpic5_manual.pdf) and in the 2*16LCD section it says[quote]
The character LCD communicates with the microcontroller via 4-bit data bus[quote]
What's also noticable when you look in the manual is that the LCD is connected to PortD while you have your code setup as if the LCD was connected to PortA and PortB. So, I'm not surprised it doesn't work.... And, since it's on PortD you don't need to worry about the analog stuff.

Also, make sure that MCU-card with the 18F8720 on it have a 4Mhz x-tal. If it have something else that needs to be reflected in the code or the timing will wrong.

So, read the manual for the development board and set the code up accordingly.


Finally, it's been a while since I used LCDOUT but I don't think the part about the $fe that Shawn wrote is 100% correct. You need $fe if the next byte you send is to be interpreted as a command by the LCD, for example LCDOUT $fe,1 to clear the screen. But when writing actual data to it you should not have the $fe in there as it will then try to interpret the first character after $fe as a command and strange things will occur. LCDOUT $fe,"Hello" will interpret the H as a command (whatever that might be) and then try to print ello.

/Henrik.

JAVEHE
- 16th January 2012, 18:55
Yes, I said that or i try to said that. This is the example that comes with Micro Code Examples as I said in my first post. Sorry for my english

JAVEHE
- 16th January 2012, 18:57
Ok thank for you time!!
I change the connection of the LCD, and i put PortD, also i change the $fe thing, but nothing happend. The only change that i see is that now the portD leds are blinking.

HenrikOlsson
- 16th January 2012, 19:34
Hi,
Did you change the individual bit assignement to match the actual hardware and changed from 8bit to 4bit?

I'd try something like this:

DEFINE LCD_DREG PORTD
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTD DEFINE LCD_RSBIT 2
DEFINE LCD_EREG PORTD
DEFINE LCD_EBIT 3
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 4000
DEFINE LCD_DATAUS 100

TRISD = %000000011

PAUSE 1000

LCDOUT $FE,1,"Hello World" 'Clear screen then print.

WHILE 1 : WEND

/Henrik.

Acetronics2
- 16th January 2012, 19:43
Hi,

the question that comes to me is ...

Which socket of the BP5 do you use for the 8 bits mode LCD ???

interesting answer ... for sure.

you should use Port J and D ... ( yess , both ! )

Alain

Acetronics2
- 16th January 2012, 19:54
That's really incredible what you can find with dedicated examples from the hardware brand ...



/*
* Project name:
Lcd8_Test (Demonstration of the Lcd8 Library routines)
* Copyright:
(c) Mikroelektronika, 2008.
* Revision History:
20081218:
- initial release;
* Description:
This code demonstrates how to use Lcd 8-bit library. Lcd is first
initialized, then some text is written, then the text is moved.
* Test configuration:
MCU: P18F8520
Dev.Board: BIGPIC5
Oscillator: HS, 10.0 MHz
Ext. Modules: Lcd 2x16 module
SW: mikroC PRO for PIC
* NOTES:
- None.
*/
// Lcd8 module connections
sbit LCD8_RS at RJ2_bit;
sbit LCD8_RW at RJ3_bit;
sbit LCD8_EN at RJ4_bit;
sbit LCD8_D7 at RD7_bit;
sbit LCD8_D6 at RD6_bit;
sbit LCD8_D5 at RD5_bit;
sbit LCD8_D4 at RD4_bit;
sbit LCD8_D3 at RD3_bit;
sbit LCD8_D2 at RD2_bit;
sbit LCD8_D1 at RD1_bit;
sbit LCD8_D0 at RD0_bit;
sbit LCD8_RS_Direction at TRISJ2_bit;
sbit LCD8_RW_Direction at TRISJ3_bit;
sbit LCD8_EN_Direction at TRISJ4_bit;
sbit LCD8_D7_Direction at TRISD7_bit;
sbit LCD8_D6_Direction at TRISD6_bit;
sbit LCD8_D5_Direction at TRISD5_bit;
sbit LCD8_D4_Direction at TRISD4_bit;
sbit LCD8_D3_Direction at TRISD3_bit;
sbit LCD8_D2_Direction at TRISD2_bit;
sbit LCD8_D1_Direction at TRISD1_bit;
sbit LCD8_D0_Direction at TRISD0_bit;
// End Lcd8 module connections


Don't you think ???

Alain

No miracle, eh, my friend JAVEHE ...:surprise:

JAVEHE
- 16th January 2012, 20:18
Thanks! Now is working :D I had problems with "LCD connections" but now i change and is fine

another question... can i show in my lcd a "variable"? I mean a character that changes?

HenrikOlsson
- 16th January 2012, 21:02
myVar VAR BYTE

For myVar = 0 to 255
LCDOUT $FE, 1, #myVAR
PAUSE 1000
NEXT

spcw1234
- 19th January 2012, 00:49
Finally, it's been a while since I used LCDOUT but I don't think the part about the $fe that Shawn wrote is 100% correct. You need $fe if the next byte you send is to be interpreted as a command by the LCD, for example LCDOUT $fe,1 to clear the screen. But when writing actual data to it you should not have the $fe in there as it will then try to interpret the first character after $fe as a command and strange things will occur. LCDOUT $fe,"Hello" will interpret the H as a command (whatever that might be) and then try to print ello.

You are correct, I never use LCDOUT this way. I always have a command in there so I have never come across this problem. Thanks for correcting this