But, I like to list subroutines with those called preceding those doing the calling. This leaves the main routine last. Notice that interrupts are disabled at the beginning of the time setting routine and enabled on leaving. This is necessary because the interrupt routine works with the same registers as the time setting routine. We can't have both changing the registers 'at the same time'.
Some code space is saved by combining wait routines for three separate pushbuttons.
The bit number has to be a constant. Instead we work with the whole port and what is called a 'mask'. A mask is like a piece of cardboard with holes in it that you place over the binary representation of a register. The mask has 1's where the holes are, zeros in the other bit positions. AND' the number with a mask to zero certain bits.