| View previous topic :: View next topic |
| Author |
Message |
gamal eldeen
Joined: 29 May 2012 Posts: 29 Location: Alexandria - Egypt
|
|
Posted: Sat Oct 13, 2012 2:51 pm |
|
|
ok the problem is in debouncing >>>
as when am change it the response improved |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Oct 13, 2012 2:52 pm |
|
|
| Post a schematic of your external switch circuit, or describe it in detail. |
|
 |
gamal eldeen
Joined: 29 May 2012 Posts: 29 Location: Alexandria - Egypt
|
|
Posted: Sat Oct 13, 2012 3:00 pm |
|
|
| VCC to R (220 ohm) to push button to RB0 bin |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Oct 13, 2012 3:40 pm |
|
|
You need a schematic like this:
| Code: |
+5v
|
<
> 4.7K
< ___ Push button switch
To | _|_|_
PIC -----------------o o------
pin |
--- GND
-
|
The resistor can be 220 ohms. It will still work. But the other side
of the button (switch) must connect to ground. |
|
 |
gamal eldeen
Joined: 29 May 2012 Posts: 29 Location: Alexandria - Egypt
|
|
Posted: Sat Oct 13, 2012 4:00 pm |
|
|
this schematic make a problem ????
| Code: |
+5v
|
<
> 4.7K
___ <
To _|_|_ |
PIC -----------------o o------
pin
|
|
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Oct 13, 2012 4:06 pm |
|
|
How do you put a logic "0" level on the PIC pin with that circuit ?
You can't. It only puts a "1" level or a "floating pin" unknown level
on the PIC pin. You need to change it to my schematic.
This is why we kept asking you for a circuit description in several posts. |
|
 |
gamal eldeen
Joined: 29 May 2012 Posts: 29 Location: Alexandria - Egypt
|
|
Posted: Sat Oct 13, 2012 4:30 pm |
|
|
| thanx ... i will change it |
|
 |
gamal eldeen
Joined: 29 May 2012 Posts: 29 Location: Alexandria - Egypt
|
|
Posted: Sat Oct 13, 2012 4:35 pm |
|
|
but i have a question:
in the isr ...
i must write RBO as:
??????????????????????
| Code: | void EXT_isr(void)
{
delay_ms (50); //debounce
if( input(PIN_B0))
{
OUTPUT_D(0xf0) |
or this code is enough: | Code: | void EXT_isr(void)
{
delay_ms (50); //debounce
OUTPUT_D(0xf0); |
|
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Oct 13, 2012 5:18 pm |
|
|
I'm not sure what you want to do. Do you want the PIC to get an
external interrupt when you press the switch ? If so, you can setup
the PIC to get an interrupt on the falling edge with this function:
| Code: |
void main()
{
ext_int_edge(H_TO_L); // Select falling edge for interrupt
.
.
.
.
}
|
If you use the switch schematic that I posted, the idle state (inactive state)
of the switch is a logic "1" level. When you press the switch, then Pin B0
will go to a "0" level. That's a "falling edge" (H to L). Then you will get
an interrupt when you press the button. To get another interrupt, you
must first release the button, and then press it again.
If you do that, then you can use the 2nd code that you posted. |
|
 |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sun Oct 14, 2012 1:39 am |
|
|
I'm still not sure what you're trying to do.
I realise you're at the stage where you're testing that you can get peripherals to function.
What do you want to happen when you press and release the button?
1) Do you want the LEDs to light when the button is down and go off when released?
OR
2) Do you want the LEDs to go from on to off, then off to on each time the button is pressed?
OR
3) Do you just want a one time operation?
OR
4) Something else?
Mike |
|
 |
|