For starters, IF tapcount > 900 is never going to be true and ticks = 256 will result in ticks being set to 0 since both tapcount and ticks are declared as BYTEs.

/Henrik.