Back again--
I thought it would be helpful to provide a couple of code segments from the program I am currently writing.
First is a function that delays writing until the slave has provided an ack. Next is a function that I use to convert integers to ASCII numbers with the added 0x03 needed to write to the display using C18.
Third is some of the display code.
Foggy
void test_ack()
{
if(SSPCON1bits.WCOL) //DDPBUF register, conditions not valid for transmission
SSPCON1bits.WCOL = 0; //<7>
if (PIR1bits.SSPIF=1) //<7> transmission complete flag
PIR1bits.SSPIF = 0; //
while(SSPCON2bits.ACKSTAT) //<6>acknowledge not received when ACKSTAT = 1
{
}
while(SSPSTATbits.BF) //<0> indicates SSPBUF is full
{
sspbuf = SSPBUF; // reading the buffer clears it
}
}
void segments(void)
void segments(void)
// below converts the digital number from above to individual integers
// look up table for ASCII numbers for Newhaven display
{
run_minutes=set_run_min; // ones
ones=run_minutes % 10;
run_minutes /= 10; // tens
tens = run_minutes % 10;
run_minutes /= 10; // hundreds
hundreds = run_minutes % 10;
seg_value[0] = 0b00110000; // 0
seg_value[1] = 0b00110001; // 1
seg_value[2] = 0b00110010; // 2
seg_value[3] = 0b00110011; // 3
seg_value[4] = 0b00110100; // 4
seg_value[5] = 0b00110101; // 5
seg_value[6] = 0b00110110; // 6
seg_value[7] = 0b00110111; // 7
seg_value[8] = 0b00111000; // 8
seg_value[9] = 0b00111001; // 9
p = seg_value[ones]; // p,q & r read the values from the array
q = seg_value[tens];
r = seg_value[hundreds];
StartI2C();
WriteI2C(0x50); //slave address
test_ack();
WriteI2C(0xFE); // clears screen
test_ack();
WriteI2C(0x51); // command
StopI2C();
Delay10TCYx(1);
}
segments(); //function call to get numbers
// Delay10TCYx(1);
StartI2C();
// test_ack();
WriteI2C(0x50); //slave address
test_ack();
WriteI2C(0xFE); // these lines for contrast
test_ack();
WriteI2C(0x52); //
test_ack();
WriteI2C(0x20); //set to 20-21 for best appearance
test_ack();
WriteI2C(0xFE); // these lines for backlight brightness
test_ack();
WriteI2C(0x53);
test_ack();
WriteI2C(0x05); // set to 05
test_ack();
WriteI2C(0xFE); //cursor position
test_ack();
WriteI2C(0x45); //cursor position
test_ack();
WriteI2C(0x00); // cursor position
test_ack();
putsI2C(set_run);
test_ack();
WriteI2C( r);
test_ack();
WriteI2C(q);
test_ack();
WriteI2C(p);
test_ack();
WriteI2C(0xFE); //cursor position
test_ack();
WriteI2C(0x45); //cursor position
test_ack();
WriteI2C(0x14); // cursor position col 1, row 3
test_ack();
putsI2C(lower_pres1);
test_ack();
WriteI2C(0xFE); //cursor position
test_ack();
WriteI2C(0x45); //cursor position
test_ack();
WriteI2C(0x54); // cursor position col 1, row 4
test_ack();
putsI2C(lower_pres2);
StopI2C();
//Delay10TCYx(1);
}