The 8051 compiler doesn't support 64-bit ints, so the old
code used an iterative method in 32-bit values. That could take
a long time when the frequency was mis-entered in Hz or MHz instead of
kHz.
This direct-computation uses 64-bit ints, but takes a fixed amount of
time for any inputs.