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

16x2 lcd not working

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



Joined: 19 Jun 2009
Posts: 7

View user's profile Send private message

16x2 lcd not working
PostPosted: Mon Aug 17, 2009 2:35 am     Reply with quote

Hi PCM Programmer, I've been trying to work a 16x2 lcd and have used your flex driver. However, nothing can be displayed on my screen. These are my connections:
Code:
#define LCD_DB4   PIN_D0
#define LCD_DB5   PIN_D1
#define LCD_DB6   PIN_D2
#define LCD_DB7   PIN_D3

#define LCD_E     PIN_C1
#define LCD_RS    PIN_C3
#define LCD_RW    PIN_C2


and my test program:
Code:
#include <16F877.H>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

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

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

while(1);
}

Apart from the connection pins, I did not change anything. Seeing that others had got theirs working on the first try, I doubt that the problem lies with the codes, but perhaps my configurations?

I'm using PIC16f877a, with 20Mhz HS oscillator.
My lcd module is S162COG series, version 1.0, from Displaytech Ltd (manufacture part number: 162COG-BA-BC).
Also, I'm using the compiler version 4.096.

Hope to hear from you soon, thanks!

regards,
Jou
Ttelmah
Guest







PostPosted: Mon Aug 17, 2009 10:06 am     Reply with quote

Obvious comment.
What have you got connected to the Vee.

Best Wishes
jou_c



Joined: 19 Jun 2009
Posts: 7

View user's profile Send private message

PostPosted: Mon Aug 17, 2009 6:20 pm     Reply with quote

Vss - GND
Vo -5V
Vdd - 5V
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 18, 2009 9:27 am     Reply with quote

Quote:

Vss - GND
Vo - 5V
Vdd - 5V

The contrast voltage Vo should be set to about 0.5 volts. Do that with
a 10K trimpot or a voltage divider built from discrete resistors. Then
you should see something on your LCD.
Guest








PostPosted: Wed Aug 19, 2009 3:39 am     Reply with quote

Hi PCM Programmer, thanks for the advice! I've used the voltage divider to get 0.5V and I can now see some display!

However... there are some problems. I'm guessing it's about the clock frequency.

Declaring the clock freq of 20MHz and 16Mhz, I only get the first 9 characters of the 1st line, i.e "Hello Wor";
Declaring 4Mhz, gives me "Line Numb" on the 1st line of the LCD;
Declaring 10Mhz gives me some funny characters on the 1st line and "Line Numb" on the second line.

Some changes that I made to the code after some testings:
Code:
#include <16F877.H>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 20000000) // this is the thing i've been playing around
#include "flex_lcd_1.c"
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

and i added
Code:
set_tris_c(0x00);
set_tris_d(0x00);

to my main function. That's all I changed.

One thing to note:
The LCD only displayed a maximum of 9 characters for every clock frequency that I tried.

Any idea why is doing that? How should I fix this problem???

Regards,
Jou
Ttelmah
Guest







PostPosted: Wed Aug 19, 2009 4:14 am     Reply with quote

What _is_ your clock frequency.

Clock, is not something you 'play around with', it _must_ be set to match the real frequency the chip is running at....

This is information given _to_ the compiler to tell it, what clock your processor is using, so it can adjust timings etc., appropriately.

There are 'rare' occasions when you can set the clock value to the wrong frequency, to 'tweak' something by a tiny factor (usually the serial settings), but this should _only_ be done, if you know what you are doing, and understand the implications. The first thing for you to do, is to look at your hardware, and identify what the actual clock frequency _is_. Then the clock, and fuse settings will need to be made to match this....

Best Wishes
jou_c



Joined: 19 Jun 2009
Posts: 7

View user's profile Send private message

PostPosted: Thu Aug 20, 2009 6:48 am     Reply with quote

Hi, thanks for your reply Ttelmah!

My oscillator frequency is 20Mhz. I've changed my clock frequency to 20 Mhz accordingly... but it's still displaying only a maximum of 9 characters per line!

And, if the characters in the 1st line is suppose to be more than 9 characters, then the 2nd line won't display at all!

Also, can I know what is how to change screen?

I'm writing my codes to do things like this:
Code:
 void main(){
lcd_init();
.// some codes here...
.
lcd_putc("\fsomething");
.
. // some codes here
.
lcd_putc("\fsomething\n"); // ****
lcd_putc("else");
.
. // other codes here again
.
}

When I run the codes, it always stop at the line marked ****!
Pls may I know what's the problem? I tried using lcd_send_byte(0,1) just before my second lcd_putc() but it also got stuck at that line.

Any help would be most welcomed.

Regards,
Jou
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Aug 20, 2009 11:00 am     Reply with quote

Quote:
When I run the codes, it always stop at the line marked

When I experience similar problems, I check, where the code actually hangs. Most likely, you have a hardware problem with your LCD interface (or a defective display) and the flex_lcd busy check waits forever.

You also reported to have added some changes to the simple flex_lcd test code. You may want to go back to the original code, just to check if you applied some dubious modification.
jou_c



Joined: 19 Jun 2009
Posts: 7

View user's profile Send private message

PostPosted: Thu Aug 20, 2009 6:59 pm     Reply with quote

The changes I made was to set up the clock frequency as previously advised by Ttelmah and to change the port pins for my application. Other than that, I did not change anything in the flex_lcd.

Anyway, just to check, I copy and paste the codes of the original flex lcd into my codes and it still does the same thing. IT WILL NOT DISPLAY PAST THE 9TH CHARACTER!

Basically, that's my biggest problem right now.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 20, 2009 7:57 pm     Reply with quote

Quote:
I'm writing my codes to do things like this:
Code:
void main(){
lcd_init();
.// some codes here...
.
lcd_putc("\fsomething");
.
. // some codes here
.
lcd_putc("\fsomething\n"); // ****
lcd_putc("else");
.
. // other codes here again
.
}

When I run the codes, it always stop at the line marked ****!

You have made a complicated test file. It's much more complicated than this:
Code:

#define LCD_DB4   PIN_D0
#define LCD_DB5   PIN_D1
#define LCD_DB6   PIN_D2
#define LCD_DB7   PIN_D3

#define LCD_E     PIN_C1
#define LCD_RS    PIN_C3
#define LCD_RW    PIN_C2


#include <16F877.H>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

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

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

while(1);
}



Quote:
I tried using lcd_send_byte(0,1) just before my second lcd_putc() but it also got stuck at that line.

and i added
Code:
set_tris_c(0x00);
set_tris_d(0x00);

You have made these changes and possibly more.

Get rid of all those changes and run the simple test program shown above.
What is the result ? Post it.
jou_c



Joined: 19 Jun 2009
Posts: 7

View user's profile Send private message

PostPosted: Thu Aug 20, 2009 9:31 pm     Reply with quote

This is the result I get on my using the simplest test program that you've shown:

"Hello Wor"

and if I change my codes to display "Hello" on the first line and "World" on the second, I get the correct result:

"Hello"
"World"

regards,
Jou
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 21, 2009 1:36 am     Reply with quote

I think there may be two problems. Try doing the first fix below.
If that doesn't solve the problem, then also do the 2nd fix shown below.

1. Vs. 4.013 is a defective version. It has problems with sending text
using lcd_putc (and maybe also with printf). It incorrectly sends a
0x00 byte at the end of the string. A suggested fix for this problem
for the flex lcd driver is shown in this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=24661&start=74


2. It's possible that the "busy bit" for your LCD may not work properly
when the LCD is operated in 4-bit mode (i.e., the normal mode we use
in the embedded microcontroller world). One possible solution for this
problem is to replace the "busy bit" polling loop with a fixed delay.
To do this in the Flex driver:

A. Comment out this line in the flex_lcd.c file, as shown below:
Quote:
// #define USE_LCD_RW 1


B. Set the R/W line to a low level before lcd_init() is called.
Do this by adding the line shown in bold below:
Quote:
void main()
{
output_low(LCD_RW);
lcd_init(); // Always call this first.

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

while(1);
}

Instead of adding this line, you could also remove the connection between
the lcd R/W pin and the PIC. Then connect the lcd's R/W pin to Ground.
jou_c



Joined: 19 Jun 2009
Posts: 7

View user's profile Send private message

PostPosted: Fri Aug 21, 2009 3:42 am     Reply with quote

Hi PCM Progammer,
Thanks for the solution! My LCD is now working well already! Although I should inform you that I had to do both things suggested by you to solve my problem.

If this is a persistent problem for the partcular compiler version, may i suggest you make a note to your code so that users of these compilers won't have to face my problem again! :D

Once again, thanks to those who have helped. I am still working on my project, hopefully I'll be able to solve all my remaining problems... else, I hope you guys won't mind me bothering again Smile

Regards,
Jou
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 21, 2009 11:55 am     Reply with quote

Quote:
may i suggest you make a note to your code so that users of these compilers

I'm not sure what you mean by this. I don't work for CCS. That is an
old version. It's known to be junk. You get what you pay for. Just saying.
jou_c



Joined: 19 Jun 2009
Posts: 7

View user's profile Send private message

PostPosted: Sat Aug 22, 2009 4:10 am     Reply with quote

PCM Programmer,

I'm sorry if i offended you in any way. let it be clear that that was not my intention at all. What i meant was to make a little note about this problem in your flex_lcd codes, for the benefit of those who have got the old version.

Actually the version i'm using is 4.096, not 4.013. I'm using the demo version though... still in the midst of trying it out:)

Regards
Jou
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