;       Input variable(s) : msec_lo
;       Output variable(s) :
;       Variable(s) affected :
;       Flag(s) affected :
;
                Size : 3 bytes + 1 bytes per jump location
;       Timing (turbo) : 8 cycles
;
:path_switch
MOV W,msec_lo ;load switch selector byte AND W,#00000011b ;keep low 2 bits - 4 position JMP PC+W ;jump to switch position pointer :pos0 JMP pb0 ;pushbutton 0 checking routine :pos1 JMP pb1 ;pushbutton 1 checking routine :pos2 JMP pb2 ;pushbutton 2 checking routine :pos3 JMP pb3 ;pushbutton 3 checking routine ;
;
;****** Virtual Peripheral: Push Buttons*
;
; This routine monitors any number of pushbuttons, debounces them properly
; as needed, and flags the main program code as valid presses are received.
; *Note: this routine requires the Time Clock virtual peripheral or similar
;
pre-processing timer routine. ;
;       Input variable(s) : pb0_down,pb1_down,debounce0,debounce1
;       
                                                              pb2_down,pb3_down,debounce2,debounce3
;       Output variable(s) : pb0_pressed, pb1_pressed, pb2_pressed, pb3_pressed
;       Variable(s) affected : debounce0, debounce1, debounce2, debounce3
;       Flag(s) affected : pb0_down,pb1_down,pb0_pressed,pb1_pressed
;       
   pb2_down,pb3_down,pb2_pressed,pb3_pressed ; Size : 12 bytes per pushbutton + actions (see below**) ;                                  + 1 byte if path switch not used
;       Timing (turbo) : 7,10, or 12 cycles/pushbutton (unless path switch used)
;
+ actions (see below**) ;
pb0
;
BANK buttons ;select bank (if not done elsewhere) JB button0,:pb0_up ;button0 pressed? JB pb0_down,:done_pb0 ;yes, but is it new press? INC debounce0 ; and adjust debounce count JNB debounce0.hold_bit,:done_pb0 ;wait till long enough SETB pb0_down ;yes, flag that button is down ;**If the button activity is short (a few bytes), it can fit here, though be
; careful that longest possible interrupt doesn't exceed int_period # of cycles.
;
; <short code segment can go here>
;
;**Otherwise, use this flag to process button press in main code (and don't
; forget to reset the flag once the button activity is complete).
SETB pb0_pressed ; and set pb0 action flag SKIP ;skip next instruction :pb0_up CLRB pb0_down ;button up, clear flag CLR debounce0 ; and clear debounce count :done_pb0
;
JMP done_pbs ;this needed only if path switch used pb1 IF num_buttons>1 ;more than 1 push button? ; BANK buttons ;do bank select (if not done elsewhere) JB button1,:pb1_up ;button1 pressed? JB pb1_down,:done_pb1 ;yes, but is it new press? INC debounce1 ; and adjust debounce count JNB debounce1.hold_bit,:done_pb1 ;wait till long enough SETB pb1_down ;yes, flag that button is down