|
|
View previous topic :: View next topic |
Author |
Message |
zonemikel
Joined: 13 Oct 2007 Posts: 53 Location: Texas
|
How To LCD connections, basic setup |
Posted: Sun Jan 13, 2008 5:39 pm |
|
|
Hello everyone,
Ive searched for this but the posts i found relating to exacty this were messed up, seems like the person needing the help had no clue, maybe i dont either anyway here goes.
// edit im using pic c ide version 3.43, that might make a difference
I have a LCD-16MOO2D which was the cheapest one i could find its a 2x16 lcd display the datasheet (2 pages) is here (pdf warning)
http://www.vishay.com/docs/37219/016m002d.pdf
i connected it to port D as specified in lcd.c file
Code: | // D0 enable
// D1 rs
// D2 rw
// D4 D4
// D5 D5
// D6 D6
// D7 D7 |
i put +5v to pin 1 (which on mine is vdd) ground to pin 2. For pin 3 i put a 10k resistor to hot and the other side to gnd(not sure what pot to use)
Before i go and pull whats left of my hair out can somone let me know if im doing everything right ? That way if my software side is right (lcd.c or flex.c ? ) i know its the connections that are failing.
here is the code im using its just a test program made just to test my pic
Code: | // from the .h file
#include <16F877.h>
#device adc=8
#use delay(clock=4000000)
#fuses NOWDT,HS,NOPUT,NOLVP
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
// includes
#include <string.h> // string stuff
#include <lcd.c>
void Beep();
void main()
{
char string[50]; //
int32 i = 0;
int32 k = 0;
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
Beep();
// Test LCD on port D
lcd_init();
delay_ms(1000);
printf(lcd_putc, "hello World");
while(1)
{
Beep();
Printf(lcd_putc, "hello World");
delay_ms(500);
printf("testing\n\r");
delay_ms(1000);
// more code here and the beep function etc . . .
|
Shortly after the pic starts up i see the lcd display come on but there are no letters just the first row of light blocks and the second row of a little darker blocks
Thanks in advance _________________ Smart people know how stupid they are. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 13, 2008 6:32 pm |
|
|
Quote: | For pin 3 i put a 10k resistor to hot and the other side to gnd. |
Does this mean you have two 10K resistors as a voltage divider ?
That won't work. That will put +2.5v on the contrast pin of the LCD.
To fix this problem, change one of the resistors to a 1K, and connect
the voltage divider circuit like this:
Quote: |
10K to +5v
1K to GND
|
The voltage at the junction will now be 5v/11 = .45v
Using 0.45v for the contrast voltage should work.
Also make sure that you connect to pins DB4-DB7 on the LCD for
the data bus (going to D4-D7 on the PIC). |
|
|
zonemikel
Joined: 13 Oct 2007 Posts: 53 Location: Texas
|
argh ... no luck |
Posted: Sun Jan 13, 2008 9:52 pm |
|
|
I did as suggested and used a 1k resistor to ground, if i put a 2k resistor it gets even lighter, anyway i can see it and i should be able to see any letters if they were showing up.
I tested every connection (d0-d2 and d4-d7) from the pic to the lcd connector just to be sure there was no fault in the soldering they all work just fine.
Some things i did notice is when you make the project with the "wizard" and then click the drivers tab then "lcd driver" then when you click i/o pins tab it shows port b having all the lcd connecting pins. But then in the actual lcd.c it says in the beginning Quote: | // As defined in the following structure the pin connection is as follows:
// D0 enable
// D1 rs
// D2 rw
// D4 D4
// D5 D5
// D6 D6
// D7 D7
//
// LCD pins D0-D3 are not used and PIC D3 is not used.
// Un-comment the following define to use port B
// #define use_portb_lcd TRUE |
and i never uncomment that line.
Im stumped at this point, i saw some other post talking about a "flex" driver im gonna look for that.
As is my lcd just shows the top line empty and the bottom line full of blocks.
//update
If i unplug all the lines to the lcd except the hot/ground/contrast it does the same thing, i unplugged its power and plugged it back in and it does the same thing. So whatever the pic is doing has 0 effect on the lcd, its as if i had just plugged it into the power, nothing happens just the bottom line is full of blocks and the top line is empty _________________ Smart people know how stupid they are. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Mon Jan 14, 2008 8:30 am |
|
|
It seems as if people keep having problems with getting LCD displays going. I've certainly had my own troubles! My experience is that the "row of black squares" is what you see when you apply power to the LCD before a valid startup sequence is sent. If the squares don't go away, you need to look at the software, and also the wiring that drives the display. I always use an oscilloscope to do this.
I have an ancient compiler version which doesn't have the LCD control functions, so I have to write my own. It's easy to cut and paste, so I'll share my startup routine, for what it's worth. I've got the display wired in 4-bit mode, and the arguments to lcd_nibble() are the data to send, whether it's a control operation, and the delay in msec to apply after doing the write. I use my own delay routine which decrements the msecs value in an interrupt, and that interrupt has other tasks too, but the compiler's delay routines should work. I won't claim that this is the most elegant way to do the job, but it's one of those situations where "Once you get it running, leave the damn thing alone!"
Code: |
void lcd_init(void)
{
for (msecs = 15; msecs > 0; ) ; // Delay 15msec
lcd_nibble(3, 1, 5);
lcd_nibble(3, 1, 1);
lcd_nibble(3, 1, 1);
lcd_nibble(2, 1, 1);
lcd_nibble(0x2, 1, 1);
lcd_nibble(0x8, 1, 5);
lcd_nibble(0x1, 1, 1);
lcd_nibble(0x0, 1, 5);
lcd_nibble(0x0, 1, 1);
lcd_nibble(0x1, 1, 5);
lcd_nibble(0x0, 1, 1);
lcd_nibble(0x6, 1, 5);
lcd_nibble(0x0, 1, 1);
lcd_nibble(0xC, 1, 5);
}
|
|
|
|
zonemikel
Joined: 13 Oct 2007 Posts: 53 Location: Texas
|
|
Posted: Mon Jan 14, 2008 12:36 pm |
|
|
John P wrote: | My experience is that the "row of black squares" is what you see when you apply power to the LCD before a valid startup sequence is sent.
[/code] |
So the lcd should not have power (vdd) until the pic has already done its dirty work ?
Whats funny is if i just have the (e/rs/rw) and (d4-d7) pins hooked up to port D on my pic then i just have the ground and contrast hooked up the pic turns on somehow, even though there is no +5 to vdd. When i have it like this (nothing on vdd) and i turn off my pic (grnd to mclr) the lcd turns off then i turn my pic on and it comes back on with the row of black squares.
I used the flex driver with the same results. All i did to the flex driver was change the pins
Code: | #define LCD_DB4 PIN_D4
#define LCD_DB5 PIN_D5
#define LCD_DB6 PIN_D6
#define LCD_DB7 PIN_D7
#define LCD_E PIN_D0
#define LCD_RS PIN_D1
#define LCD_RW PIN_D2 |
then in my main i have this
Code: | lcd_init(); // Always call this first.
lcd_putc("\fHello World\n");
lcd_putc("Line Number 2");
while(1); |
just like it says. so should i have the vdd/vss going to the +5v/gnd on my voltage regulator, so when the circuit starts up the lcd gets power or is that wrong ?
Some thing i noticed is that in the other posts they always say the first (top?) line is full of black squares, on mine its the bottom, not sure of that matters.
Thanks for all the help, unless ive got a bum lcd im sure its something im doing wrong.
/////////////////////
// update
/////////////////////
When i have this in my main
Code: | Beep();
delay_ms(2000);
lcd_init(); // Always call this first.
delay_ms(2000);
Beep();
lcd_putc("\fHello World\n");
lcd_putc("Line Number 2");
while(1){
delay_ms(2000);
Beep();
lcd_putc("\fHello World\n");
lcd_putc("Line Number 2");
} |
And i try it with the +5v to the lcd i just get the bottom row of black boxes when i unplug the +5v to the vdd on the lcd and turn on the circuit it will do the first beep (before init) then it will blink the lcd after every beep, so its blinking after every attempted write, but this is only when i have the +5 volts disconnected from the vdd on the lcd. _________________ Smart people know how stupid they are. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 14, 2008 1:53 pm |
|
|
Make sure that you understand the pin numbering system on
the LCD connector. The odd-numbered pins are all on one
side of the connector. The even pins are on the other side.
Make sure you properly identify pin 1.
Also, the LCD must be fully powered up before you
write comands or data to it. In fact, a delay of a few tens
of milliseconds is required before you send anything to it,
while it does its own internal power-on init sequence.
The CCS driver and the Flex driver incorporate this delay. |
|
|
zonemikel
Joined: 13 Oct 2007 Posts: 53 Location: Texas
|
|
Posted: Mon Jan 14, 2008 5:30 pm |
|
|
Ok pcm ill be sure to check all the pins on the lcd and make sure i was counting them right when i get home ... good idea. _________________ Smart people know how stupid they are. |
|
|
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Mon Jan 14, 2008 7:13 pm |
|
|
Sorry, ambiguous wording on my part.
I meant, "The black boxes are shown after power is applied, until a valid startup sequence is received." Surely it's obvious that nothing at all happens if the LCD isn't powered! |
|
|
zonemikel
Joined: 13 Oct 2007 Posts: 53 Location: Texas
|
Some Pictures |
Posted: Tue Jan 15, 2008 9:02 am |
|
|
Well i checked everything, im sure i was right on the pinning for the lcd but here are some pictures maybe somone else can see the flaw because i cant find anything wrong. The code is still the same (the one above with like 2 second delays between everything).
This is how i have everything hooked up, it actually shows pins 1,2 and 13,14 on the lcd so it would be hard for me to get that wrong, but i posted my pinning in red.
this is how it hooks up on the breadboard, the connections are shown in the middle, i have wires there i just didnt want them in the picture but the lines with arrows on either end are how i have the lcd connected to portD
And of course this is what i see when i turn it on
Im really stumped. _________________ Smart people know how stupid they are. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jan 16, 2008 12:13 am |
|
|
Quote: | As is my lcd just shows the top line empty and the bottom line full of blocks. |
Your LCD is upside down. It's rotated 180 degrees. In your photo, your
finger is pointing at the top row. So in fact, the black squares are on
the top row.
Can you re-take the last photo, and make it a lot sharper ?
I had to pump up the gamma and brightness on it as well.
Overall, I would get rid of all those wires. I would have
direct connections between the LCD and the PIC. |
|
|
zonemikel
Joined: 13 Oct 2007 Posts: 53 Location: Texas
|
|
Posted: Wed Jan 16, 2008 10:47 pm |
|
|
Quote: | Can you re-take the last photo, and make it a lot sharper ? |
Sure thing sorry about the crappy picture i took another one and it is here i didnt want to post it in the thread because its kinda big, but it should allow you to see perfectly whats going on.
http://www.zonemikel.com/crap/lcdBIG.gif
data sheet is here
http://www.vishay.com/docs/37219/016m002d.pdf
Quote: | Overall, I would get rid of all those wires. I would have
direct connections between the LCD and the PIC. |
How do you mean? I made the board to hook up to a breadboard for testing, that way i can see how stuff works before i solder it. What kind of connection would you recommend ?
Thanks for the help. _________________ Smart people know how stupid they are. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jan 16, 2008 11:56 pm |
|
|
It looks like you have a 1K resistor going from the contrast pin to +5v,
and that's the entire contrast circuit. If so, that's not correct.
You should change it so there is a 1K resistor going between the contrast
pin and ground, and also a 10K resistor bewteen contrast and +5v.
This will set the contrast pin voltage to approximately 0.45 volts.
You should check it with a voltmeter to confirm this.
You should also check all the connections between the PIC and the LCD
with an ohmeter. Turn off the power and put one probe on the PIC pins
and the other probe on the LCD pins, and go through each set of pins
to verify the connections. You have three sets of wires, and at least
four connectors to be concerned with. It should be checked.
Here is a schematic of the contrast circuit.
Code: |
10K 1K
+5v ---/\/\/\/---o---/\/\/\/--- GND
|
|
to LCD
contrast pin
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|