CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Why doesn't this simple program work?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 06, 2012 4:53 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Feb 08, 2012 5:06 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Feb 08, 2012 6:55 pm     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Thu Feb 09, 2012 4:18 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group