Arduino Uno 74HC595
MOSI (11) => DS (14) - first chip only
SCK (13) => SH_CP (11)
SS (10) => ST_CP (12) - SPI /CS
Other '595 connections
+5V => /MR (10) - reset disabled
Gnd => /OE (13) - outputs on
Q7' (9) => DS (14) of next chip
+5V => Vcc (16)
Gnd => Gnd (8 )



if((millis()-ms)>ONE_SEC){
ms+=ONE_SEC;
BCDtime++;
fixHMS();
}
by keeping a running count of 'milliseconds' and adding 1000 to it whenever it lags by more than 1000. There seem to be a lot of reports of problems with millis() accuracy. . . .
)
You already have a 16MHz crystal for the ATmega16U2 running the USB interface, so why not tap into that accurate clock for the main ATmega328P MCU instead of fitting a s--tty resonator?
No wonder Arduinos have such a rep for crappy timekeeping.
An ATmega48 will do easily.
#define ONE_SEC 997784UL // micros() in one second trimmed for resonator.which was calculated based on the time lost during a 15 hour run, and:int main() {
uint32_t t; // temp for digit extraction
uint8_t d; // extracted digit, then its font
uint32_t ms; // tick counter to sync to system micros count.
setup(); // initialisation
ms=micros();
while(1){ // Superloop
flags.bMode=!digitalRead(BTNMODE);
flags.bSet=!digitalRead(BTNSET);
if((micros()-ms)>ONE_SEC){
ms+=ONE_SEC;
BCDtime++;
fixHMS();
}
switch(flags.bSet<<1|flags.bMode){
case 0b00: //Normal
display(BCDtime>>8);
VFDsymbWrite(VFD_SYMB_DOT,(BCDtime&1)); //Flashing dot
break;
case 0b01: //Mode pressed
display(BCDtime&0xFFFFUL);
VFDsymbWrite(VFD_SYMB_DOT,0); //No dot
break;
case 0b10: //Set pressed
BCDtime+=0x000100UL; //Increment only minutes
if((BCDtime&0x00FF00UL)==0x005A00UL) BCDtime&=0xFF00FFUL; //Wrap 60 to 00
goto doSet;
case 0b11: //Set + Mode pressed
BCDtime+=0x010000UL; //Increment hours
doSet:
BCDtime&=0xFFFF00UL; //Clear seconds
ms=micros();
fixHMS();
display(BCDtime>>8);
VFDsymbWrite(VFD_SYMB_DOT,1); //Fixed dot
delay(80);
break;
}
delay(20);
} //endWhile(1)
}//endFn main
which is how I'm keeping time in my main() function (I've got a dummy .ino file so I can program it in real GCC C++ without the IDE mangling it before compilation).
- it was scanning one extra non-existent digit, and the variable after the display buffer array was the flags structure, which resulted in the top segment of the third digit getting lit, (or brightened if already lit) whenever the [Secs] button was pressed. Fortunately I had the display well dimmed so it was obvious that segment was getting extra time in each frame, and that it wasn't display buffer corruption.
#define ONE_SEC 999187UL // micros() in one second trimmed for resonator.
and is tracking a NNTP corrected PC clock to better than 2 seconds a day. To do any better, I'd have to either write a sketch to automate the clock setting and error measurement, or use a *good* frequency meter.