Hi Robert,
Getting to know the timer is fine, but that would be otherwise extreme for button debounce.
You can do a program timer to lock the button for a delay after being pushed.
Code:
dtimer var byte
dtimer = 0
main:
IF port.1 = 1 && dtimer = 0 then
dtimer = 200
gosub fire ‘oh no, he pushed the button, all hell is going to break loose.
endif
IF dtimer > 0 then
dtimer = dtimer-1
endif
goto main
If you needed interrupt driven buttons it would pay to set the timer in the ISR and
decrement the timer in your main program, and reenable interrupts when the timer reaches zero.
It’s good practice to keep interrupts for the thing that really needs it… like keeping real time is a good example 
With regard to the speed, you can’t count to 400 in your Ticks byte,
but you can count to 240 Seconds (instead of 60 Seconds) to delay the time
Code:
IF Seconds = 240 THEN
Seconds = 0
Minutes = Minutes + 1
MinutesChanged = 1
ENDIF
Now if you have to display the seconds anywhere just:
Code:
DisplaySeconds var byte
DisplaySeconds = Seconds / 4 ‘ divide by four
‘print Hours, Minutes, DisplaySeconds.
If you needed a high speed signal find and asm routine to rotate a byte with carry, and output bit.0 out a pin.
The benefit of that is ensuring it takes a constant period of time to run the check.
You might find in this code:
Code:
IF flag = 0 then
flag = 1
else
flag = 0
endif
once it’s decompiled it could take a cycle less to execute depending on the result.
So if you’re trying to produce a square wave it could be jagged.
These things are easier to do with HPWM of you have the hardware though.
Bookmarks