| View previous topic :: View next topic   | 
	
	
	
		| Author | 
		Message | 
	
	
		
			PCM programmer
 
 
  Joined: 06 Sep 2003 Posts: 21708
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Nov 16, 2009 1:17 pm     | 
				     | 
			 
			
				
  | 
			 
			
				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
 
 
 
 
  
			
			
			
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Nov 17, 2009 8:11 am     | 
				     | 
			 
			
				
  | 
			 
			
				| THANK YOU A MILLION............I REALLY APPRECIATE IT!!!!!!!! | 
			 
		  | 
	
	
		  | 
	
	
		
			entah
 
 
  Joined: 23 Sep 2010 Posts: 7
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Sun Oct 03, 2010 7:45 am     | 
				     | 
			 
			
				
  | 
			 
			
				how to add the switch...plzzzz... help!!!! _________________ helpme!! Im the blind IT person!! | 
			 
		  | 
	
	
		  | 
	
	
		
			Ttelmah
 
 
  Joined: 11 Mar 2010 Posts: 19967
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Sun Oct 03, 2010 10:15 am     | 
				     | 
			 
			
				
  | 
			 
			
				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
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Oct 04, 2010 3:44 am     | 
				     | 
			 
			
				
  | 
			 
			
				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()..    | 
			 
		  | 
	
	
		  | 
	
	
		
			PCM programmer
 
 
  Joined: 06 Sep 2003 Posts: 21708
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Oct 04, 2010 2:04 pm     | 
				     | 
			 
			
				
  | 
			 
			
				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
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Thu Oct 07, 2010 4:42 am     | 
				     | 
			 
			
				
  | 
			 
			
				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!! | 
			 
		  | 
	
	
		  | 
	
	
		 |