I have a 7"display but the only examples i find are pic examples (i think)
I ported the SPI version for the display already from that to arduino and that works as expected.
But now i'm busy with the I2C code so i can choose which connection i want. and make a library for it.
I don't know if its necessary but i will use it on my due
but i have a couple of Wire issues i'm not sure off.
I think the only functions which needs to be corrected are the
master_ACK
slave_ACK
IIC_WriteByte
IIC_ReadByte
so i think start en stop voids can be removed
Start() and stop() changed for Wire.beginTransmission(); and Wire.endTransmission();
sbit MCU_RST=P2^3;
sbit SCL=P1^1;
sbit SDA=P1^0;
sbit next =P2^7; //next
bit ack;
#define write_data_addr 0x0c //slave addresses with write data
#define read_data_addr 0x0d //slave addresses with write data
#define write_cmd_addr 0x0e //slave addresses with write command
#define read_cmd_addr 0x0f //slave addresses with read status
//I2C_Init()
void SPI_Init(void)
{
// SCL = 1;
// SDA = 1;
wire.begin(); // i think only this line instead of the two above
}
//start
void start(void)
{
SDA=1;
delay(1);
SCL=1;
delay(1);
SDA=0;
delay(1);
SCL=0;
delay(1);
}
//stop
void stop(void)
{
SDA=0;
delay(1);
SCL=1;
delay(1);
SDA=1;
delay(1);
SCL=0;
delay(1);
}
//Host sends an ACK
//ack=0 ACKNOWLEDGE ack=1 NOT ACKNOWLEDGE
void master_ACK(bit acknow)
{ SDA=acknow;
delay(1);
SCL=1;
delay(1);
SCL=0;
delay(1);
}
//Slave sends ACK
void slave_ACK(void)
{uchar i=0;
delay(1);
SDA=1;
delay(1);
SCL=1;
delay(1);
while((SDA==1)&&i<200)i++;
delay(1);
SCL=0;
delay(1);
}
//*********I2C send byte
void IIC_WriteByte(uchar Byte)
{uchar t;
for(t=0;t<8;t++)
{ delay(1);
SDA=(bit)(Byte & 0x80) ;
Byte <<=1;
delay(1);
SCL=1;
delay(1);
SCL=0;
delay(1);
}
slave_ACK();
}
//*********I2C Read byte
uchar IIC_ReadByte(void)
{uchar t,read_data=0;
SCL=0;
delay(1);
SDA=1;
delay(1);
for(t = 0; t < 8; t++)
{ delay(1);
SCL = 1;
delay(1);
read_data<<=1;
if(SDA == 1)
read_data=read_data|0x01;
SCL=0;
}
master_ACK(ack);
return read_data;
}
void LCD_CmdWrite(uchar cmd)
{
Wire.beginTransmission();
IIC_WriteByte(0x0e);
IIC_WriteByte(cmd);
Wire.endTransmission();
}
//////////////SPI Write data or parameter
void LCD_DataWrite(uchar Data)
{
Wire.beginTransmission();
IIC_WriteByte(0x0c);
IIC_WriteByte(Data);
Wire.endTransmission();
}
///////////////Read data or parameter
uchar LCD_DataRead(void)
{
uchar Data;
Wire.beginTransmission();
IIC_WriteByte(0x0d);
ack=1;
Data=IIC_ReadByte();
Wire.endTransmission();
return Data;
}
///////////SPI Read status
uchar LCD_StatusRead(void)
{
uchar Data;
Wire.beginTransmission();
IIC_WriteByte(0x0f);
ack=1;
Data=IIC_ReadByte();
Wire.endTransmission();
return Data;
}
Already Thanks
Johan