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

Lcd interfacing problem with pic16f877a
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
armghan11



Joined: 08 Jan 2013
Posts: 11

View user's profile Send private message

Lcd interfacing problem with pic16f877a
PostPosted: Fri Feb 15, 2013 1:45 am     Reply with quote

I bought 16x2 lcd module jhd162A.... i want to test a simple program by interfacing lcd with pic16f877a.

Here is the code

Code:
#include <16F877A.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)

#include <flex_lcd.c>

void main()
{
lcd_init();
delay_ms(250);
printf(lcd_putc,"Hello World");
output_high(Pin_C3);
while(true)
   {
   
   
   }
}


and this is the flex_lcd library file i am using

Code:
// flex_lcd.c

// These pins are for the Microchip PicDem2-Plus board,
// which is what I used to test the driver.  Change these
// pins to fit your own board.

#define LCD_DB4   PIN_B4
#define LCD_DB5   PIN_B5
#define LCD_DB6   PIN_B6
#define LCD_DB7   PIN_B7       

#define LCD_E     PIN_D6
#define LCD_RS    PIN_D7 

// If you only want a 6-pin interface to your LCD, then
// connect the R/W pin on the LCD to ground, and comment
// out the following line.

// #define USE_LCD_RW   1     

//========================================

http://www.ccsinfo.com/forum/viewtopic.php?t=24661

The program works fine on proteus but sadly i am not getting any output on hardware. Please help :(
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Fri Feb 15, 2013 1:55 am     Reply with quote

First thing, your delay wants to be _before_ the lcd_init, not afterwards. LCD's take a long time to wake up. Some nearly a second!. Proteus dos not simulate this properly.
Second triple check your chip is actually running, and running at the right speed. Do a simple flash LED program first, and time it. Proteus 'accepts what you tell it' about the clock, where the real processor requires this to be right. This will also check for obvious faults like MCLR not being pulled up.
Third _decoupling_. Capacitor(s) with really good HF performance, right close to the chip, and LCD connector. Again Proteus ignores problems here.
Fourth triple check the power connections. Proteus makes these 'automatically' for you, so they are easy to forget when looking at the schematic.

You can perhaps see 'why' we hate Proteus.....

Best Wishes
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Feb 15, 2013 8:02 am     Reply with quote

Seconded.

I also suggest you read the forum guidelines.

Mike
armghan11



Joined: 08 Jan 2013
Posts: 11

View user's profile Send private message

PostPosted: Fri Feb 15, 2013 11:54 am     Reply with quote

Thanks... i'll try it Smile
my code is ok?
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Fri Feb 15, 2013 1:24 pm     Reply with quote

What are you using for contrast control?

I recently had a problem with an LCD "not working" using Flex_Lcd, and the problem was contrast.

Some LCDs need a negative voltage for contrast, you can generate -v with a charge pump like i did.

The driver you are using is by member "PCMprogrammer" so based on my time on the forum, I'm gonna go ahead and say the problem is 99% certain to be hardware...or in your case, Proteus.

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Feb 16, 2013 8:02 am     Reply with quote

Quote:
The program works fine on proteus but sadly i am not getting any output on hardware. Please help :(

When you say "not getting any output on hardware", do you also mean that you are watching the output on pin_c3?

In which case, you really do need to do as Ttelmah says, your problem may or may not be contrast related.

Mike

EDIT. And remove Proteus.
armghan11



Joined: 08 Jan 2013
Posts: 11

View user's profile Send private message

PostPosted: Sat Feb 16, 2013 8:19 am     Reply with quote

Mike Walne wrote:
Quote:
The program works fine on proteus but sadly i am not getting any output on hardware. Please help :(

When you say "not getting any output on hardware", do you also mean that you are watching the output on pin_c3?

In which case, you really do need to do as Ttelmah says, your problem may or may not be contrast related.

Mike

EDIT. And remove Proteus.


yes on hardware i am getting high on pin_c3... but not any output on lcd.... may be a contrast problem... i am using 5k variable resistance to set contrast
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Feb 16, 2013 1:57 pm     Reply with quote

OK. So your PIC is running.

Have you checked:-

1) PIC is running at the correct speed, (simple LED flasher test)?
2) The LCD really is a single rail version, (there's a bewildering array of them)?
3) The connections to the LCD are correct, (again they are not all the same, I once laid out a board with the LCD all wrong, because I'd picked up the connections for a different, but closely numbered, device from the same manufacturer, very embarrassing)?
4) You've got a one second delay at the START of your code?
5) The data sheet timing requirements for your LCD, (once more, they vary, it may be worthwhile extending some of the delays to see what happens)?
6) The waveforms on the LCD pins with a 'scope?
7) You no longer have Proteus on your PC?

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Sat Feb 16, 2013 2:06 pm     Reply with quote

How have you got your Vee pot wired?.
I remember these displays. The data sheet shows a pot to ground, but they display nothing till you put about 4v on the Vee pin. Try a pot between the supply rails, with a 1K current limiting resistor to the pin.
Also you _have_ got the R/W pin on the LCD connected to ground?. This is needed.

Best Wishes
armghan11



Joined: 08 Jan 2013
Posts: 11

View user's profile Send private message

PostPosted: Sat Feb 16, 2013 3:26 pm     Reply with quote

Mike Walne wrote:
OK. So your PIC is running.

Have you checked:-

1) PIC is running at the correct speed, (simple LED flasher test)?
2) The LCD really is a single rail version, (there's a bewildering array of them)?
3) The connections to the LCD are correct, (again they are not all the same, I once laid out a board with the LCD all wrong, because I'd picked up the connections for a different, but closely numbered, device from the same manufacturer, very embarrassing)?
4) You've got a one second delay at the START of your code?
5) The data sheet timing requirements for your LCD, (once more, they vary, it may be worthwhile extending some of the delays to see what happens)?
6) The waveforms on the LCD pins with a 'scope?
7) You no longer have Proteus on your PC?

Mike


i will test this simple program tomorrow... added delay before the initializing LCD and led flashing to check speed.

Here is the code

Code:
#include <16F877A.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)

#include <flex_lcd.c>

void main()
{
delay_ms(2000);
lcd_init();
delay_ms(1000);
printf(lcd_putc,"Hello World");
delay_ms(250);
while(TRUE)
{
output_high(Pin_C3);
delay_ms(1000);
output_low(Pin_C3);
delay_ms(1000);
}
}
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

Indentation
PostPosted: Sun Feb 17, 2013 11:32 am     Reply with quote

If code is indented so that each closing } is immediately below its opening { you (and others) will find it much easier to follow.

Code:
void main()
{
  delay_ms(2000);
  lcd_init();
  delay_ms(1000);
  printf(lcd_putc,"Hello World");
  delay_ms(250);
  while(TRUE)
  {
    output_high(Pin_C3);
    delay_ms(1000);
    output_low(Pin_C3);
    delay_ms(1000);
  }
}

Mike
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Mon Feb 18, 2013 7:24 am     Reply with quote

Quote:
i am using 5k variable resistance to set contrast


... your described contrast control _may_ be wrong.
(depending on the LCD)

i had the same setup with my LCD and that did not work since the LCD required -Ve for contrast. i generated a -v using a charge pump... quite simple.


Code:
              D1
GND o--------|<---o                   
                  |
                  |
            C1    |  D2
PUMP o------|[----o--|<-----o
PIN                         |
                      C2    |
               o------|[----o---------o V-               
              _|_
              GND


Note the polarity of components.
you can add an aditional RC filter on V-.... i did
(its really hard to draw in text so i didnt add it here)

use only real hardware... forget proteus.



EDIT:
Looking at your code, if you implement the CHPump you could _for Testing only_ replace:

Code:
output_high(Pin_C3);
delay_ms(1000);
output_low(Pin_C3);
delay_ms(1000);


with

Code:
output_toggle(Pin_C3);
delay_ms(1);


and have C3 = PUMP PIN

afterwards you should try to use PWM to control the CHPump.


ALSO:

this is the original Test program for 16x2:
Code:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

#include "flex_lcd.c"
   
//==========================
void main()
{
lcd_init();  // Always call this first.

lcd_putc("\fHello World\n");
lcd_putc("Line Number 2");

while(1);
}



why did you change it to this:

Code:
printf(lcd_putc,"Hello World");




try this:

Code:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

#include "flex_lcd.c"
   
//==========================
void main()
{
lcd_init();  // Always call this first.

lcd_putc("\fHello World\n");
lcd_putc("Line Number 2");

while(1)
{
output_toggle(Pin_C3);
delay_ms(1);
}
}



note ive included my modification to drive the charge pump (temporarily)

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
armghan11



Joined: 08 Jan 2013
Posts: 11

View user's profile Send private message

PostPosted: Sat Mar 02, 2013 8:16 am     Reply with quote

Gabriel wrote:
Quote:
i am using 5k variable resistance to set contrast


... your described contrast control _may_ be wrong.
(depending on the LCD)

i had the same setup with my LCD and that did not work since the LCD required -Ve for contrast. i generated a -v using a charge pump... quite simple.


Code:
              D1
GND o--------|<---o                   
                  |
                  |
            C1    |  D2
PUMP o------|[----o--|<-----o
PIN                         |
                      C2    |
               o------|[----o---------o V-               
              _|_
              GND


Note the polarity of components.
you can add an aditional RC filter on V-.... i did
(its really hard to draw in text so i didnt add it here)

use only real hardware... forget proteus.



EDIT:
Looking at your code, if you implement the CHPump you could _for Testing only_ replace:

Code:
output_high(Pin_C3);
delay_ms(1000);
output_low(Pin_C3);
delay_ms(1000);


with

Code:
output_toggle(Pin_C3);
delay_ms(1);


and have C3 = PUMP PIN

afterwards you should try to use PWM to control the CHPump.


ALSO:

this is the original Test program for 16x2:
Code:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

#include "flex_lcd.c"
   
//==========================
void main()
{
lcd_init();  // Always call this first.

lcd_putc("\fHello World\n");
lcd_putc("Line Number 2");

while(1);
}



why did you change it to this:

Code:
printf(lcd_putc,"Hello World");




try this:

Code:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

#include "flex_lcd.c"
   
//==========================
void main()
{
lcd_init();  // Always call this first.

lcd_putc("\fHello World\n");
lcd_putc("Line Number 2");

while(1)
{
output_toggle(Pin_C3);
delay_ms(1);
}
}



note ive included my modification to drive the charge pump (temporarily)

G.


Lcd is working fine when i use Mikro C compiler! so its not a hardware problem anymore. this is something to do with code and burner! Today i tried simple led blinking program with 1sec delay between on and off. but it was not showing correct delay with ccs c compiler but when i wrote the same code on mikro c it was working like a charm.

Can this be a burner problem ? I am using Genius Programmer G540. is it not compatible with ccs c ?
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Sat Mar 02, 2013 8:54 am     Reply with quote

if you can program your pic with a blink LED program then its not a programmer problem.
_________________
CCS PCM 5.078 & CCS PCH 5.093
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Sat Mar 02, 2013 8:55 am     Reply with quote

i just noticed this:

Code:
#define LCD_DB6   PIN_B6
#define LCD_DB7   PIN_B7   


Those are the Clock and Data pins for programming...

if not properly isolated, your pic might not program correctly or at all..

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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