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.
If you needed interrupt driven buttons it would pay to set the timer in the ISR andCode: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
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
Now if you have to display the seconds anywhere just:Code:IF Seconds = 240 THEN Seconds = 0 Minutes = Minutes + 1 MinutesChanged = 1 ENDIF
If you needed a high speed signal find and asm routine to rotate a byte with carry, and output bit.0 out a pin.Code:DisplaySeconds var byte DisplaySeconds = Seconds / 4 ‘ divide by four ‘print Hours, Minutes, DisplaySeconds.
The benefit of that is ensuring it takes a constant period of time to run the check.
You might find in this code:
once it’s decompiled it could take a cycle less to execute depending on the result.Code:IF flag = 0 then flag = 1 else flag = 0 endif
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