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

LCD HD44780 PCF8574T i2c Driver
Goto page Previous  1, 2, 3, 4, 5, 6  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
nilohdez



Joined: 12 Dec 2013
Posts: 1

View user's profile Send private message

LCD HD44780 PCF8574T i2c Driver
PostPosted: Thu Dec 12, 2013 9:09 pm     Reply with quote

Hello Hugo, PCM and ...others:
I have a big problem with this I2C LCD driver posted here, and it is that my PCF8574T LCD has different connection pin-out.

I want to change it in the code from:

// PCF8574P LCD
// ======== ======
// P0 Enable
// P1 RS
// P2 RW
// P3 No connect
// P4 D4
// P5 D5
// P6 D6
// P7 D7

To:

// PCF8574T LCD
// ======== ======
// P0 > D4
// P1 > D5
// P2 > D6
// P3 > D7
// P4 > ENABLE
// P5 > RW
// P6 > RS
// P7 > Not connected

I'll appreciate your help defining this new pin-out distribution in the code explained above by Hugo and maybe PCM can write a new generic Flex_i2c_LCD 20x4 and 20x2 for all of us :-)
Thanks in advance.
Core2



Joined: 27 Sep 2008
Posts: 22

View user's profile Send private message

PostPosted: Sat Nov 22, 2014 12:38 pm     Reply with quote

Ttelmah wrote:
As a minor 'consider this', why not change the init to something like:
Code:

void lcd_init(void)
{
    delay_ms(200); //LCD power up delay
    cont int8 init_data[] = {0x0,0x10,0x0,0x0,0x10, \
    0x30,0x30, \ //8bit mode
    0x30,0x20, \ //4bit mode
    0x20,0x80, \ //2lines 5*7
    0x00,0xC0, \ //No cursor
    0x00,0x60 };
    int8 ctr;
    //Request works on the command by set the RS = 0 R/W = 0 write
    for (ctr=0;ctr<sizeof(init_data;ctr++)
         lcd_send_byte(ctr); //send initialisation
    //clears the display
    lcd_clear();
}

When you are using the same command fifteen times, it may well be a case of 'better to loop'. Smile


I'm getting Compiler erors with the "\" in the array above, but I don't understand why?

*** Error 1 "D:\CCS PICC Projects\Tests\I2C_FLEX_LCD\i2c_Flex_LCD.h" Line 121(16,18): Illegal C character in input file 0x2F after \
*** Error 1 "D:\CCS PICC Projects\Tests\I2C_FLEX_LCD\i2c_Flex_LCD.h" Line 122(16,18): Illegal C character in input file 0x2F after \
*** Error 1 "D:\CCS PICC Projects\Tests\I2C_FLEX_LCD\i2c_Flex_LCD.h" Line 123(16,18): Illegal C character in input file 0x2F after \
*** Error 1 "D:\CCS PICC Projects\Tests\I2C_FLEX_LCD\i2c_Flex_LCD.h" Line 124(16,18): Illegal C character in input file 0x2F after \

My compiler version is 5.026. I'm testing with a 16F882.

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Nov 22, 2014 12:58 pm     Reply with quote

Move the line continuation backslashes so they are after the comments
on each line. And change 'cont' to const.
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Nov 22, 2014 1:11 pm     Reply with quote

and add a close paren after sizeof(init_data) <== in the For line... :-)
_________________
Google and Forum Search are some of your best tools!!!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Sat Nov 22, 2014 3:10 pm     Reply with quote

And understand that 'something like' means this is just an immediate 'untested' idea, that needs you to work out the exact syntax....
Core2



Joined: 27 Sep 2008
Posts: 22

View user's profile Send private message

PostPosted: Sat Nov 22, 2014 5:37 pm     Reply with quote

Thanks for the replies. I have to admit that I 'panicked' in that right after I compiled, and got the errors, my wife informed me that WE were going shopping. Not knowing when we'd get back, I shot off that message, and I wasn't sure when we were getting back.

I had already changed the 'cont' to 'const' and added the needed ')'.

SO, now we are back home. All is good with the program.

It's been 5 or so years since I've done any (PIC) programming. I'm using a PIC16F882, for the time being. Looking in the 16F882 Header file, I see the list of 'Fuses'. I thought there used to be a 'List' or something that explained what the 'Fuses' pertained too. Like I have no clue what 'CFMEN' or 'IESO' mean. And, I'm looking at the Datasheet. Just trying to figure out what FUSES I need. CCS has changed the way the IDE looks and works (a LOT) sine the last time I remember using it!

Thanks again,
Duane
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Nov 22, 2014 5:40 pm     Reply with quote

Look in the PICC directory where the compiler is located for the Fuses.txt file

IESO Internal External Switch Over mode enabled

For the other I think you meant FCMEN which is Fail Safe Clock Monitor Enabled

If you have the IDE then click on Config Bits on the Toolbar
I think I read somewhere the fuses.txt file only comes with the IDE version.
I have always used the IDE so I don't know for sure.
Google can also find the info...
_________________
Google and Forum Search are some of your best tools!!!!
Core2



Joined: 27 Sep 2008
Posts: 22

View user's profile Send private message

PostPosted: Sat Nov 22, 2014 6:30 pm     Reply with quote

Like I said, it's been a while since I last programmed a PIC. IIRC there WAS a Wizard that, when starting a new project, that 'helped' you select the options you wanted and then created the first couple of lines of code. It included the correct .h file, set up things like the ADC bits, RS@#@ stuff, i2c stuff, and such. Does it still do that, that you know of?

I did find the 'fuses.txt' file and will use that in conjunction with the fuses listed in the .h file to figure out what I need.

Thanks for you help.
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Nov 22, 2014 6:39 pm     Reply with quote

The IDE still has the PIC Wizard that does a lot of the basic setup work for you....yes.

In the IDE go to File=>New=>Project Wizard

Be sure to include the NOLVP fuse if it is listed for your processor.
_________________
Google and Forum Search are some of your best tools!!!!
i26c2



Joined: 01 Apr 2015
Posts: 19

View user's profile Send private message

Re: Working Driver!!!
PostPosted: Wed Apr 01, 2015 1:51 pm     Reply with quote

younder wrote:
Thanks for the tips Ttelmah!!!

Both Drivers are working now... but I've modified and recompiled a third one... I will share it here for anyone who needs in future...after all.. I owe a lot to this forum...

It can control any compatible LCD HITACHI from a bus I2C with
an PCF8574T I/O expander.

The Driver worked with 2x16, 2x20 and 4x20 lcd modules.

I renamed it for "i2c_Flex_LCD.h"

Driver code:
Code:

//-----------------------------------------------------------------------------
// Title:         i2c_Flex_LCD
// Description:   Driver for common LCD with 1/2/3 or 4 row modules using PCF8574T interface board with I2C protocol.
// Date:          Nov-2013
// Ver.Rev.:      1.0
// Author:        Hugo Silva ([email protected]) #Based on the routines of 20X4_LCD_I2C_DRIVER.h from Pumrin S.
//-----------------------------------------------------------------------------
//
// lcd_init() Must be called before any other function.
//
// lcd_putc(c) Will display c on the next position of the LCD.
// 
//     \f Clear LCD dispay
//     \1 Set write position on LCD Line 1
//     \2 Set write position on LCD Line 2
//     \3 Set write position on LCD Line 3
//     \4 Set write position on LCD Line 4
//
//     lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1)
//
//-----------------------------------------------------------------------------
// LCD pins D0-D3 are not used.
//-----------------------------------------------------------------------------
//
// Commment   : Control of a compatible LCD HITACHI from a bus I2C with
//              an EXPANDER of I/O with connection I2C. The tests of these
//              routines have been programmed using the IC PCF8574T of Phillips.
//              I used 4 bits mode programming. The 8 bits mode programming
//              is possible if you use 2 x PCF8574T.
//
// As defined in the following structure the pin connection is as follows:
//
//  PCF8574P     LCD
//  ========     ======
//     P0        RS
//     P1        RW
//     P2        Enable 
//     P3        Led Backlight
//     P4        D4
//     P5        D5
//     P6        D6
//     P7        D7
//
//  The SCL and SDA pins should be pull-up resistor as shown below:
//
//             +5v
//               |
//               <
//               > 4.7K       
//               <         
//To PIC         |          To i2c slave
//pin xx ------------------ SDA pin 
//(SDA)                     
//              +5v
//               |
//               <
//               > 4.7K       
//               <         
//To PIC         |          To i2c slave
//pin xx ------------------ SCL pin 
//(SCL)
//
//To PIC                    To i2c slave
//Vss pin ----------------- Vss or ground pin 
//                |
//              -----
//               ---  Ground
//                - 
// 
// THIS DOCUMENT IS PROVIDED TO THE USER "AS IS"
//-----------------------------------------------------------------------------

#define LCD_ADDR       0x4E //I2C slave address for LCD module

#define ON             1
#define OFF            0
#define RS             0b00000001  //P0 - PCF8574T Pin connected to RS
#define RW             0b00000010  //P1 - PCF8574T Pin connected to RW
#define EN             0b00000100  //P2 - PCF8574T Pin connected to EN
#define BACKLIGHT_LED  0b00001000  //P3 - PCF8574T Pin connected to BACKLIGHT LED

#define lcd_line_one   0x80   // LCD RAM address for line 1
#define lcd_line_two   0xC0   // LCD RAM address for line 2
#define lcd_line_three 0x94   // LCD RAM address for line 3
#define lcd_line_four  0xD4   // LCD RAM address for line 4
 
byte address;
int1 lcd_backlight=ON;

void i2c_send_nibble(unsigned char data)
   {   
        i2c_start();
        delay_us(20);
        i2c_write(LCD_ADDR); //the slave addresse
        delay_us(20);
        i2c_write(data);
        delay_us(20);
        i2c_stop();
        delay_us(20);
   }

void lcd_send_byte(unsigned char data)
   {
        if (lcd_backlight) data=data|EN|BACKLIGHT_LED; else data=data|EN; //set pin EN
        i2c_send_nibble(data);
        data=data-4;       //toggle EN back to 0
        i2c_send_nibble(data);
   }
   
void lcd_clear()
{
    lcd_send_byte(0x00);
    lcd_send_byte(0x10);
    delay_ms(2);
}

void lcd_init()
{
    delay_ms(200); //LCD power up delay
       
   //Request works on the command by set the RS = 0 R/W = 0 write
        lcd_send_byte(0x00);
        lcd_send_byte(0x10);
        lcd_send_byte(0x00);
        lcd_send_byte(0x00);
        lcd_send_byte(0x10);
           //First state in 8 bit mode
        lcd_send_byte(0x30);
        lcd_send_byte(0x30);
           //Then set to 4-bit mode
        lcd_send_byte(0x30);
        lcd_send_byte(0x20);
           //mode 4 bits, 2 lines, characters 5 x 7 (28 h)
        lcd_send_byte(0x20);
        lcd_send_byte(0x80);
           //no need cursor on (0Ch)
        lcd_send_byte(0x00);
        lcd_send_byte(0xC0);
           //the cursor moves to the left (06 h)
        lcd_send_byte(0x00);
        lcd_send_byte(0x60);
           //clears the display
        lcd_clear();
}

void lcd_gotoxy( byte x, byte y)
{     
static char data;
     
   switch(y)
   {
      case 1:  address= lcd_line_one;     break;
      case 2:  address= lcd_line_two;     break;
      case 3:  address= lcd_line_three;   break;
      case 4:  address= lcd_line_four;    break;
      default: address= lcd_line_one;     break; 
   }
 
   address+=x-1;
   data=address&0xF0;
   lcd_send_byte(data);
   data=address&0x0F;
   data=data<<4;
   lcd_send_byte(data);
}

//Display the character on LCD screen.
void LCD_PUTC(char in_data)
{
 char data;     
  switch(in_data)
   { 
     case '\f': lcd_clear()    ;  break;               
     case '\1': lcd_gotoxy(1,1);  break;
     case '\2': lcd_gotoxy(1,2);  break;
     case '\3': lcd_gotoxy(1,3);  break;
     case '\4': lcd_gotoxy(1,4);  break;

     default:
        data=in_data&0xF0;
        data=data|RS; //set RS pin to 1
        lcd_send_byte(data);
        data=in_data&0x0F;
        data=data<<4;
        data=data|RS; //set RS pin to 1
        lcd_send_byte(data);
     break;
   }
}


Main code:
Code:

#include <18f4550.h>
#device ICD = TRUE
#device ADC=10               
#use delay (clock=48000000)
#use i2c(Master,Fast=100000, sda=PIN_D6, scl=PIN_D7,force_sw)
#include <i2c_Flex_LCD.h>   
#fuses HSPLL,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,USBDIV,PLL5,CPUDIV1,DEBUG,ICSP1 // configura fuses

void main()
{
Char string="Test";
int16 test=1;

  lcd_init();
  lcd_backlight=ON;
 
        while (TRUE)
   {   
         test=test+1;
         
         lcd_clear();  //Clear Display
         printf(LCD_PUTC,"\1%s","LCD Line 1");  //Print on LCD line 1
         delay_ms(1000);
         
         printf(LCD_PUTC,"\2%s","LCD Line 2");  //Print on LCD line 2
         delay_ms(1000);
       
         printf(LCD_PUTC,"\f\1%s","LCD Line 1"); //Clear display, print again on Line 1
         delay_ms(1000);
         
         printf(LCD_PUTC,"\f\2%s","LCD Line 2"); //Clear display, print again on Line 2
         delay_ms(1000); 
         
         lcd_backlight=OFF;
         printf(LCD_PUTC,"\f\1%s\2%s","LCD BackLight","     OFF      "); //Clear display, print again on Line 1
         delay_ms(1000);
         
         lcd_backlight=ON;
         printf(LCD_PUTC,"\f\1%s\2%s","LCD BackLight","     ON      "); //Clear display, print again on Line 2
         delay_ms(1000);
   }   
}


Thanks guys for all support!
BR
Hugo



Hi, I am working with a PIC24f16ka101 20pin DIP micro controller and the DFRobot I2C / TWI LCD1602 Module. After removing a couple fuses that simply don't exist for my micro I was able to compile the code and load my PIC. The back light goes on for my display but nothing else works.

I then realized my slave address was 0x20 so I changed that, and I changed the I2C pins to the correct ones for my PIC but it still does not work. I am pulling up the clock and data pins to 3V instead of 5V but the display says it should work anywhere from 2.7-11V so it should not be an issue. I feel like something is missing or different in the code for the display and/or processor I am using.

Could someone help me out?
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Apr 01, 2015 3:01 pm     Reply with quote

I 'googled' that lcd module, fist hit , was Wiki from dfrobot and ....Supply voltage: 5V !!!

I suspect that is your problem..
3 volt PIC, 5 volt LCD..
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 01, 2015 3:47 pm     Reply with quote

Quote:

DFRobot I2C / TWI LCD1602 Module

the display says it should work anywhere from 2.7-11V

Can you post a link to:

1. The product page for this lcd.

2. The data sheet that gives specs on the i2c interface. I don't want the
data sheet for the HD44780 controller. I want the one that says the lcd
module works from 2.7 to 11v, and gives specs on the i2c interface that
DFRobot added to the lcd.
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Apr 01, 2015 4:39 pm     Reply with quote

i downloaded the schematic right from dfrobot.... and it clearly shows the LCD module/I2C chip being fed from VCC , which is 5 volts. There are 2 'logic level' translators on the I2C bus lines though, which would allow a 3V micro to communicate with the 5 volt LCD unit.

Now you 'might' be able to run a 3 volt LCD module IF the PCF chip will run at 3 volts....


Jay
i26c2



Joined: 01 Apr 2015
Posts: 19

View user's profile Send private message

PostPosted: Wed Apr 01, 2015 8:06 pm     Reply with quote

You are right, the 3-11V was for the LCD back-light and the LCD itself can run from 2.7 to 5.5V (From http://www.dfrobot.com/image/data/TOY0046/HD44780.pdf). Strangely they post the data sheet for the LCD module only and not for the i2C module, for that they just post a schematic. There is no indication on whether it can handle 3V. It is terrible that they don't have a data sheet for their own product.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Thu Apr 02, 2015 12:38 am     Reply with quote

The order page for the module, says:

"3.2" LCD display; White character on Blue background; Supply voltage: 5V; I2C Address: 0x27".....

The core LCD controller can run from 2.7 to 5.5v, but the complete module is specified to use 5v.....

There are three different revisions of these units, and all say 5v somewhere.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4, 5, 6  Next
Page 2 of 6

 
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