CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC16F877A LCD displaying problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
endazyar



Joined: 30 Apr 2013
Posts: 6

View user's profile Send private message

PIC16F877A LCD displaying problem
PostPosted: Tue Apr 30, 2013 10:58 am     Reply with quote

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]
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 30, 2013 11:17 am     Reply with quote

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.
endazyar



Joined: 30 Apr 2013
Posts: 6

View user's profile Send private message

PostPosted: Tue Apr 30, 2013 12:15 pm     Reply with quote

But a friend of mine made it work while having the connections like that and programmed with Micro C.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 30, 2013 12:31 pm     Reply with quote

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.
endazyar



Joined: 30 Apr 2013
Posts: 6

View user's profile Send private message

PostPosted: Wed May 01, 2013 6:01 am     Reply with quote

I did as you said, but still there is nothing on lcd :( Thank you for your replies btw.
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Wed May 01, 2013 6:15 am     Reply with quote

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
endazyar



Joined: 30 Apr 2013
Posts: 6

View user's profile Send private message

PostPosted: Wed May 01, 2013 6:36 am     Reply with quote

That's my circuit.


And the schematic on ISIS
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Wed May 01, 2013 7:11 am     Reply with quote

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
endazyar



Joined: 30 Apr 2013
Posts: 6

View user's profile Send private message

PostPosted: Wed May 01, 2013 7:16 am     Reply with quote

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.
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Wed May 01, 2013 10:21 am     Reply with quote

Hi,

I noticed something missing in your code. Add this line after your #fuses line.

Code:

#use delay(clock=4000000)


John
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 01, 2013 11:25 am     Reply with quote

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
endazyar



Joined: 30 Apr 2013
Posts: 6

View user's profile Send private message

PostPosted: Wed May 01, 2013 11:53 am     Reply with quote

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.
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Wed May 01, 2013 12:11 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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