View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Feb 06, 2012 4:53 pm |
|
|
Quote: | I'm pushing a momentary push button that has power on one side and the
jumper to the PIC pin A1 on the other side.
|
So it can only output a high level state to the PIC pin ? Then when it's
not pressed, the PIC pin is left floating ? That's not good.
Change your switch circuit so it looks like this:
Code: |
+5v
|
<
> 4.7K
< ___ Switch
To | _|_|_
PIC -----------------o o------
pin |
--- GND
-
|
This is the industry standard way to connect a switch. The pull-up resistor
holds the input pin at a high logic level as the idle state. When the button
is pressed, it puts a low logic level (0v) on the PIC pin.
Then change your code so it looks for a logic 0 as the active state (button
pressed). |
|
|
Username
Joined: 01 Nov 2011 Posts: 17
|
|
Posted: Wed Feb 08, 2012 5:06 pm |
|
|
I know that pull-ups and pull-downs are a good way to reduce stray current, but i'm not sure that is causing the problem. Even when I take the button out of the circuit and jumper the pin directly to power or ground there is no response. Could it be something is set wrong in the FUSES?
Thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 08, 2012 6:55 pm |
|
|
Before you try using interrupts, try this simple program and see if it
works. When you press down the button, the LED should go on.
When release the button, the LED should go off. I tested this code in
hardware, with vs. 4.120, and it works.
The button circuit is the same one as I posted earlier in this thread.
The LED circuit looks like this:
Code: |
pin 470 ohms LED
A0 -----/\/\/\/------->|----
|
|
----- Ground
---
-
|
Code: |
#include <12F683.H>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT
#use delay(clock=4M)
#define BUTTON_PIN PIN_A1
#define LED_PIN PIN_A0
//======================================
void main()
{
while(1)
{
if(input(BUTTON_PIN) == 0)
output_high(LED_PIN);
else
output_low(LED_PIN);
}
} |
|
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Thu Feb 09, 2012 4:18 am |
|
|
I haven't used this chip 12F683. Most start with reading the data sheet and noting the capabilities of each pin (Ex. does it default to analog is it open drain etc) On small packages the programming pins maybe needed to perform other functions after programming so attention needs to be paid to disconnecting the programmer when running the target and disconnecting the target circuit on the programming pins while programming. After reading the data sheet heed PCM programmer's advice of starting simple. |
|
|
|