View previous topic :: View next topic |
Author |
Message |
endazyar
Joined: 30 Apr 2013 Posts: 6
|
PIC16F877A LCD displaying problem |
Posted: Tue Apr 30, 2013 10:58 am |
|
|
Hello everyone, I'm trying to print something in a LCD 2x16 (LMD16L). I work on on PIC16F877A, my code is below, LCD has the light on when I give it the power, however nothing appears on LCD. When I simulate the code on ISIS it works well.
Any help would be appreciated. Thanks in advance.
Code: | #include <lcd.h>
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#define use_portb_lcd TRUE
#include <lcd.c>
void main ( )
{
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_CCP1(CCP_OFF);
setup_CCP2(CCP_OFF);
set_tris_b(0x00);
lcd_init();
while(1)
{
lcd_send_byte(0, 0x0d);
printf(lcd_putc,"\f selam");
delay_ms(1000);
printf(lcd_putc,"\n sule");
delay_ms(1000);
}
} |
The circuit
[/img] |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Apr 30, 2013 11:17 am |
|
|
Go to Google image search
http://www.google.com/imghp?hl=en&tab=wi
and search for this:
Quote: | schematic 16x2 lcd 16F877A |
Then compare your LCD connections to the sample schematics. |
|
![](templates/subSilver/images/spacer.gif) |
endazyar
Joined: 30 Apr 2013 Posts: 6
|
|
Posted: Tue Apr 30, 2013 12:15 pm |
|
|
But a friend of mine made it work while having the connections like that and programmed with Micro C. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Apr 30, 2013 12:31 pm |
|
|
You have the contrast circuit connected to the Ground pin (Vss) on
the LCD. You have the contrast pin (Vee) connected to nothing.
Also, the resistor values in the contrast circuit are not correct.
The values should be selected so the Vee pin is set at 0.4 volts. |
|
![](templates/subSilver/images/spacer.gif) |
endazyar
Joined: 30 Apr 2013 Posts: 6
|
|
Posted: Wed May 01, 2013 6:01 am |
|
|
I did as you said, but still there is nothing on lcd :( Thank you for your replies btw. |
|
![](templates/subSilver/images/spacer.gif) |
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Wed May 01, 2013 6:15 am |
|
|
endazyar wrote: | But a friend of mine made it work while having the connections like that and programmed with Micro C. |
Monkey see, monkey do.....
Post your new schematic!
John |
|
![](templates/subSilver/images/spacer.gif) |
endazyar
Joined: 30 Apr 2013 Posts: 6
|
|
Posted: Wed May 01, 2013 6:36 am |
|
|
That's my circuit.
And the schematic on ISIS
![](http://m1305.hizliresim.com/19/1/mn6qn.png) |
|
![](templates/subSilver/images/spacer.gif) |
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Wed May 01, 2013 7:11 am |
|
|
Hi,
Your schematic is still wrong. Pin #1 of the LCD, which is labelled
'Vss', must be connected to GND, not to +5V.
Your photo seems to show Pin #1 connected to GND, so it indicates that you
aren't being really careful and precise with your documentation..... What
else have you missed?
Are you sure that the PIC is actually running? Connect an LED to an I/O pin
of the PIC (thru a suitable current limiting resistor), and then blink the LED
on and off at a predictable rate (ie. 1 sec. on, 1 sec. off) to see if the PIC is
running, and running at the correct speed!
John |
|
![](templates/subSilver/images/spacer.gif) |
endazyar
Joined: 30 Apr 2013 Posts: 6
|
|
Posted: Wed May 01, 2013 7:16 am |
|
|
I'm sorry, in the circuit the pin 1 is connected to the GND, there is a mistake on the ISIS schematic. I'll try to test with the leds now then. |
|
![](templates/subSilver/images/spacer.gif) |
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Wed May 01, 2013 10:21 am |
|
|
Hi,
I noticed something missing in your code. Add this line after your #fuses line.
Code: |
#use delay(clock=4000000)
|
John |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 01, 2013 11:25 am |
|
|
Quote: | #define use_portb_lcd TRUE
#include <lcd.c> |
This shows you are using the CCS lcd driver.
But your photo shows that you have the R/W pin connected to ground.
The CCS lcd.c driver does not support this.
Many more of the lcd connections on your photo do not match
the schematic, and they are not correct for the lcd.c driver.
The CCS lcd.c driver expects these connections (if setup for PortB):
Code: | Pin B0 - EN
Pin B1 - RS
Pin B2 - R/W
Pin B3 - not used
Pin B4 - DB4
Pin B5 - DB5
Pin B6 - DB6
Pin B7 - DB7 |
Your photo shows that pins 39 and 40 on the PIC are not connected.
But those are pins B6 and B7. You need to fix all the connections.
Change it to be the same as the table above.
Also, you should add a 100 nF (0.1 uF) ceramic capacitor between the
Vdd and Vss pins (+5v and ground) on the PIC, on both sides of the
40-pin DIP package.
Also, your photo shows connections between LCD pins DB0-DB3 and
ground (the brown wires). That's not necessary. Those pins have
internal pull-ups and you can leave DB0-DB3 unconnected.
Also, your photo shows that you have +5v and ground connected directly
to the backlight power and ground pins on the LCD. You are normally
supposed to use a series resistor to limit the current.
This thread tells how to do it, with a link to a backlight resistor calculator:
http://www.ccsinfo.com/forum/viewtopic.php?t=37646&start=10 |
|
![](templates/subSilver/images/spacer.gif) |
endazyar
Joined: 30 Apr 2013 Posts: 6
|
|
Posted: Wed May 01, 2013 11:53 am |
|
|
I changed all the connections according to that schema below which ezflyr told me to use. So the connections in that schematic are not suitable for lcd.c right ? I think I'll need to change all the connections according to the adjustments you've told me.
![](http://4.bp.blogspot.com/-52hKTA-k1dE/TmEZKNHPFOI/AAAAAAAAAIs/J03gVXK9_D0/s1600/16x2+LCD.JPG) |
|
![](templates/subSilver/images/spacer.gif) |
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Wed May 01, 2013 12:11 pm |
|
|
Hi,
Did you understand PCM programmers last message? Your LCD power
connections are now correct, but you need to rewire your other LCD
connections according to the required connections in LCD.c!
This should take you a maximum of about 5 minutes!
John |
|
![](templates/subSilver/images/spacer.gif) |
|