| ??? 03/10/03 10:37 Read: times |
#41188 - RE: T0 and T1 pins of 8051 Responding to: ???'s previous message |
T0 & T1 being used directly as count inputs to the timer may have limited usefulness if the input is exposed to multiple counts from a bouncy contact.
However the T0 and T1 inputs could be just used as normal port input bits and then under those conditions software could simply read the inputs and filter them in software. A common technique that I use is to debounce inputs by a timed sampling. For example have a timer interrupt occur at a 1 mSec rate. At each interrupt time simply have each input bit be read and shifted left into the LSB of a memory variable. You have one variable for T0 and one for T1. [Or what ever other input port bit(s)]. Then when you want to see the state on the input in the mainline code you look at these variables instead. I often decide that 4 milliseconds is a good debounce period. So I look at the low nibble of the variable and if it is 0xF then you know the input has been high for 4 mSec. If the nibble is 0x0 then you know the input has been stable low for 4 milliseconds. If on the other hand if you were trying to use the inputs with the normal T0 and T1 functions to count events it may then be necessary to debounce the contact closure in hardware. However I would not do this. It would be very simple to add a very small piece of software logic to the previously mentioned interrupt routine to poll the two variables similar to shown below. This shows counting events on the pin when it has been detected low to high for 4 milliseconds. ; internal memory variables for contact 0 ; initialize these to zeros at startup CONTACT0_FILTER DS 1 CONTACT0_COUNT DS 1 CONTACT0_PREV DS 1 ; internal memory variables for contact 1 ; initialize these to zeros at startup CONTACT0_FILTER DS 1 CONTACT0_COUNT DS 1 CONTACT0_PREV DS 1 ;embed the following code into the timer ;interrupt service routine ... ... CON0_HANDLER:   MOV A,CONTACT0_FILTER   MOV C,P3.4   ;get state of T0 pin   RLC   MOV CONTACT0_FILTER,A   ANL A,#0FH   JZ CON0_LOW   CJNE A,#0FH,CON1_HANDLER ; CON0_HIG:   CJNE A,CONTACT0_PREV,CON0_HIG1   JMP CON1_HANDLER CON0_HIG1:   ;here when Contact 0: L->H   MOV CONTACT0_PREV,A   INC CONTACT0_COUNT   ;increment the counter   JMP CON1_HANDLER ; CON0_LOW:   CJNE A,CONTACT0_PREV,CON0_LOW1   JMP CON1_HANDLER CON0_LOW1:   ;here when Contact 0: H->L   MOV CONTACT0_PREV,A   JMP CON1_HANDLER ; CON1_HANDLER:   MOV A,CONTACT1_FILTER   MOV C,P3.5   ;get state of T1 pin   RLC   MOV CONTACT1_FILTER,A   ANL A,#0FH   JZ CON1_LOW   CJNE A,#0FH,CONTINUE ; CON1_HIG:   CJNE A,CONTACT1_PREV,CON1_HIG1   JMP CONTINUE CON1_HIG1:   ;here when Contact 1: L->H   MOV CONTACT1_PREV,A   INC CONTACT1_COUNT   ;increment the counter   JMP CONTINUE ; CON1_LOW:   CJNE A,CONTACT1_PREV,CON1_LOW1   JMP CONTINUE CON1_LOW1:   ;here when Contact 1: H->L   MOV CONTACT1_PREV,A CONTINUE: ... ... Hope this info helps Michael Karas |
| Topic | Author | Date |
| T0 and T1 pins of 8051 | 01/01/70 00:00 | |
| RE: T0 and T1 pins of 8051 | 01/01/70 00:00 | |
| RE: T0 and T1 pins of 8051 | 01/01/70 00:00 | |
| RE: T0 and T1 pins of 8051 - MJK | 01/01/70 00:00 | |
| RE: T0 and T1 pins of 8051 | 01/01/70 00:00 | |
| RE: T0 and T1 pins of 8051 - Jez | 01/01/70 00:00 | |
RE: T0 and T1 pins of 8051 | 01/01/70 00:00 |



