Hi,

I think you should wait for the button ( up or down ) to be released BEFORE jumping to "setfreq".
That implies The BUTTON command to be slightly modified for an auto-repeat feature ... AND also to increase the debugging time to, say, 100-250 ms ...

Also note you can simplify the output to PortA.0-3 ... as the 4 lower bits of "myfreq" are the same of your Output. ( just have to "catch" the invalid codes ...)

Alain