Simple time keeper

I’ve been running this simple time keeping code for several days now,
The uC is a '1284P with 16 MHz xtal and 2 22pF caps, just one that happened to be readily at hand.
Started it by giving it an initial time, then opening the Serial Monitor ~ 2 seconds before that time, as that seemed about the right time to reset and open start the program.

unsigned long currentMicros;
unsigned long previousMicros;
unsigned long elapsedTime;

// Initial time to start, adjust as needed.

byte hundredths;
byte tenths;
byte oldTenths;
byte secondsOnes = 0;
byte oldSecondsOnes;
byte secondsTens = 0;
byte minutesOnes = 2;
byte minutesTens = 3;
byte hoursOnes = 4;
byte hoursTens = 0;

void setup() {

  Serial.begin(115200); // make serial monitor match
  Serial.println ("Setup Done");
}

void loop() {

  currentMicros = micros();

  // how long's it been?
  elapsedTime = currentMicros - previousMicros;
  if ( elapsedTime >= 10000UL) { // 0.01 second passed? Update the timers
    previousMicros  = previousMicros + 10000UL;

    hundredths = hundredths + 1; // increment
    if (hundredths >= 10) {
      hundredths = 0; // else rollover and increment next digit

      tenths = tenths + 1;
      if (tenths >= 10) {
        tenths = 0;
        secondsOnes = secondsOnes + 1;
        if (secondsOnes >= 10) {
          secondsOnes = 0;
          secondsTens = secondsTens + 1;
          if (secondsTens >= 6) {
            secondsTens = 0;
            minutesOnes = minutesOnes + 1;
            if (minutesOnes >= 10) {
              minutesOnes = 0;
              minutesTens = minutesTens + 1;
              if (minutesTens >= 6 ) {
                minutesTens = 0;
                hoursOnes = hoursOnes + 1;
                if ((hoursTens == 2) && (hoursOnes == 4)) {
                  hoursOnes = 0;
                  hoursTens = 0;
                }// hours total rollover check
                if (hoursOnes >= 10) {
                  hoursOnes = 0;
                  hoursTens = hoursTens  + 1;
                } // hoursOnes rollover check
              } // minutesTens rollover check
            } // minutesOnes rollover check
          } // secondsTens rollover check
        } // secondsOnes rollover check
      } // tenths rollover check
    } // hundredths rollover check
  }// hundredths passing check

  if (oldTenths != tenths) { // show the elapsed time
    oldTenths = tenths;
    Serial.print(hoursTens);
    Serial.print(hoursOnes);
    Serial.print(":");
    Serial.print(minutesTens);
    Serial.print(minutesOnes);
    Serial.print(":");
    Serial.print(secondsTens);
    Serial.print(secondsOnes);
    Serial.print(".");
    Serial.println (tenths);

  } // end one second check

} // end loop

Still tracking pretty good sitting in my 60F to 85F living room after a couple of days.
Summer time, no AC, cool nights.

Would be easy to read a couple of buttons to bump the time up & down for setting the time,
and to add a time to check against for an alarm function.

I use the individual digits method to make it easy to drive 7 segment displays.

timeKeepingTest.jpg

I like to wait for an input key to synchronize time manually:

Still tracking pretty good sitting in my 60F to 85F living room after a couple of days.

You are allowed to work in your living room? :-X

A 3231 costs .99
.

Pretty good Bob! A good crystal?

Your project reminds me of one of mine:

Mine uses two buttons to set the time.

larryd:
You are allowed to work in your living room? :-X

Mrs. CrossRoads is also an engineer.

A 3231 costs .99

Getting a dead accurate clock working using a software phase-locked loop? Priceless.

She's definitely a keeper!

.