View previous topic :: View next topic |
Author |
Message |
armghan11
Joined: 08 Jan 2013 Posts: 11
|
Lcd interfacing problem with pic16f877a |
Posted: Fri Feb 15, 2013 1:45 am |
|
|
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
|
|
Posted: Fri Feb 15, 2013 1:55 am |
|
|
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
|
|
Posted: Fri Feb 15, 2013 8:02 am |
|
|
Seconded.
I also suggest you read the forum guidelines.
Mike |
|
|
armghan11
Joined: 08 Jan 2013 Posts: 11
|
|
Posted: Fri Feb 15, 2013 11:54 am |
|
|
Thanks... i'll try it
my code is ok? |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Fri Feb 15, 2013 1:24 pm |
|
|
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
|
|
Posted: Sat Feb 16, 2013 8:02 am |
|
|
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
|
|
Posted: Sat Feb 16, 2013 8:19 am |
|
|
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
|
|
Posted: Sat Feb 16, 2013 1:57 pm |
|
|
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
|
|
Posted: Sat Feb 16, 2013 2:06 pm |
|
|
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
|
|
Posted: Sat Feb 16, 2013 3:26 pm |
|
|
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
|
Indentation |
Posted: Sun Feb 17, 2013 11:32 am |
|
|
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
|
|
Posted: Mon Feb 18, 2013 7:24 am |
|
|
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
|
|
Posted: Sat Mar 02, 2013 8:16 am |
|
|
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
|
|
Posted: Sat Mar 02, 2013 8:54 am |
|
|
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
|
|
Posted: Sat Mar 02, 2013 8:55 am |
|
|
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 |
|
|
|