Reading and reacting to menu switches
Posted: Fri Jul 20, 2007 9:42 am
Further to my post http://matrixmultimedia.com/mmforums/vi ... php?t=2910 I now have a macro running to read my 4 menu setting switches on Port B upper nibble. It has
Interrupt on port B
Read port B upper nibble
Decode reading to decide which switch is pressed
Set one of 4 variables from 0 to 1 to indicate which switch is pressed.
Exit to main program.
Next problem is how long do I leave the variables set and how do I clear them back to zero? They have to remain set for about 1 second so that all the many subroutines of main code that need to react to these switches can react. Could pepper the main code with a β€clear variables to zero’ macro at critical points, but easy to forget where to put it so end up prematurely clearing them or forgetting to do so.
Better would be some sort of timer running in background that auto zeroed the 4 variables after 1 second. How can this be done? Would some variant of this code that you gave me in http://matrixmultimedia.com/mmforums/vi ... php?t=3425 work? Afraid I don’t understand timers yet.
Main Program
Start
Calculation - counter = 0
Interrupt - Enable timer interrupts
While 1 - Main Program Loop
End
Timer_Interrupt_Macro
Start
Decision - Counter = 255
YES: Decision - PIN on - YES - Turn Off Pin / NO - Turn On Pin
NO: Calculation - Counter = Counter + 1
End
Alternatively is there a much more elegent way to read and react to menu switch inputs?
Interrupt on port B
Read port B upper nibble
Decode reading to decide which switch is pressed
Set one of 4 variables from 0 to 1 to indicate which switch is pressed.
Exit to main program.
Next problem is how long do I leave the variables set and how do I clear them back to zero? They have to remain set for about 1 second so that all the many subroutines of main code that need to react to these switches can react. Could pepper the main code with a β€clear variables to zero’ macro at critical points, but easy to forget where to put it so end up prematurely clearing them or forgetting to do so.
Better would be some sort of timer running in background that auto zeroed the 4 variables after 1 second. How can this be done? Would some variant of this code that you gave me in http://matrixmultimedia.com/mmforums/vi ... php?t=3425 work? Afraid I don’t understand timers yet.
Main Program
Start
Calculation - counter = 0
Interrupt - Enable timer interrupts
While 1 - Main Program Loop
End
Timer_Interrupt_Macro
Start
Decision - Counter = 255
YES: Decision - PIN on - YES - Turn Off Pin / NO - Turn On Pin
NO: Calculation - Counter = Counter + 1
End
Alternatively is there a much more elegent way to read and react to menu switch inputs?