Sorry for the long absence, long week ![]()
Changed all the int's to bytes on the clock parts but no change.
also changed counter to uint16_t counter;
When i set the count to 373 it saves.
But only appears as 373 on newest run. Older numbers apear as 3101, and 3098. also parts of the next set of byte's that have not been writen to or should not have been appear changed.
void saveTheCount(){ // this should only run once per day
if(savecount == 1 && saved == 0){
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
byte second = bcdToDec(Wire.read());
byte minute = bcdToDec(Wire.read());
byte hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
byte weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - saturday
byte monthDay = bcdToDec(Wire.read());
byte month = bcdToDec(Wire.read());
byte year = bcdToDec(Wire.read());
savedAddress = eeprom_read_word((uint16_t*)10); //read address for starting position
// saves in mm/dd/yy|count order
eeprom_write_byte((uint8_t*)savedAddress, month); //eg address 100
eeprom_write_byte((uint8_t*)savedAddress + 1, monthDay); //101
eeprom_write_byte((uint8_t*)savedAddress + 2, year); //102
eeprom_write_word((uint16_t*)savedAddress + 3, counter); //103 and 104 since its a word (2 bytes)
savedAddress = savedAddress + 5; // increment address and prepare to save
if(savedAddress >= 4090){ //rollover to starting address 100
savedAddress = 100;
}
eeprom_write_word((uint16_t*)10, savedAddress);
//lets add offset to second and save to update clock
second = 1 + offset + second; //not sure how long the time interval is from the last read to now so add 1 second,
//since I know this DS1307 is 2-6s off per day :( (tested already)
//this is overkill but ya never know
if(second >= 61){ //just incase seconds ends up at 61+
second = second - 60;
minute = minute + 1; // only runs at around min 30-32 so no need to carry to hours
}
//end overkill
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero); //stop oscillator
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(weekDay));
Wire.write(decToBcd(monthDay));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.write(zero); //start
Wire.endTransmission();
saved = 1; // this way it only runs once per day, after that it is returned
// to 0 a few minutes later after savecount statement is no longer true
}
}
this part is the part shown in the pics, it runs 7 times, once for each row on the screen
uint8_t m; //month // these change during each run
uint8_t d; //day
uint8_t y; //year
uint16_t c; //count
itoa (savedAddress, array, 10); //debugging
glcd.drawstring(88, 0, array); //debugging
//////////First run
m = eeprom_read_byte((uint8_t*)savedAddress);
d = eeprom_read_byte((uint8_t*)savedAddress+1);
y = eeprom_read_byte((uint8_t*)savedAddress+2);
c = eeprom_read_word((uint16_t*)savedAddress+3);
itoa (m, array,10);
glcd.drawstring(0, 1, array);
itoa (d, array,10);
glcd.drawstring(12,1, "/");
glcd.drawstring(18, 1, array);
itoa (y, array,10);
glcd.drawstring(30,1, "/");
glcd.drawstring(36, 1, array);
itoa (c, array,10);
glcd.drawstring(52,1, "|");
glcd.drawstring(57, 1, array);
savedAddress = savedAddress + 5;
any ideas welcome
btw
johnwasser, if i dont use uint16_t* it throws errors.

