[11]
Example Initialization Program
Slave Address = 0x3F
/*****************************************************/
const char Slave = 0x7E;
//slave address+Write bit
const char Comsend = 0x00;
const char Datasend = 0x40;
/*****************************************************/
void I2C_out(unsigned char j)
//I2C Output
{
int n;
unsigned char d;
d=j;
for(n=0;n<8;n++){
//send 8 bits
if((d&0x80)==0x80)
//get only the MSB
SDA=1;
//if 1, then SDA=1
else
SDA=0;
//if 0, then SDA=0
d=(d<<1);
//shift data byte left
SCL = 0;
SCL = 1;
//clock in data
SCL = 0;
}
SCL = 1;
while(SDA==1){
//wait here until ACK
SCL=0;
SCL=1;
}
SCL=0;
}
/*****************************************************/
void I2C_Start(void)
{
SCL=1;
SDA=1;
SDA=0;
SCL=0;
}
/*****************************************************/
void I2C_Stop(void)
{
SDA=0;
SCL=0;
SCL=1;
SDA=1;
}
/*****************************************************/
void Show(unsigned char *text)
{
int n,i;
char page=0xB0;
//first page
for(i=0;i<13;i++){
//100 pixels = 12.5 pages
I2C_Start();
I2C_out(Slave);
I2C_out(Comsend);