16 X 2 LCD with PCF 8574 (without using I2C library)

Hello friends, I am here using a LCD with 8574 but without any LCD library . Address of 8574 is set to 32 (0x20) .
P0 is Connected to EN of LCD , P1 to RS and P2-P5 are connected to D4-D7 of LCD . With code I have written (which is a bit lengthy ) I am not getting any output. Contrast is moderate so that's not a problem for sure.
Can you guys help me out of it...... :cold_sweat: :~

#include<Wire.h>
int add=32;
int x=1;
byte command,data;
byte string[13]={'A','W','E','S','O','M','E',' ','R','A','H','U','L'};
void setup()
{
Wire.begin();
Wire.beginTransmission(add);
lcd_initialise();
}
void loop()
{ if(x)// wanted to run this only once
{
for(int i=0;i<=11;i++)
lcd_display(string*);*

  • }*
    x=0;
    }
    void lcd_initialise()
    {
  • command=0x38;//init lcd 2 line 5x7 matrix*
  • lcd_command(command);*
  • command=0x0E;//Lcd on cursor on*
  • lcd_command(command);*
  • command=0x01;//clear lcd*
  • lcd_command(command);*
  • command=0x06;//shift cursor right*
  • lcd_command(command);*
  • command=0xC0;//cursor at line 1 and position 1*
  • lcd_command(command);*
    }
    void lcd_display(byte data1)
    {
  • byte temp;*
  • temp=0xF0 && data1;*
  • temp=temp>>2;*
  • temp=temp^0x02;*
  • Wire.beginTransmission(add);*
  • Wire.write(temp);// rs equals one for data and en equal zero*
  • // en=1 and send again then again en =0*
  • temp=temp^0x01;// exoring en becomes 1*
  • Wire.write(temp);*
  • delay(10);// delay in between*
  • temp=temp^0x01;// again exoring en becomes 0*
  • // and data will be latched*
  • Wire.write(temp);*
  • // same to be repeated for lower nibble*
  • delay(10);*
  • temp=0x0F && data1;*
  • temp=temp<<2;*
  • temp=temp^0x02;// rs made 1 for data reg*
  • //and en is 0 as default*
  • Wire.write(temp);*
  • temp=temp^0x01;// en made 1*
  • Wire.write(temp);*
  • delay(10);// some delay in between*
  • temp=temp^0x01;// en made 0 to get data latched*
  • Wire.write(temp);*
  • delay(50);*
  • Wire.endTransmission();*
    }
    void lcd_command(byte command1)
    {
  • byte temp;*
  • temp=0xF0 && command1;*
  • temp=temp>>2;*
  • Wire.beginTransmission(add);*
  • Wire.write(temp);// rs and en both equal zero*
  • // en=1 and send again then again en =0*
  • temp=temp^0x01;// exoring en becomes 1*
  • Wire.write(temp);*
  • delay(10);*
  • temp=temp^0x01;// again exoring en becomes 0*
  • // and data will be latched*
  • Wire.write(temp);*
  • // same to be repeated for lower nibble*
  • delay(10);*
  • temp=0x0F && command1;*
  • temp=temp<<2;*
  • Wire.write(temp);*
  • temp=temp^0x01;*
  • Wire.write(temp);*
  • delay(10);*
  • temp=temp^0x01;*
  • Wire.write(temp);*
  • delay(500);*
  • Wire.endTransmission(); *
    }
    [/quote]
    LCD_i2c.ino (2.02 KB)

Your code is difficult to read because you have used 'quote' tags instead of 'code' tags, so please go back an edit your post to fix this.

I have not thoroughly gone through your code but a few things stand out.

Are you sure that your are using a PCF8574 and not a PCF8574A which has a different address?

How do you know that your contrast is 'moderate'? If you are not sure of the setting then an extreme setting (0 volts) on pin 3 a good option.

It would be a good idea to use the 'initialization by instruction' sequence recommended in the HD44780 datasheet rather than the incorrect one used in a lot of the examples floating around the internet. Follow the LCD Addressing link at http://web.alfredstate.edu/weimandn for more information. You will also find programming examples there.

Instead of using "

{ if(x)//wanted to run this only once  ...

" why don't you just put the relevant code in setup(), that's what setup() is for?

The LCD initialization sequence should certainly be in setup(). This change alone may fix your program and should be done first.

This (

command=0xC0;//cursor at line 1 and position 1

) is putting the cursor at line 1 and position 0 if you count from 0 - 9 and it is putting the cursor at line 2 and position 1 if you count from 1 - 10. This isn't your basic problem since this address (0x40) is visible on all displays that I know of.

That should keep you out of trouble for a while.

Don