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 CCS Technical Support

start button question

 
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 Nov 16, 2009 1:17 pm     Reply with quote

Here is a demo program that will toggle an LED on/off when a
push-button is pressed.
Code:

#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud = 9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

// A push-button switch must be connected to the following
// pin on the PIC.  The switch must connect the pin to
// ground when it's pressed.  The PIC pin must have a
// pull-up resistor on it (Example: 10K).
#define BUTTON_PIN  PIN_A4   

// This pin must have an LED with a series resistor connected
// to it. (Example:  470 ohms).  The cathode of the LED should
// connect to ground.
#define LED_PIN     PIN_B1


void wait_for_button(void);

//====================================
void main()
{
output_low(LED_PIN);

while(1)
  {
   wait_for_button();
   
   output_toggle(LED_PIN);
  }

}
//==================================

void wait_for_button(void)
{
char count;

// Wait for the button to be released. 
// The button must be in the "up" state for two
// consecutive samples, at 10 ms intervals.

count = 0;

while(1)
  {
   if(input(BUTTON_PIN))
      count++;
   else
      count = 0;
   
   if(count == 2)
      break;

   delay_ms(10);
  }

// Now that the button is up, wait until the
// user presses it. For the keypress to be
// considered valid, the button must be held
// down for two consecutive samples, taken at
// 10 ms intervals.

count = 0;

while(1)
  {
   if(input(BUTTON_PIN) == 0)
      count++;
   else
      count = 0;
   
   if(count == 2)
      break;

   delay_ms(10);
  }

}
newbie1000
Guest







PostPosted: Tue Nov 17, 2009 8:11 am     Reply with quote

THANK YOU A MILLION............I REALLY APPRECIATE IT!!!!!!!!
entah



Joined: 23 Sep 2010
Posts: 7

View user's profile Send private message

PostPosted: Sun Oct 03, 2010 7:45 am     Reply with quote

how to add the switch...plzzzz... help!!!!
_________________
helpme!! Im the blind IT person!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Sun Oct 03, 2010 10:15 am     Reply with quote

Read the comments in the code, on lines 7 to 10. Tells you how to connect the switch....

Best Wishes
serabut



Joined: 03 Oct 2010
Posts: 1

View user's profile Send private message

PostPosted: Mon Oct 04, 2010 3:44 am     Reply with quote

tq for comment.....but i means if want add some switch and led in program this not at board...
so how....can ur explain to me??coz i already try but has error at
void main().. Question
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 04, 2010 2:04 pm     Reply with quote

Does serabut = entah ?

Please don't use two different identities on the same thread.
If you are a different person, please don't "hijack" someone else's thread.
entah



Joined: 23 Sep 2010
Posts: 7

View user's profile Send private message

PostPosted: Thu Oct 07, 2010 4:42 am     Reply with quote

no same person la....but same team.....we have project for last sem lorrr......we student lorrrr....we dont know about this program so just ask k....dont treat we like you pcm....ur pro about this but we new....aiyoooo.....!!!so help lorrr....
_________________
helpme!! Im the blind IT person!!
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