Hi:
I have been fighting with this all day. I am trying to write the values read from a DS1307 to an I2C based LCD Display.
I have the display working perfectly and can write anything I want, move the cursor around and anything else I want it to do.
I have two functions that take the value that is read from the DS1307 and split it into a Tens value and a Ones value which I want to write to the cursor locations I have set up.
Each of these functions tests the value of one of the digits and assigns the Hex code for the character to send to the LCD. Everything that goes to the LCD is in Hex.
I have the correct Hex value at the end of each function, but when I check the value in the main code that was supposed to flow through the return(val), it is always 0.
I don't understand why I am not getting the Hex value that is in the variable before the return().
I have commented all of the code including what it does and doesn't show correctly.
I would really appreciate any and all suggestions or comments on why this isn't working.
Thanks
Tim Vukman
The code from the main Loop() is here:
byte RHours; // Setup holder for read of HOURS Register
DS_register = DS_Hours; // Set desired address to HOURS
read_DS1307(DS_address); // Pass values to Read Routine
RHours = DS_data; // Save BCD returned from HOURS holder
Serial.print("Hours Read :"); // Debug write to show value read
Serial.println(RHours, DEC); // Debug write of value returned ****** PERFECT *******
LCD_data = 0x47; // Cursor Position for Hours
LCD_data2 = 2; // Column 2
LCD_data3 = 1; // Line 1
write_AL202_triple(LCD_address, LCD_data, LCD_data2, LCD_data3);
delay(100);
Split_DS1307_Tens(DS_data); // Split off the Tens digit from value read
LCD_data = (DS_Tens, HEX); // Copy the value returned to data byte for LCD write function
Serial.print("DS_Tens in Hours Loop: "); // Show me what I have now ********ALWAYS 0*********
Serial.println(DS_Tens, HEX);
Serial.print("LCD Hours in hours loop: "); // Show me what I will send ********Shows 10H****
Serial.println(LCD_data, HEX);
LCD_Send_Char(LCD_address); // Send WANTED HEX value to LCD
delay(100);
Split_DS1307_Ones(DS_data); // Split off the Ones digit from value read
LCD_data = (DS_Ones, HEX); // Copy the value returned to data byte for LCD write function
Serial.print("LCD Ones in hours loop: "); // Show me what I have now *******ALWAYS 0********
Serial.println(LCD_data, HEX); // Show me what I will send ********Shows 10H****
LCD_Send_Char(LCD_address);
delay(100);
These are the functions that split the value read from the DS1307:
//************************************************************************
// Split Byte Returned from DS1307 Read for Tens
//************************************************************************
byte Split_DS1307_Tens(byte Hours)
{
byte DS_Tens;
DS_Tens = (Hours & 0xF0); // Take off the first digit
if (DS_Tens == 0) { DS_Tens = 0x30; } // Swap the hex value in
else if (DS_Tens == 1) { DS_Tens = 0x31; }
else if (DS_Tens == 2) { DS_Tens = 0x32; }
else if (DS_Tens == 3) { DS_Tens = 0x33; }
else if (DS_Tens == 4) { DS_Tens = 0x34; }
else if (DS_Tens == 5) { DS_Tens = 0x35; }
else if (DS_Tens == 6) { DS_Tens = 0x36; }
else if (DS_Tens == 7) { DS_Tens = 0x37; }
else if (DS_Tens == 8) { DS_Tens = 0x38; }
else if (DS_Tens == 9) { DS_Tens = 0x39; }
Serial.print("DS_Tens *Split*:"); // Show me what I have
Serial.println(DS_Tens, HEX); // ALWAYS CORRECT
return (DS_Tens, HEX); //******SEEMS TO ALWAYS RETURN 0*************
delay(100);
}
//************************************************************************
// Split Byte Returned from DS1307 Read for Ones
//************************************************************************
byte Split_DS1307_Ones(byte Hours)
{
byte DS_Ones;
DS_Ones = (Hours & 0x0F); // Take off the second digit
if (DS_Ones == 0) { DS_Ones = 0x30; } // Swap the hex value in
else if (DS_Ones == 1) { DS_Ones = 0x31; }
else if (DS_Ones == 2) { DS_Ones = 0x32; }
else if (DS_Ones == 3) { DS_Ones = 0x33; }
else if (DS_Ones == 4) { DS_Ones = 0x34; }
else if (DS_Ones == 5) { DS_Ones = 0x35; }
else if (DS_Ones == 6) { DS_Ones = 0x36; }
else if (DS_Ones == 7) { DS_Ones = 0x37; }
else if (DS_Ones == 8) { DS_Ones = 0x38; }
else if (DS_Ones == 9) { DS_Ones = 0x39; }
Serial.print("DS_Ones *Split*:"); // Show me what I have
Serial.println(DS_Ones, HEX); // ALWAYS CORRECT
return (DS_Ones); //******SEEMS TO ALWAYS RETURN 0*************
delay(100);
}
This is the code that sends the Hex value to the LCD:
//************************************************************************
// LCD Send Single Character Function *****VERIFIED*****
//************************************************************************
void LCD_Send_Char(byte LCD_address)
{
Wire.beginTransmission(LCD_address);
Wire.send(LCD_data);
Serial.print("LCD_data Send Single: "); // Shows the value sent
Serial.println(LCD_data, HEX); // Currently *****ALWAYS 10H*******
Wire.endTransmission();
delay(100);
}