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

LCD05 i2c LCD 4x20

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



Joined: 19 Oct 2013
Posts: 6

View user's profile Send private message

LCD05 i2c LCD 4x20
PostPosted: Fri Dec 06, 2013 1:39 pm     Reply with quote

Hi all,

I'm using this LCD
http://www.robot-electronics.co.uk/htm/Lcd05tech.htm

And using code above. I think I've a data type conversion problem (float to string array). In this case I want to show max_temp on the LCD. MESSAGE_LCD() function works properly. Any suggestions ?

Code
Code:
#include <16F877.h>
#DEVICE PASS_STRINGS=IN_RAM

#include <string.h>

#fuses XT,NOWDT,NOPROTECT,NOLVP,BROWNOUT

#use delay(clock=4000000)

#use standard_io(C) 
#use standard_io(B)
#use standard_io(A)

float max_temp;
char txt[20];

#include "LCD05_i2c.c"

void main()
{
   clear_lcd();
   message_lcd();
   show_cursor();

   max_temp = 25.16;
   
   while(1)
   {
      light_lcd();
      delay_ms (500);
      clear_lcd();
      text_on_lcd ((char)max_temp);
  }
}


And LCD driver
Code:
/************************************************************/
/*           G L O B A L   V A R I A B L E S                */
/************************************************************/
int LCD03_ID   =  0xC6;   // I2C addrres for LCD03
char text[20];
char texto[20];
int i;                    // text buffer pos
int n;                    // Char number
short int light;          // Turn ON-Off display light
int command;              // LCD Command
int row;                  // Row PosiciĆ³n
int line;                 // Line Position
int contrast;

/************************************************************/
/*                 F U N C T I O N S                        */
/************************************************************/

void cursor_lcd(LCD03_ID, line, row);
void write_lcd(byte LCD03_ID);
void command_lcd ( byte LCD03_ID, byte command );
void light_lcd ();
void clear_lcd ();
void carrier_return ();
void text_hello ();
void text_on_lcd();
void message_lcd();
void text_lcd();

/******************** FUNCTION write TEXT LCD **************************/

void write_lcd(byte LCD03_ID)
{
   for ( i=0; i<n; i++) {
   
         i2c_start();              // Start i2c communication ...
         i2c_write(LCD03_ID);      //...with LCD03 address ...
         i2c_write(0);             //...poiting to zero pos on the LCD03 register
         i2c_write(text[i]);       //...write char into i position on text[i]
         i2c_stop ();              // ending transmission
         delay_ms(10);
      }
}
   
/********************* FUNTCION write command LCD **************************/

void command_lcd ( byte LCD03_ID, byte command )
{
   i2c_start();                  // Start i2c communication ...
   i2c_write(LCD03_ID);          //...with LCD03 address .....
   i2c_write(0);                 //...poiting to zero pos on the LCD03 register
   i2c_write(command);           //...write action
   i2c_stop ();                  // ending transmission
}

/***************** FUNCTION TURN ON-OFF display light ************************/
   
void light_lcd ()
{
   light=light+1;                      // Swap light state
   if (light==1) command=19;           // turn on light command
   else command=20;                    // turn off light command
   command_lcd(LCD03_ID, command);     // Send action to LCD
   delay_ms(300);                     
}

/********************** FUNCTION clear DISPLAY ********************************/

void clear_lcd ()
{
   command=12;                         // clear display command
   command_lcd(LCD03_ID, command);     // Send action to LCD
   delay_ms(150);                     
}

/******************* FUNCTION clear previou char *************************/

void clear_character ()
{
   command=8;                          // clear display command
   command_lcd(LCD03_ID, command);     // Send action to LCD
   delay_ms(300);                     
}

/*********************** FUNCTION HIDE CURSOR *******************************/

void clear_cursor ()
{
   command=4;                          // Hide cursor command
   command_lcd(LCD03_ID, command);     // send action to LCD
   delay_ms(150);                     
}

/*********************** FUNCTION SHOW CURSOR *******************************/

void show_cursor ()
{
   command=6;                          // Show cursor command
   command_lcd(LCD03_ID, command);     // Send action to LCD
   delay_ms(150);                     
}

/********************** FUNCTION CARRIER RETURN ******************************/

void carrier_return ()
{
   command=13;                         // LCD Carrier Return command
   command_lcd(LCD03_ID, command);     // Send action to LCD
   delay_ms(300);                     
}

/********************* FUNCTION CONTRAST *********************************/
void  lcd_contrast (contrast)
{
   i2c_start();                  // Start i2c comunication ...
   i2c_write(LCD03_ID);          // ...with LCD03 address...
   i2c_write(0);                 // ... pointing into zero register position on LCD03
   i2c_write(30);                 // cursor position ... 
   i2c_write(contrast);               // ... and row
   i2c_stop ();                  // End transmission
}

/********************* FUNCTION LCD_TYPE *********************************/

void  lcd_type (void)
{
   i2c_start();                  // Start i2c comunication ...
   i2c_write(LCD03_ID);          // ...with LCD03 address...
   i2c_write(0);                 // ... pointing into zero register position on LCD03
   i2c_write(24);                 // cursor position ... 
   i2c_write(3);               // ... and row
   i2c_stop ();                  // End transmission
}

/********************* FUNCTION write TEXT ********************************/

void text_hello (line, row)
{
   strcpy (text, "Hello");                   // First Line Text
   n=strlen(text);                           // Getting number of chars
   cursor_lcd (LCD03_ID, line, row);         // Send cursor position
   write_lcd (LCD03_ID);                     // Send first line text
}

/************************* FUNCTION TEXT_ON_LCD*******************************/
void text_on_lcd (text)
{
   strcpy (texto, text);                        // First Line tex
   n=strlen(texto);                             // Get number of chars
   row=((20-n)/2)+1;                            // Centered Text position
   line=1;                                      // ... in the first line
   cursor_lcd (LCD03_ID, line, row);            // Send cursor position
   write_lcd (LCD03_ID);                        // Send text on the first line
}

/********************* FUNCTION MESSAGE *********************************/

 void message_lcd()
 {
   
   strcpy (text, "This is a");              // First Line text
   n=strlen(text);                          // Get number of chars
   row=((20-n)/2)+1;                        // Centered Text position
   line=1;                                  // ... in the first line
   cursor_lcd (LCD03_ID, line, row);        // Send cursor position
   write_lcd (LCD03_ID);                    // Send text on the first line
   
   strcpy (text, "welcome message");         // second line text
   n=strlen(text);                           // Get number of chars
   row=((20-n)/2)+1;                         // Centered Text position
   line=2;                                   // ... on the second line
   cursor_lcd (LCD03_ID, line, row);         // Send cursor position
   write_lcd (LCD03_ID);                     // Send text on the second line
 
   strcpy (text, "--------------------");    // on the fourth line
   n=strlen(text);                           // Get number of chars
   row=((20-n)/2)+1;                         // Centered Text position
   line=3;
   cursor_lcd(LCD03_ID, line, row);          // Send cursor position
   write_lcd (LCD03_ID);                     // Send text on the fourth line
 
   strcpy (text, "PIC (c)");                 // on the fourth line
   n=strlen(text);                           // Get number of chars
   row=((20-n)/2)+1;                         // Centered Text position
   line=4;
   cursor_lcd(LCD03_ID, line, row);          // Send cursor position
   write_lcd (LCD03_ID);                     // Send text on the fourth line
   
 }
 
/********************** FUNCTION CURSOR POSITION *****************************/

void cursor_lcd (byte LCD03_ID, byte line, byte row)
{
   i2c_start();                  // Start i2c comunication ...
   i2c_write(LCD03_ID);          // ...with LCD03 address...
   i2c_write(0);                 // ... pointing into zero register position on LCD03
   i2c_write(3);                 // cursor position ... 
   i2c_write(line);              // ...on line...
   i2c_write(row);               // ... and row
   i2c_stop ();                  // End transmission
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Dec 07, 2013 12:22 am     Reply with quote

Quote:
I think I've a data type conversion problem (float to string array).

Use the sprintf() function. Example:
http://www.ccsinfo.com/forum/viewtopic.php?t=28842
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