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

Simple LCD interface, 4-bit using Project Wizard example

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



Joined: 13 Apr 2009
Posts: 5
Location: Melbourne, Florida

View user's profile Send private message Send e-mail

Simple LCD interface, 4-bit using Project Wizard example
PostPosted: Tue Aug 04, 2009 9:40 am     Reply with quote

I built a simple LCD interface circuit, using a PIC16LF84A @ 4MHz with port b dedicated to the 4-bit interface and a working 2x16 LCD display.

Using the Project Wizard, I selected "use LCD" driver, ticked off the "example code" box, and it added the following statement:

Code:
lcd_putc("\fReady....\n");


Looking at the lcd_putc() procedure in LCD.C (the LCD driver code) it is clearly displays a single character at a time. The procedure lcd_putc() should only output one character, in this statement the '\f'. Here is the the lcd_putc() code:

Code:
void lcd_putc(char c) {           
   switch (c) {
     // Clear the display
     case '\f'   : lcd_send_byte(0,1);
                   delay_ms(2);
                   break;
     // move the cursor to line 2, first character
     case '\n'   : lcd_gotoxy(1,2);
                   break;
     // move the cursor to the left one character
     case '\b'   : lcd_send_byte(0,0x10);
                   break;
     default     : lcd_send_byte(1,c);
                   break;
   } // end switch(c)
}  // end procedure lcd_putc()


How is this statement supposed to display the "Ready..." message? Am I missing something?

My display doesn't output anything at this point, and in addition to a code question I may have wiring problems but I would like to understand what the example was expected to do.

David
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Tue Aug 04, 2009 9:55 am     Reply with quote

Am I the first Smile

CCS compiler has a special built in ability.
When presented with a function with a single char parameter and called with a const string the CCS compiler will iterate throught the string calling the function once for each char.

If you look in the LCD file you will also notice that there is an equivilant but slower function for sending strings.

So yes it will work!
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Aug 04, 2009 11:37 am     Reply with quote

Also remember that \f and \n are understood by the compiler to be escaped chars. (or in other words, what's the hex/dec equiv of this defined escape sequence)

So you don't want to send a '\' and an 'n', but those are understood to be a single ASCII non-viewable char.

typically \r\n means to send a CR/LF combo.

If you'd like to read all about it:
http://en.wikipedia.org/wiki/Newline

lastly, if you think about it (and read the datasheet for the LCD's controller), all transactions to the LCD are 1byte at a time. In the case of a character LCD, that might be a Char at a time, with a graphics LCD, that might be 1dot (or multiple) at a time.

In the case of the nibble wide bus (4bits) each char/byte takes 2 transactions!!

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Guest








PostPosted: Tue Aug 04, 2009 11:47 am     Reply with quote

Wayne_ wrote:
Am I the first Smile

CCS compiler has a special built in ability.
When presented with a function with a single char parameter and called with a const string the CCS compiler will iterate throught the string calling the function once for each char.

If you look in the LCD file you will also notice that there is an equivilant but slower function for sending strings.

So yes it will work!


OK, that's cool. which file contains that routine? I looked in LCD.C and only found:

lcd_putc()
lcd_init()
lcd_getc()
lcd_gotoxy()
lcd_read_byte()
lcd_send_nibble()
lcd_send_byte()


I wrote a "lcd_puts()":

Code:
void lcd_puts(char *inString) {
   unsigned char index = 0;

   while (inString[index] != NULL) {
      lcd_putc(inString[index++]);                         
   } // end while(there are characters to output)
 
} // end procedure lcd_puts(inString)



This code works on another C-Compiler (Dev C/C++on my PC in console mode) . Like I said, I may have a wiring problem (solder-less breadboards can be flaky, along with the builder ;) or a port location problem. I will try it and report back.

Thanks for the reply,

David
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Aug 04, 2009 11:51 am     Reply with quote

To elaborate what Wayne said already, CCS has already done the work for you...


Code:

printf(lcd_putc, "This is my string\r\b");


or even
Code:

unsigned char string[20];

sprintf(string, "My reading: 0x%02X\r\n", somevar);
printf(lcd_putc, "%s", string);


This is in the CCS manual under printf and sprintf

-Ben

P.s. START SIMPLE to get your LCD working. A lot of the problems start with wiring. Make sure you have all the lines hooked up. In a lot of cases (because the Hitachi 44780) was so popular, you need, E, RS, RW, D4:7 for 4 bits. If you don't have the contrast and +5/GND hooked up right, it won't work either. :D
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Wed Aug 05, 2009 2:01 am     Reply with quote

Quote:
If you look in the LCD file you will also notice that there is an equivilant but slower function for sending strings.


Yes sorry about that, I was thinking of something else.
dk-info



Joined: 13 Apr 2009
Posts: 5
Location: Melbourne, Florida

View user's profile Send private message Send e-mail

Thanks for the LCD help!
PostPosted: Wed Aug 05, 2009 9:39 am     Reply with quote

Thanks to all who helped, the simple LCD is now working. The short points:

    Make sure to un-comment the (#define use_portb_lcd TRUE) port definition in lcd.c when using a device with the lcd connected to port b
    In the project wizard, do not select both the LCD driver, and the "use LCD" options.
    Insure the Vee voltage is set to make the characters viable. (A 10k pot between Vdd and Vss works great)
    Insure the interface code matches your interface, (i.e. nibble/byte)
    Insure the control signals and data bits are within the same port, and match the structure "lcd_pin_map"


This is a great forum, and with the kind help of the forum members, made a frustrating experience easier.

David
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