??? 09/23/04 17:55 Read: times |
#78027 - RE: Defining debouncing Responding to: ???'s previous message |
Hi Craig,
I think I've got it, here's the new code and it appears to be working. The next thing I want to work on is this part: When it comes to debouncing the human or "throttling" the input what you can do is first wait for a valid signal. That means you debounce for 50-100ms and if the signal indicates the button was pressed the whole time then you assume you have a valid input. Once you have a valid input you toggle your LED. Then you execute a loop which does nothing more than wait for the button to be released. As long as the button is still pressed you keep looping. As soon as the button is released you go back to your main "DELAY" section of the code which will wait for the next keypress. .ORG 2000H MOV A,#9FH ;SET UP MOV DPTR,#0F803H ; PORT A MOVX @DPTR,A ; AS AN INPUT MOV A,#89H ;SET UP MOV DPTR,#0F903H ; PORT E MOVX @DPTR,A ; AS AN OUTPUT MOV 40H,#00 ;CLEAR FLAG-IS LED ON/OFF MOV A,#0FFH ;TURN OFF MOV DPTR,#0F901H ; ALL LEDS MOVX @DPTR,A ; TO PORT E RESET1:MOV R6,#10 ;OUTER LOOP TO DET. VALID STATE RESET:MOV R7,#00 ;INNER LOOP TO DET. VALID STATE MOV DPTR,#0F800H ;POINT TO PORT A MOVX A,@DPTR ; TO READ SWITCH MOV 50H,A ;SAVE RESULT OF SWITCH READ READ:MOV DPTR,#0F800H ;POINT TO PORT A MOVX A,@DPTR ;READ SWITCH AGAIN CJNE A,50H,RESET1 ;COMPARE SAVED TO NEW DJNZ R7,READ ;DECREMENT INNER LOOP DJNZ R6,READ ;DECREMENT OUTER LOOP MOV A,50H ;IS SWITCH OPEN/CLOSED JNZ RESET1 ;IF SWITCH OPEN (A=NOT ZERO) MOV A,40H ;MONITOR FLAG JNZ CLEAR SET:INC 40H ;SET FLAG MOV DPTR,#0F901H ;POINT TO PORT E MOV A,#0FFH MOVX @DPTR,A ;TURN ON LED SJMP RESET CLEAR:DEC 40H ;CLEAR FLAG MOV DPTR,#0F901H ;POINT TO PORT E MOV A,#0FEH MOVX @DPTR,A ;TURN OFF LED SJMP RESET I hope to post the final product tonight. Thanks-Lisa |