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 support@ccsinfo.com

Serial LCD driver help needed

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








Serial LCD driver help needed
PostPosted: Fri Mar 02, 2007 3:03 pm     Reply with quote

I have a serial LCD which requires commands to clear the screen, home, go to line 2, etc. I'm using the PIC16F877A development kit and the PIC MCU C Compiler. I'm not using the built in RS232 on the kit as it is true RS232 and not TTL logic levels. The RS232 input on the LCD is not true RS232 but logic levels.

The LCD requires an ASCII 254 to prep it for the next command, such as ASCII 1, to clear the screen.

I use the following code:

#define lcd 254
#define clr 1

putc(lcd);
delay_ms(1);
putc(clr);
delay_ms(1);
printf("Hello");

and all I get is a scramble.

When I use the watch function to look at lcd, I see it is set to -2. And when I look at clr, I see it set to 1. Now what am I really sending to the LCD? If it is really a -2, then I can see why it doesn't work. When I look at it using the monitor function of the compiler, I see a while block, which I assume represents a non-printable character. But which one, -2 or 254?

I must be doing something basically stupid, but I can't figure it out.

I've tried all cominbations of bit count, parity, baud rate, invert and the like and I can't get it to work.

Help! Sad
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 02, 2007 3:25 pm     Reply with quote

1. Post the manufacturer and part number of your LCD.
Post a link to the website for it.

2. Post a complete test program that includes your posted code,
but that also shows the #include for the PIC, and the #fuses
statement, and the #use rs232 statement. This test program
will be basically what you have already posted, but will be
"complete", so that it can be compiled with no editing required.

3. Post your compiler version.
Ttelmah
Guest







PostPosted: Fri Mar 02, 2007 3:26 pm     Reply with quote

You are sending what you expect.
The problem with what you are seeing, is in the 'watch' setup. You have it set to display the value as a _signed_ value. In signed 8bit notation, -2, is 0b11111110. In unsigned notation, this is 254.
Now the fault then lies in the settings for the communication with the LCD. You say you have tried all possibilities. Are you dead sure you have your _clock_ definition right. This is critical, since it sets how the baud rate values work. If (for instance), you have a real clock at 6MHz, and the definition says '8000000', then if you setup to send data at 9600bps, it'll really be sent at 7200bps, and won't work if the other end expects 9600bps. I'd also be looking carefully at the connections. What pins are you using for the serial?. One 'classic', would be if you are using RA4, which must have a pull-up resistor, for use as an output. Whose is the display?.

Best Wishes
Guest








PostPosted: Fri Mar 02, 2007 3:43 pm     Reply with quote

In the #USE RS232 syntex options, I used BRGH10K which is supposed to take care of small bit rate problems.

I would like to set a variable to "unsigned" but the Data Definitions section of the compiler manual does not show this to be an option. I'm using version v3.190 of he PCW compiler.
alchazz



Joined: 03 Oct 2006
Posts: 13

View user's profile Send private message

PostPosted: Fri Mar 02, 2007 4:07 pm     Reply with quote

OK, looks like I missed one reply. My project consists of over 8 pages of C code. All works like it's supposed to. I left the LCD driver for last as it was supposed to be trivial, just doing what I had explained in the original post. I had been using the "monitor" function of the debugger for my output. It kept the parts count down in the breadboard.

I suppose I will have to write a short program to test the RS232 interface to the serial LCD and try that out.

So, how does one send ASCII characters between 128 and 256 if an unsigned character is needed and there is no provision in the compiler that I see?

BTW, the serial LCD is a BPI-216 and the site is:

http://www.seetron.com/slcds.htm
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 02, 2007 5:05 pm     Reply with quote

Quote:

I'm using the PIC16F877A development kit and the PIC MCU C Compiler.
I'm not using the built in RS232 on the kit as it is true RS232 and not TTL
logic levels. The RS232 input on the LCD is not true RS232 but logic levels.

Here's the manual for the BPI-216 LCD:
http://www.seetron.com/pdf/bpi_bpk.pdf
On page 3, it says:
Quote:

Figure 3 shows how to connect the BPI-216 to PCs

PC Serial (comm) Port

They show a DB-9 connector on the back of your PC, and they show
how to connect it directly to the BPI-216. You could do this, and thus
prove that the LCD is working OK.


They also have this important note on a required start-up delay:
Quote:

Startup Time
When the BPI-216 is first powered up, it requires about 750 milliseconds
(ms) to initialize the LCD and get ready to receive data. Programs
should wait about a second after powerup before sending data to the
BPI-216.


That's why I wanted you to post a test program.

See this post. It shows what I mean by a short test program.
http://www.ccsinfo.com/forum/viewtopic.php?t=29376&start=3
It could even be shorter than that.
alchazz



Joined: 03 Oct 2006
Posts: 13

View user's profile Send private message

PostPosted: Fri Mar 02, 2007 5:41 pm     Reply with quote

I do the delay before the write to the serial LCD. I did read the manual. Maybe I'll fire up my BASIC Stamp and see if it works with that.

The module does a self test at power up and displays a message. Of course, this doesn't prove that the input works, but the odds are very good that it does.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 02, 2007 5:48 pm     Reply with quote

Quote:
The module does a self test at power up and displays a message

Is this a one-time test that you did, or does the LCD do this every time
you power it up ?

The manual says you have to specifically jumper it for the Test mode
(and then remove the jumper when done with testing).
Quote:

Quick Checkout and Contrast Adjustment
You can test the unit for proper operation without a computer/serial port.
Temporarily connect the serial input to one of the +5 terminals of J1,
then connect power to +5 and GND. The LCD will display a test message.
Ttelmah
Guest







PostPosted: Sat Mar 03, 2007 3:35 am     Reply with quote

In CCS, an int, is unsigned by default. It is the 'watch', that is making the decision that this binary value represents a signed number. The same happens with the internal printf.
Code:

   int i=254;
   signed int j=-2;
   printf("%d %d/n/r",i,j);
   //This will print -2 -2
   printf("%u %u/n/r",i,j);
   //This will print 254 254

Note that though the numbers are 'declared' as signed, and unsigned respectively, and then initialised with a signed, and an unsigned value, it is the output representation selection, which decides what you see. If these were sent on the serial, as 'raw' characters (using putc), the same bit pattern is sent for each.

Best Wishes
Guest








PostPosted: Sat Mar 03, 2007 11:24 am     Reply with quote

OK, thanks for the info on the default for the CCS compiler. So I got confused by what the "watch" showed.

As for the LCD module, it does display the message upon power up every time. But then again, the input fo the LCD is connected to a development kit output. If all it requires is +5 at the serial input pin to cause it to go into a test mode, then it doesn't matter if it is a logic high or the power connection which does it. It must be then that the development board outputs must be high when it powers up thereby sending the LCD into a test mode.

One other question. The serial characteristics of the LCD are that the baud rate should be 9600, which is what I have chosen for the PIC RS232 output, and no parity, 8 bits, and 1 stop bit. But, the compiler does not give an option in the #use RS232 for a stop bit. It does give the option of setting bits. So should I set the bit option to 8 or 9? I imagine that the 9 choice would include the 8 bit ASCII and the 1 bit stop bit?
Guest








PostPosted: Mon Mar 05, 2007 2:26 pm     Reply with quote

Hah, Very Happy I finally soved the problelm. When I push the reset button on the development system after I hit the debugger button on the IDE and before I start the program, it works. HUH? Rolling Eyes

Does hitting the reset button "flush" the pinouts on the development system? At this point, I'm pushing on with the project and not debugging the development system.
alchazz



Joined: 03 Oct 2006
Posts: 13

View user's profile Send private message

PostPosted: Tue Mar 06, 2007 3:12 pm     Reply with quote

This finally worked.
Code:

// LCD test example for a serial LCD Module
// Part Number BPI-216
// Scott Edwards Electronic, Inc.
// www.seetron.com

#include <16F877A.h>
#device  ICD=TRUE
#fuses   HS,NOLVP,NOWDT,PUT
#use     delay (clock=20000000)

#include <stdlib.h>
// #use RS232 (debugger)  //baud=9600, xmit=PIN_C6, rcv = PIN_C7
 #use RS232 (baud=9600, parity = N, bits = 9, invert, brgh1ok, xmit=PIN_D0)

#define lcd           254   // command is next
#define clr           1     // clear screen and home
#define home          2     // home
#define line1         128   // goto beginning of line 1
#define line2         192   // goto beginning of line 2

void clear_display()
  {
    putc(lcd);
    delay_ms(2);
    putc(clr);
    delay_ms(20);
  }                         // end of clear_display

void goto_line1()
  {
    putc(lcd);
    delay_ms(2);
    putc(line1);
    delay_ms(20);
  }                         // end of goto_line1

void goto_line2()
  {
    putc(lcd);
    delay_ms(2);
    putc(line2);
    delay_ms(20);
  }                         // end of goto_line2

void go_home()
  {
    putc(lcd);
    delay_ms(2);
    putc(home);
    delay_ms(20);
  }                         // end of go_home

void main()
{
   int n;

   delay_ms(1000);  // wait for LCD
   clear_display();
   printf("1234567890123456");

   for (n=1;n < 12; n++)
    {
     goto_line2();
     printf("%02d              ",n);
     delay_ms(1000);
    }

 }   // end main
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