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

2-Wire LCD Interface

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



Joined: 30 Mar 2013
Posts: 17

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

2-Wire LCD Interface
PostPosted: Thu May 30, 2013 1:33 pm     Reply with quote

hello everybody !
i use pc 16F877 4MHZ i wanna use the bus I2C to communicate with (DS1703 TIME - AND my LCD 16x2)
the communication with PIC and LCD use an flip-flops into 74LS174 this is refer to "Myke method" you can join : http://www.rentron.com/Myke1.htm
so ! i make a search on ccs forum ! i find this two result :
http://www.ccsinfo.com/forum/viewtopic.php?t=24426&highlight=74ls174
http://www.ccsinfo.com/forum/viewforum.php?f=1
and no solution yet ! cause the code or driver was wrong !
so can you help me !
this is a big problem :( thank you
temtronic



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

View user's profile Send private message

PostPosted: Thu May 30, 2013 1:45 pm     Reply with quote

You cannot use the I2C peripheral of the PIC to communicate with the 'Myke method of LCD control' schematic.
Although it is a 'clock and data' serial communications protocol it is NOT I2C.
You'll have to use 2 other pins for your LCD system leavng the I2C pins for the DS1307 RTC. Be sure to use correct pullups on the I2C bus line !!

hth
jay
mohamed2040



Joined: 30 Mar 2013
Posts: 17

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

PostPosted: Thu May 30, 2013 2:03 pm     Reply with quote

thank you for your fast answer Smile
but !
so i must use two other pins to make communication with LCD , the first PIN used to (internal ou external clock ?) and the second one to send data ? from pic to 74LS147 ? sorry i not understand :(
i have an other solution! to use MCP23016 ! on I2C Bus ! ?? with DS1307
but i havent MCP23016 driver :(
dyeatman



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

View user's profile Send private message

PostPosted: Thu May 30, 2013 2:22 pm     Reply with quote

There is a 23016 driver in the code library.
_________________
Google and Forum Search are some of your best tools!!!!
mohamed2040



Joined: 30 Mar 2013
Posts: 17

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

PostPosted: Thu May 30, 2013 2:32 pm     Reply with quote

oops ! yep you right :( but I'm searching solutions :( to make communication PIC-LCD with only two wires cause i need more pin :( to connect other hardware
so this is the driver of MCP
Code:


#ifndef  MCP23016
#define  MCP23016

#define MCP_write 0B01000000
#define MCP_read  0B01000001

#define GP0     0x00
#define GP1     0x01
#define OLAT0   0x02
#define OLAT1   0x03
#define IPOL0   0x04    // INPUT POLARITY PORT REGISTER 0
#define IPOL1   0x05    // INPUT POLARITY PORT REGISTER 1
#define IODIR0  0x06    // I/O DIRECTION REGISTER 0
#define IODIR1  0x07    // I/O DIRECTION REGISTER 1
#define INTCAP0 0x08 // INTERRUPT CAPTURE REGISTER 0
#define INTCAP1 0x09 // INTERRUPT CAPTURE REGISTER 1
#define IOCON0  0x0A // I/O EXPANDER CONTROL REGISTER 0
#define IOCON1  0x0B // I/O EXPANDER CONTROL REGISTER 1
//////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////
void InitMCP23016(int8 AddressSelect, int8 P0, int8 P1)
{
   i2c_start();
      delay_us(20);
   i2c_write(MCP_write | (AddressSelect << 1));
      delay_us(20);
   i2c_write(IODIR0);
      delay_us(20);
   i2c_write(P0);
      delay_us(20);
   i2c_write(P1);
      delay_us(20);
   i2c_stop();
      delay_us(20);
   i2c_start();
      delay_us(20);
   i2c_write(MCP_write | (AddressSelect << 1));
      delay_us(20);
   i2c_write(IOCON0);
      delay_us(20);
   i2c_write(0x01);
      delay_us(20);
   i2c_stop();
      delay_us(50);
}
//////////////////////////////////////////////////////////////////////////////
void GetGPx(int8 AddressSelect, int8 *P0, int8 *P1)
{
   i2c_start();
      delay_us(20);
   i2c_write(MCP_write | (AddressSelect << 1));
      delay_us(20);
   i2c_write(GP0);
      delay_us(20);
   i2c_stop();
      delay_us(50);
   i2c_start();
      delay_us(20);
   i2c_write(MCP_read | (AddressSelect << 1));
      delay_us(20);
   *P0 = i2c_read();
      delay_us(20);
   *P1 = i2c_read(0);
      delay_us(20);
   i2c_stop();
      delay_us(50);
}
//////////////////////////////////////////////////////////////////////////////
void SetGPx(int8 AddressSelect, int8 P0, int8 P1)
{
   i2c_start();
      delay_us(20);
   i2c_write(MCP_write | (AddressSelect << 1));
      delay_us(20);
   i2c_write(OLAT0);
      delay_us(20);
   i2c_write(P0);
      delay_us(20);
   i2c_write(P1);
      delay_us(20);
   i2c_stop();
      delay_us(50);
}
//////////////////////////////////////////////////////////////////////////////
void GetINTGPx(int8 AddressSelect, int8 *P0, int8 *P1)
{
   i2c_start();
      delay_us(20);
   i2c_write(MCP_write | (AddressSelect << 1));
      delay_us(20);
   i2c_write(INTCAP0);
      delay_us(20);
   i2c_stop();
      delay_us(50);
   i2c_start();
      delay_us(20);
   i2c_write(MCP_read | (AddressSelect << 1));
      delay_us(20);
   *P0 = i2c_read();
      delay_us(20);
   *P1 = i2c_read(0);
      delay_us(20);
   i2c_stop();
      delay_us(50);
}
//////////////////////////////////////////////////////////////////////////////
void SetGPREG(int8 AddressSelect, int8 REG, int8 Data)
{
   i2c_start();
      delay_us(20);
   i2c_write(MCP_write | (AddressSelect << 1));
      delay_us(20);
   i2c_write(REG);
      delay_us(20);
   i2c_write(Data);
      delay_us(20);
   i2c_stop();
      delay_us(50);
}
#endif


AND this is the schematic connection :
[img]
http://u7903.direct.atpic.com/37111/0/2395801/0.png
[/img]
lien : http://u7903.direct.atpic.com/37111/0/2395801/0.png
i wanna just know how can i use this code to communicate with PIC and to print just "HELLO"
dyeatman



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

View user's profile Send private message

PostPosted: Thu May 30, 2013 2:41 pm     Reply with quote

You are trying to do this in Proteus correct?
_________________
Google and Forum Search are some of your best tools!!!!
mohamed2040



Joined: 30 Mar 2013
Posts: 17

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

PostPosted: Thu May 30, 2013 2:54 pm     Reply with quote

dyeatman, yes sure but can't make communication between MCP and PIC to write something on LCD.
But : I'm using DS1307 on I2C to put TIME on LCD
dyeatman



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

View user's profile Send private message

PostPosted: Thu May 30, 2013 3:01 pm     Reply with quote

Please read the PIC101 message at the top of the forum. We generally
dont assist with Proteus projects in this forum. You need to go to the Proteus
forum. Too many serious bugs in Proteus...
_________________
Google and Forum Search are some of your best tools!!!!
mohamed2040



Joined: 30 Mar 2013
Posts: 17

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

PostPosted: Thu May 30, 2013 3:18 pm     Reply with quote

Proteus is not my problem now Smile
my problem is : how can i make communication with 3 devices :
The Pic 16F877 and MC23016 and LCD 16x2 to write "HELLO" on LCD Smile
so i don't say that i had a problem in Proteus Smile
dyeatman



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

View user's profile Send private message

PostPosted: Thu May 30, 2013 4:40 pm     Reply with quote

Proteus itself IS the problem... Proteus does not emulate many devices
well especially when you start looking at PICS communicating using I2C and
SPI. The pros on this site have been burned so many times they just
don't do Proteus....Proteus will not complain even when a number of serious
problems exist with your code and circuit, it just won't work. Many times
the code and circuit wil be OK but Proteus won't work properly.
_________________
Google and Forum Search are some of your best tools!!!!
temtronic



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

View user's profile Send private message

PostPosted: Thu May 30, 2013 5:06 pm     Reply with quote

As I've used the '877 for a couple decades...please tell us WHY you can't wire the LCD to the PIC in 8bit mode?
According to your original post you have a DS1307 RTC that needs 2 pins, another I2C device( 2 more pins).
It is very easy to interface LCD module to PIC using an entire port(8 bits) for data and 2 more for control.

As others have said Proteus is NOT reliable! Full of bugs,errors, faulty DRCs! I've yet to see ANY Proteus schematic presented here (over 100 !) that would actually work in the real world.

Also, you should consider using the '887. More memory,more fuctionality, LESS cost !

hth
jay
mohamed2040



Joined: 30 Mar 2013
Posts: 17

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

PostPosted: Sat Jun 01, 2013 6:46 am     Reply with quote

thank you all Smile
yessss Proteus >> Full of bugs with I2C
my problem was solved! Rolling Eyes
with Proteus frankly I have not found problems!
I used the PCF 8574
with this driver :
Code:

#use i2c(master, sda=PIN_C4, scl=PIN_C3)
#define PORT_BASE_ADDRESS 0x40

unsigned char read_from_port();
void write_to_port(unsigned char data_byte);

unsigned char read_from_port()
{
    unsigned char port_byte=0;
    i2c_start();                             
    i2c_write((PORT_BASE_ADDRESS + 1));       
    port_byte=i2c_read(0);             
    i2c_stop();
    return port_byte;
}
                                               

void write_to_port(unsigned char data_byte)
{
    i2c_start();
    i2c_write(PORT_BASE_ADDRESS);
    i2c_write(data_byte);
    i2c_stop();
}
mohamed2040



Joined: 30 Mar 2013
Posts: 17

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

PostPosted: Sat Jun 01, 2013 6:51 am     Reply with quote

temtronic Embarassed
thank you sooo much bro
i use I2C PCF with 2 wires to write and read from LCD with an other DS1307 wasconnected on I2C cause i need more PIN :(
temtronic



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

View user's profile Send private message

PostPosted: Sat Jun 01, 2013 7:32 am     Reply with quote

So now you're NOT using the 'Myke method', but using an I2C port chip.....
Actually a good option as it keeps you 'I2C' compatible, frees up 2 pins,and easy to understand.

Be adviced though not ONE proteus schematic presented here(100s have) will ever work in the real world....

cheers
Jay
mohamed2040



Joined: 30 Mar 2013
Posts: 17

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

PostPosted: Sat Jun 01, 2013 4:24 pm     Reply with quote

yes that's sure ! but no problem ! to use two devices ! (DS1307 and PCF8574)
on I2C ! it will be working in real ! i'll buy PCF Devices and i'll try ! on test plate
temtronic Smile thank you again ! you are the best !
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