Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
11/03/03 21:18
Read: times


 
#57771 - RE: toggle function
Responding to: ???'s previous message
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.
; 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
	CSEG	AT 0x0000
	JMP	START

	ORG	0x000B		; timer 0 ISR
	JMP	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,#00000001b	; 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
	MOV	IE,#10000010b	; 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
	CALL	BUTTON1_PROCESS
	CALL	BUTTON2_PROCESS
; the rest calls...
	JMP	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

	END

Good days!

List of 28 messages in thread
TopicAuthorDate
toggle function            01/01/70 00:00      
   RE: toggle function            01/01/70 00:00      
   RE: toggle function            01/01/70 00:00      
   RE: toggle function            01/01/70 00:00      
   RE: toggle function            01/01/70 00:00      
      RE: toggle function            01/01/70 00:00      
         Hardware De-bounce            01/01/70 00:00      
            De-bouncing is more complex!            01/01/70 00:00      
            RE: Hardware De-bounce            01/01/70 00:00      
               RE: Hardware De-bounce            01/01/70 00:00      
                  RE: Hardware De-bounce            01/01/70 00:00      
                     RE: Classic Hardware De-bounce            01/01/70 00:00      
                        RE: Classic Hardware De-bounce            01/01/70 00:00      
            RE: Hardware De-bounce            01/01/70 00:00      
               RE: Hardware De-bounce            01/01/70 00:00      
   Switch bounce - Scope plots            01/01/70 00:00      
      RE: Switch bounce - Scope plots            01/01/70 00:00      
      APOLOGIES... :(            01/01/70 00:00      
         RE: Note            01/01/70 00:00      
             Resistor for capacitor dischar            01/01/70 00:00      
               RE: Resistor for capacitor dischar            01/01/70 00:00      
               RE: Added Resistor            01/01/70 00:00      
                  RE: Added Resistor            01/01/70 00:00      
                     RE: Added Resistor            01/01/70 00:00      
                     Did you read my last reply?            01/01/70 00:00      
      RC + Schmitt-trigger - Scope plots            01/01/70 00:00      
   RE: toggle function            01/01/70 00:00      
      RE: toggle function            01/01/70 00:00      

Back to Subject List