Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

about scaning switches with pic 16f84

Status
Not open for further replies.

hassan1980

Full Member level 4
Full Member level 4
Joined
Jan 14, 2005
Messages
204
Helped
9
Reputation
18
Reaction score
6
Trophy points
1,298
Activity points
1,340
I am looking for the perfect way to scan switches with pic 16f84

I am using this program :

SCAN btfss porta,0
goto SCAN

I faced the problem with this subroutine, the problem is : when I turn on the lamp of my bedroom then pic 16f84 achieve the scannig prosses without any push of the switch that lead me to say that the scaning routines affected by external sparks like turn on lamp and turning on TV, would you please help me to cover this problem.

I am waiting your replies
 

This is the way you scan the switches.
But do you have a strong enough pullup or pulldown on that input?
Sometimes an RC filter on the pin can help, too.
 

    hassan1980

    Points: 2
    Helpful Answer Positive Rating
Search EDA board for "debounce" for more info but this is short explanation:

This code is written from head and it's not tested

Code:
CNT res 1

   movlw 255        ;time for debounce
   movf CNT,w

SCAN
   btfss PORTA,0
   goto SCAN
DEB
   decfsz CNT       ;wait for debounce time to run out
   goto DEB

   btfss PORTA,0   ;test again
   goto SCAN        ;if not, it's false signal, goto SCAN

                       ; here you do job for presed button

hope this will help you
branek
 

    hassan1980

    Points: 2
    Helpful Answer Positive Rating
If you want to scan an input attatched with a switch, you have to do two things primarily:

1st: You have to attach a pull-up, or pul-down resistor with the input for stability, you can use 10Kohm, the first end of it with 5Vdc and the other to the PIC input, now R is called pull-up resistor, and your switch must be attached with the input pin and the ground.

2nd: You have to take into your account the debounce problem, which it comes when you push the switch, so you have to detect the switch after an enough delay time, maybe 20 ms, then decide if the switch in on or off.

Lastly, I suggest you to use the RB7-RB4, as on-change interrupt pins...

have a nice time...
 

    hassan1980

    Points: 2
    Helpful Answer Positive Rating
VVV said:
This is the way you scan the switches.
But do you have a strong enough pullup or pulldown on that input?
Sometimes an RC filter on the pin can help, too.

I attached 10K resistor to +5V then I attached the other side of resistor to the pic and the first pin of the switch on the other hand I attached the second side of the switch to Ground, but the problem is still.

the problem is when I turn on the lamp of my bedroom pic 16f84 achieve scaning without any press of the switch.

Would you please let me know how to make RC Filter and how to conect it?

I am waiting your replies
 

hmm, btfss skips the next instruction if the specified pin is at logic 1, that should loop while your switch is held in and continue through the program when it is released.

Do you have the specified decouping capacitors close to the pic?
 

    hassan1980

    Points: 2
    Helpful Answer Positive Rating
throwaway18 said:
hmm, btfss skips the next instruction if the specified pin is at logic 1, that should loop while your switch is held in and continue through the program when it is released.

Do you have the specified decouping capacitors close to the pic?

No, How to do it.
 

The PIC power needs to be decoupled: use at least a 0.1uF cap between its Vdd and Vss pins, as close to the package as possible.

Do not forget to tie the /MCLR pin to Vcc through a resistor and maybe add a 0.1uF cap to GND. Perhaps the PIC is resetting, but you think it's just sensing the button as being pressed.

As for the RC filter, try first adding a cap 10nF-100nF from the pin to GND.
 

    hassan1980

    Points: 2
    Helpful Answer Positive Rating
I faced this problem before many times, don't leave any floating pin whether input or output.
Put a pullup or pulldown resistors on each pin.
 

    hassan1980

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top