
;btw, just if you are interesting with usage of timer as debounce/control routine, here is an example how to detect buttons` actions. Here eight buttons are connected to port 1 and controled via timer 0. 

#include "C:RigelReads51includesfr51.inc"

; variables
T0_TEMP	 DATA	0x20		; temporal buffer
T0_STATE DATA	0x21		; unbounced state of buttons
T0_FLAGS DATA	0x22		; button action (bit addressable)
BUTTON8	BIT	T0_FLAGS.7
BUTTON7	BIT	T0_FLAGS.6
BUTTON6	BIT	T0_FLAGS.5
BUTTON5	BIT	T0_FLAGS.4
BUTTON4	BIT	T0_FLAGS.3
BUTTON3	BIT	T0_FLAGS.2
BUTTON2	BIT	T0_FLAGS.1
BUTTON1	BIT	T0_FLAGS.0

; reload value for 50Hz at 11.059Mhz is 11059200/12/50/256 = 72
T0_SCALE EQU	(256-72)

;----------------------------------------------------------------
; reset vectors
	ORG 00H
	LJMP START

	ORG	0BH		; timer 0 ISR
	LJMP	T0_ISR

;----------------------------------------------------------------
; Button control based on Interupt service routine of timer 0
T0_ISR:
	MOV	TH0,#T0_SCALE	; reload timer divider
	PUSH	ACC
	PUSH	PSW
	MOV	A,P1		; load current buttons` state
	XCH	A,T0_TEMP	; keep it
	XRL	A,T0_TEMP	; compare with previous one
	JNZ	T0_ISR_END	; state is changed: debounce...
; two read attemps are with the same result - process it
	MOV	A,T0_TEMP
	XCH	A,T0_STATE	; hold stable state
	XRL	A,T0_STATE	; detect changed bits
	ANL	A,T0_STATE	; detect realised buttons
	ORL	T0_FLAGS,A	; indicate changed buttons
T0_ISR_END:
	POP	PSW
	POP	ACC
	RETI

;----------------------------------------------------------------
; main entrance
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

START:
; set timer 0 to 16-bit mode
	CLR	EA
	MOV	TCON,#00000000b	; stop timer 0
	MOV	TMOD,#00000010b	; timer 0 is 16-bit divider
	MOV	TH0,#T0_SCALE
    
; prepare initial values
	MOV	T0_TEMP,P1
	MOV	T0_STATE,T0_TEMP
	MOV	T0_FLAGS,#00000000b
; run button control
	SETB EA
    SETB ET0
    ;MOV	IE,#10000001b	; allow timer 0 interrupt
	SETB	TR0		; start timer 0
; main cycle: sleep till event occures
RUN:	
	MOV	PCON,#00000001b	; idle mode
	NOP			; some parts require it
	LCALL	BUTTON1_PROCESS
	LCALL	BUTTON2_PROCESS
    LCALL BUTTON3_PROCESS
        LCALL BUTTON4_PROCESS
; the rest calls...
	SJMP	RUN

BUTTON1_PROCESS:
	JNB	BUTTON1,BUTTON1_END 
; button 1 was pressed and realised: process it here
	CLR	BUTTON1
BUTTON1_END:
	RET

BUTTON2_PROCESS:
	JNB	BUTTON2,BUTTON2_END
; button 2 was pressed and realised: process it here
	CLR	BUTTON2
BUTTON2_END:
	RET

; the rest buttons` subroutines
BUTTON3_PROCESS:
	JNB	BUTTON3,BUTTON3_END
; button 2 was pressed and realised: process it here
	CLR	BUTTON3
BUTTON3_END:
	RET

    BUTTON4_PROCESS:
	JNB	BUTTON4,BUTTON4_END
; button 2 was pressed and realised: process it here
	CLR	BUTTON4
BUTTON4_END:
	RET
	END

                                 