A mechanical switch will "open and close" literally thousands of times each time you actually close the switch or open the switch. This is due to the mechanical contacts rubbing together (settling) closed or opening. Don't forget, you're sampling the open or closed position many times during that time period without a delay. Rick Rafael Vidal Aroca wrote: > Hi, i tried this example on PIC16F84, that counts the number of > changes on a switch. It's easy to understand the btfss and btfsc parts > that waits for changes on the switch and then adds the change to the > counter. > > But i didn't realize why we need to delay a bit (ANTIREBOND) when > the switch is changed. According to the example's text, it's because of > mechanical problems of switches...anyone could give me a better > explanation for the need of this delay? > > LOOP btfss PORTA,0 > goto LOOP > call ANTIREBOND > > LOOP2 btfsc PORTA,0 > goto LOOP2 > call ANTIREBOND > > incf COUNTER,f > movf COUNTER,w > movwf PORTB > > goto LOOP > > ANTIREBOND bcf INTCON,2 > > movlw 0xB0 > > movwf OPTION_REG > > DEL btfss INTCON,2 > goto DEL > return > > []s Rafael. > http://grad.icmc.sc.usp.br/~rva > > -- -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics