View previous topic :: View next topic |
Author |
Message |
mohamed2040
Joined: 30 Mar 2013 Posts: 17
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Thu May 30, 2013 1:45 pm |
|
|
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
|
|
Posted: Thu May 30, 2013 2:03 pm |
|
|
thank you for your fast answer
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: 1934 Location: Norman, OK
|
|
Posted: Thu May 30, 2013 2:22 pm |
|
|
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
|
|
Posted: Thu May 30, 2013 2:32 pm |
|
|
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: 1934 Location: Norman, OK
|
|
Posted: Thu May 30, 2013 2:41 pm |
|
|
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
|
|
Posted: Thu May 30, 2013 2:54 pm |
|
|
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: 1934 Location: Norman, OK
|
|
Posted: Thu May 30, 2013 3:01 pm |
|
|
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
|
|
Posted: Thu May 30, 2013 3:18 pm |
|
|
Proteus is not my problem now
my problem is : how can i make communication with 3 devices :
The Pic 16F877 and MC23016 and LCD 16x2 to write "HELLO" on LCD
so i don't say that i had a problem in Proteus |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Thu May 30, 2013 4:40 pm |
|
|
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: 9229 Location: Greensville,Ontario
|
|
Posted: Thu May 30, 2013 5:06 pm |
|
|
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
|
|
Posted: Sat Jun 01, 2013 6:46 am |
|
|
thank you all
yessss Proteus >> Full of bugs with I2C
my problem was solved!
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
|
|
Posted: Sat Jun 01, 2013 6:51 am |
|
|
temtronic
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: 9229 Location: Greensville,Ontario
|
|
Posted: Sat Jun 01, 2013 7:32 am |
|
|
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
|
|
Posted: Sat Jun 01, 2013 4:24 pm |
|
|
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 thank you again ! you are the best ! |
|
|
|