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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/18/04 19:57
Read: times


 
Msg Score: +2
 +2 Informative
#76130 - debouncing code using vertical counters
Debouncing is a topicoften raised here, and there was a recent article on Jack Ganssle's web pages about it. Looking around, I found a section of Jack's piece quoted on embedded.com with comments, and I have been working with my version of this exquisite piece of debouncing code, written by Scott Dattalo. It is, I hope, the 8052 equivalent of
http://www.dattalo.com/technical...ounce.html
this brilliant piece of <hack, hack> PIC code.

The code debounces 8 bits of a port by using "vertical" counters - an inspired idea I haven't used before where we use the 2 bits in each bit weight of two bytes to count from 0..3. So every BIT has its own counter in 2 bits of the databytes ctrA and ctrB. Very clever and concise.

This is the code, which would be called
<PRE>
DATA
CtrA: dS 1
CtrB ds 1
DBNCE: DS 1

CODE

abs 000h
BEGIN: LJMP 100H

abs 100H

MOV ctra,#0
MOV ctrB,#0
MOV DBNCE,#1
MOV A,#1

Start: MOV A,CtrB ;increment the vertical counter
XRL CtrA,A ;A+:= A XOR B
MOV A,ctrb
CPL A ;B+:= NOT (B)
XCH A,ctrB

MOV A,P1 ;Has the input data changed ?
XRL a,Dbnce

ANL ctrA,A ;clear counter on no changes?
ANL ctrB,A

MOV A,ctrB ;Check counter
ORL A,CtrA

ANL Dbnce,A
XRL A,#0FFH
ANL A,P1
ORL Dbnce,A

jmp start




This is the first time I have unPICed any code like this.

NOW it SEEMS to work in Pinnacle, but it doesn't work in my Epascal simulator. Can anyone else confirm its behaviour with something else ?

The input data is set up on Port 1
The output is the contents of Dbnce, which could be in bit addressable memory,

Steve

List of 12 messages in thread
TopicAuthorDate
debouncing code using vertical counters            01/01/70 00:00      
   RE: debouncing code using vertical count            01/01/70 00:00      
      RE: debouncing code using vertical count            01/01/70 00:00      
   RE: debouncing code using vertical counters            01/01/70 00:00      
      RE: debouncing code using vertical count            01/01/70 00:00      
   RE: debouncing code using vertical counters            01/01/70 00:00      
      RE: debouncing code using vertical count            01/01/70 00:00      
         RE: debouncing code using vertical count            01/01/70 00:00      
   RE: debouncing code using vertical counters            01/01/70 00:00      
      RE: debouncing code using vertical count            01/01/70 00:00      
      RE: debouncing code using vertical counters            01/01/70 00:00      
   RE: debouncing code using vertical counters            01/01/70 00:00      

Back to Subject List