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

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
i26c2



Joined: 01 Apr 2015
Posts: 19

View user's profile Send private message

PostPosted: Sun Apr 05, 2015 11:19 am     Reply with quote

I am not sure what you are referring to but all grounds are common. If you are refering to the debugger, the ground is common, if it was not I would not be able to program the PIC, if you are refering to the LCD, yes, I created a header plug which has all 4 pins, clock, data, ground and +5V. I have +5V going to 5V source, ground going to the common ground between LCD, micro, 5V source and 3V source. The level translator also uses common ground.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Apr 05, 2015 1:12 pm     Reply with quote

In your first post in this thread, here:
http://www.ccsinfo.com/forum/viewtopic.php?t=51351&start=24
you reference an i2c lcd driver for a 20x4 lcd. That driver has a line
address table:
Code:

#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

But you're using a 16x2 lcd. A 16x2 lcd has different line starting
addresses. The 1st and 2nd line addresses are 0x00 and 0x40.
There are other changes needed, because there is no line 3 and line 4
for your lcd.

Also, post your short program that calls the lcd driver. It should be
a short Hello World program. Post the complete program with the
#include for the PIC, #fuses, #use delay(), #include for the lcd
driver, main(), etc.
i26c2



Joined: 01 Apr 2015
Posts: 19

View user's profile Send private message

PostPosted: Sun Apr 05, 2015 7:11 pm     Reply with quote

So This is my attempt to modify the driver for a two-line display. It still doesn't work:

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 (sergio-hugo@bol.com.br) #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       0x40 //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   0x00   // LCD RAM address for line 1
#define lcd_line_two   0x40   // LCD RAM address for line 2
 
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;
      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;
   }
}

I was trying to run the code that was with the driver, but I simplified it to just sending one word to one line of the display, it is still not doing anything. I have tried 0x20, 0x40, and 0x4E addresses for slave address and still no luck.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Apr 06, 2015 1:26 am     Reply with quote

Er.....
Code:

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);
}


Wrong.....

You are sending the low nibble on both writes. So this function does not send a byte. Look at how it is done in the very first post in this thread or in the flex_lcd driver.

Not going to get very far with major mistakes like this....

The whole approach in your code seems reversed. According to the sheets for the adapter module, the bit layout is:

BL EN RW RS D3 D2 D1 D0

So the data nibble is sent as the low nibble, with the control bits attached as the top nibble. You are changing low bits to set enable, backlight etc....

Look at the I2C driver at the start of this thread. Change this for two lines, and add the backlight bit only.
i26c2



Joined: 01 Apr 2015
Posts: 19

View user's profile Send private message

PostPosted: Mon Apr 06, 2015 8:02 am     Reply with quote

Two things: 1. I copied the code from hugo's flex driver from this thread and he said it works with 1,2,3, and 4 line displays, and 2. he said it worked.

The first driver posted it was mentioned didn't work, so not sure if I should try that or keep working with the flex one. You mentioned look at the flex one but that's where that code is from, I didn't modify that as far as I know
i26c2



Joined: 01 Apr 2015
Posts: 19

View user's profile Send private message

another shot
PostPosted: Mon Apr 06, 2015 9:02 am     Reply with quote

I tried with the code given here as its for a 16X2 display: http://www.co.optimengineering.com/forum/viewtopic.php?t=53192&view=previous

still no luck. I don't have time to continue so I will just be using LED indicators for different voltage levels, though I am still curious about getting the LCD working, I just don't have any more time to devote to it. Thank you all for your help
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Apr 06, 2015 10:55 am     Reply with quote

i26c2 wrote:
Two things: 1. I copied the code from hugo's flex driver from this thread and he said it works with 1,2,3, and 4 line displays, and 2. he said it worked.

The first driver posted it was mentioned didn't work, so not sure if I should try that or keep working with the flex one. You mentioned look at the flex one but that's where that code is from, I didn't modify that as far as I know


You need to start looking at code, not just copying it and hoping.
The one you have just pointed to, for example, is a text based module, not a Hitachi type display.

The code pasted right at the start of this thread is closer to potentially working, than the code you have copied.

By 'flex_lcd', I mean _flex_lcd_ the PCM_programmer code in the code library, not the code that has been posted as 'I2C flex_lcd', which cannot work. It has major bugs...

Key is to step back and understand what is involved here. This is _not_ an I2C interfaced LCD. The PCF8574, is an I2C interfaced 8bit port. Nothing more. Using simple I2C commands you can write a byte to this. Now flex_lcd, shows exactly how to control an LCD connected to any pattern of bits on a port, using a nibble interface.

So wherever this turns on a pin, or sets a pattern of bits, if you simply substitute the I2C commands to set this pin or output this pattern of bits, this is all that is needed. There is one 'added complexity', in that the LCD involved has a backlight pin that needs to be enabled, but this only the matter of turning on one extra pin.

So something like....
OK.

I've sat down and written a minimum core driver for this.

'Core', since it just replaces the core nibble function from PCM_programmer's flex LCD driver.

What you need is to load the type and initialisation from the corresponding
flex_lcd for the size display you are using. I've included the ones for a two line display.

(with thanks to PCM_programmer)
Code:

//Using a PC8574 to control an LCD

#define I2C_ADDRESS 0x40 //(change to 0x4E if you have the earliest board
//or if you change the jumpers on the later boards - remember Arduino
//address *2

//Using bit 0 to 3 for the nibble. If this is not how the LCD is wired
//then you'd need to switch to the layout and modify the nibble function.
#define LCD_E     6
#define LCD_RS    4
#define LCD_RW    5
#define LCD_BACK  7 //define if backlight exists
//Just use bit numbers here for the control bits

//Now setup the I2C
#use I2C(master, I2C1, fast=400000)
//change to 100K if using the standard chip, and change pins if not using
//hardware I2C.

//========================================
//Setup here to suit teh LCD. Look at the other flex_lcd drivers to see how it
//changes for different LCD's

#define lcd_type 2        // 0=5x7, 1=5x10, 2=2 lines
#define lcd_line_two 0x40 // LCD RAM address for the 2nd line

int8 const LCD_INIT_STRING[4] =
{
 0x20 | (lcd_type << 2), // Func set: 4-bit, 2 lines, 5x8 dots
 0xc,                    // Display on
 1,                      // Clear display
 6                       // Increment cursor
 };
 
int1 byte_to_PC8574(int8 chr)
{ //output a byte to the PC8574
    int1 ack;
    i2c_start();
    ack=i2c_write(I2C_ADDRESS);
    if (ack!=0)
       return FALSE;
    i2c_write(chr);
    i2c_stop();
    return TRUE;
}

//Macro to set a bit to a value
#define BIT_VAL(val,x,y) if(y) bit_set(val,x);else bit_clear(val,x)

int1 backlight=TRUE; //set TRUE/FALSE to enable the backlight bit
int1 regsel=FALSE;

//-------------------------------------
int1 lcd_send_nibble(int8 nibble)
{
    int8 dummy=0;
    dummy=nibble & 0xF; //change to BIT_VAL functions if mapping is
    //not D0 to D3.
    //set the required bits in the output byte
    #ifdef LCD_BACK
        BIT_VAL(dummy,LCD_BACK,backlight); //set the backlight if enabled
    #endif
    BIT_VAL(dummy,LCD_RS,regsel); //add register select
    //since dummy is initilised to 0, E always starts low.
    if (!byte_to_PC8574(dummy))
       return FALSE;
    bit_set(dummy,LCD_E);
    byte_to_PC8574(dummy); //Enable high
    bit_clear(dummy,LCD_E);
    byte_to_PC8574(dummy); //and back low
    //send the nibble, and pulse the enable.
    return TRUE;
}

//----------------------------------------
// Send a byte to the LCD.
int1 lcd_send_byte(int8 address, int8 n)
{
    if(address)
       regsel=TRUE;
    else
       regsel=FALSE;
    if (!lcd_send_nibble(n >> 4))
       return FALSE;
    lcd_send_nibble(n & 0xf);
    return TRUE;
}

//----------------------------
int1 lcd_init(void)
{
   int8 i;

   regsel=FALSE; //ensure starts with RS low
   //Setup the I2C

   delay_ms(15);
   for(i=0 ;i < 3; i++)
   {
      if (!lcd_send_nibble(0x03))
         return FALSE;
      delay_ms(5);
   }

   lcd_send_nibble(0x02);

   for(i=0; i < sizeof(LCD_INIT_STRING); i++)
   {
      lcd_send_byte(0, LCD_INIT_STRING[i]);
      delay_ms(5);
   }
   return TRUE;
}

//----------------------------

void lcd_gotoxy(int8 x, int8 y)
{
   int8 address;

   if(y != 1)
      address = lcd_line_two;
   else
      address=0;

   address += x-1;
   lcd_send_byte(0, 0x80 | address);
}

//-----------------------------
void lcd_putc(char c)
{
   switch(c)
   {
   case '\f':
      lcd_send_byte(0,1);
      delay_ms(2);
      break;
   
   case '\n':
       lcd_gotoxy(1,2);
       break;
   
   case '\b':
       lcd_send_byte(0,0x10);
       break;
   
   default:
       lcd_send_byte(1,c);
       break;
   }
}


I haven't tried this. Haven't got the chip, and so haven't even test compiled, but it shows an approach to replacing the code I/O function for flex_lcd with a version driving the I2C.

Only thing different, is that lcd_init, returns 'TRUE' if the chip acknowledges, so if this returns FALSE it signals an I2C error, or address error etc..
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Apr 06, 2015 12:17 pm     Reply with quote

Have just found another board being used with completely different address and wiring....
Code:

#define I2C_ADDRESS 0x7E

//Using bit 4 to 7 for the nibble. Instead....
#define LCD_E     2
#define LCD_RS    0
#define LCD_RW    1
#define LCD_BACK  3 //define if backlight exists
//Just use bit numbers here for the control bits

//-------------------------------------
int1 lcd_send_nibble(int8 nibble)
{
    int8 dummy=0;
    swap(nibble)
    dummy=nibble & 0xF0; //Using d4 to D7
    //set the required bits in the output byte
    #ifdef LCD_BACK
        BIT_VAL(dummy,LCD_BACK,backlight); //set the backlight if enabled
    #endif
    BIT_VAL(dummy,LCD_RS,regsel); //add register select
    //since dummy is initilised to 0, E always starts low.
    if (!byte_to_PC8574(dummy))
       return FALSE;
    bit_set(dummy,LCD_E);
    byte_to_PC8574(dummy); //Enable high
    bit_clear(dummy,LCD_E);
    byte_to_PC8574(dummy); //and back low
    //send the nibble, and pulse the enable.
    return TRUE;
}


Several people were moaning that the standard library did not work on this one. Different I2C address, Wiring reversed....

I must say if I was trying to use one of these, I'd start by _creating_ some data:
1) Run PCM_Programmer's I2C scanner and find what address it is on.
2) Use a ohmmeter and test what LCD pin connects to what pin on the PC8574.

Then one could setup the driver in a couple of minutes.

Then I suspect the original driver you found almost works, except when posted, the poster managed to leave out one <<4, in the data accesses, so that the wrong part of the byte gets sent on one transmission.
sunil_kasar



Joined: 05 May 2015
Posts: 2
Location: India

View user's profile Send private message AIM Address

Interfacing I2c LCD display with ATmega16
PostPosted: Tue May 05, 2015 4:45 am     Reply with quote

Hello All,

I am new to embedded system. I have 20x4 LCD display(JHD 204A) with PCF8574T.
I am connecting this to ATmega16 microcontroller. Can I use the same LCD code which is posted above?
pic.programmer



Joined: 30 Apr 2015
Posts: 29
Location: Banned - spammer

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

Re: Interfacing I2c LCD display with ATmega16
PostPosted: Tue May 05, 2015 6:23 am     Reply with quote

The above code and the I2C LCD Code posted in Library section by me are written for CCS C Compiler and it can be used with AVR. If you can use mikroC PRO AVR Compiler then I will port my I2C LCD code to AVR and give it to you. If you need AVR code then let me know.

Also ask your question related to AVR at edaboard microcontrollers section. I will answer there.

This is CCS C forum and please don't ask AVR related questions here.

Here is a AVR I2C LCD code I wrote. You can use this.

http://www.edaboard.com/thread337028.html
sunil_kasar



Joined: 05 May 2015
Posts: 2
Location: India

View user's profile Send private message AIM Address

PostPosted: Tue May 05, 2015 10:17 pm     Reply with quote

Thanks a lot....
younder



Joined: 24 Jan 2013
Posts: 53
Location: Brazil

View user's profile Send private message

I2C Driver in the library
PostPosted: Sun Jun 21, 2015 7:19 pm     Reply with quote

Hi guys,

It seems that this thread got a bit confused due to so many posts and changes/suggestions in the code for the "i2c_Flex_LCD" using Phillips PCF8574T.

I'm sharing the version I've been using for a while in the Code Library, and hope that this can be helpful for someone.

http://www.ccsinfo.com/forum/viewtopic.php?p=197704

Thanks
Hugo
_________________
Hugo Silva
Katynga



Joined: 21 May 2017
Posts: 1

View user's profile Send private message

PostPosted: Sun May 21, 2017 4:29 am     Reply with quote

Hi:

I have a problem, when i compile this code:

i26c2 wrote:
So This is my attempt to modify the driver for a two-line display. It still doesn't work:

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 (sergio-hugo@bol.com.br) #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       0x40 //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   0x00   // LCD RAM address for line 1
#define lcd_line_two   0x40   // LCD RAM address for line 2
 
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;
      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;
   }
}


I was trying to run the code that was with the driver, but I simplified it to just sending one word to one line of the display, it is still not doing anything. I have tried 0x20, 0x40, and 0x4E addresses for slave address and still no luck.



I get an error message on line 91

Code:
 i2c_start();

And say:
Quote:
Line91(19,20):A numeric expression must appear here.

Shocked Shocked

I know that in the middle of () no numerical expression is needed
What happens to the code?

Code:
i2c_write(LCD_ADDR); //the slave addresse

And say:
Quote:
Line93(19,28):Expect comma



I use this code for the PIC 16F873A, and I2C connected the PCF8574.
It should work the same.

Will I have problems with the compiler version or the operating system?
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sun May 21, 2017 7:27 am     Reply with quote

CCS commonly reports errors long after they actually happen.

What happens is you make some small syntax error earlier in the code, which is not 'terminal', and the compiler then carries on until it can no longer get the code to work.

So your error could easily be in your 'main' code, calling the LCD driver.

It'll also complain on i2c_start, if the I2C interface has not been correctly configured yet.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun May 21, 2017 8:06 am     Reply with quote

That error occurs if there is no #use i2c() statement.
I think he's just compiling the driver only. He's new to CCS and doesn't
realize there must be a program that calls the driver. You can't normally
just compile the driver by itself. You will get errors.

In Hugo Silva's post here,
http://www.ccsinfo.com/forum/viewtopic.php?t=54063
he has a 2nd section with this title:
Quote:
Test Code: i2c_Flex_LCD_Test.c

That section has the #use i2c() statement in it.
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 5 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