done_int mov     w,#-int_period      ;interrupt every 'int_period' clocks retiw                       ;exit interrupt ;
;****** End of interrupt sequence
;
;************************** RESET ENTRY POINT *****************************
;
reset_entry
;
PAGE start ;Set page bits and then ; JMP start ; jump to start of code ;
;*********************
;* Main Program Code *
;*********************
;
start
mov     !rb,#%00001111          ;Set RB in/out directions
CLR     FSR                     ;reset all ram starting at 08h
:zero_ram SB      FSR.4                                                                     ;are we on low half of bank?
SETB    FSR.3                   ;If so, don't touch regs 0-7
CLR     IND                     ;clear using indirect addressing
IJNZ    FSR,:zero_ram           ;repeat until done
MOV     !OPTION,#%10011111      ;enable rtcc interrupt ;
Main:loop
;
;the following code watches pb0-pb3 for presses and acts on them
button_check
;
BANK buttons ;select pb bank MOV W,pbflags ;load pushbutton flags AND W,#00001111b ;keep only 'pressed' flags JZ :no_press ;jump ahead if not pressed MOV temp,W ;store flags temporarily CLR temp2 ;clear 2nd temp storage reg. :which_pb INC temp2 ;increment 2nd temp value RR temp ;check which button SC ;skip ahead if not this one JMP :which_pb ;keep looping MOV W,--temp2 ;get 2nd temp value (less 1) MOV temp,W ;save it in temp MOV W,#11110000b ;get clear mask for pbflags AND pbflags,W ;clear all "pressed" flags MOV W,temp ;get which button pressed JMP PC+W ;Go do PB routines :pb0 JMP pb0_action ;do pb0 action :pb1 JMP pb1_action ;do pb1 action :pb2 JMP pb2_action ;do pb2 action :pb3 JMP pb3_action ;do pb3 action :no_press
;
;
<main program code goes here> ; JMP     Main:loop ;back to main loop ;
pb0_action
;
;
<pb0 action here> ; JMP Main:loop ;
pb1_action
;
;
<pb1 action here> ; JMP Main:loop