| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| wwwglro 
 
 
 Joined: 03 Sep 2009
 Posts: 17
 
 
 
			    
 
 | 
			
				| pic 16f84A software problems |  
				|  Posted: Thu Sep 03, 2009 8:29 am |   |  
				| 
 |  
				| Hello I have a program that does this: I have 2 buttons and 2 LEDs.
 When I push the first button, first LED lights for 5 seconds. If I push the second button, first LED stops lighting and the second LED starts lighting for 5 seconds.
 
 My problem is: when the button is kept pushed for more then 0,3 seconds, I want that the LED to light until the button is released. (not 5 seconds).
 
 Here is the program. (It does the first part I described above: first LED lights for 5 seconds and if a button is pressed, it stops lighting first led and starts lighting the second one).
 
 Thank you.
 
 
  	  | Code: |  	  | #include <16f84A.h> #use delay(clock=4000000)
 long bec0=1;
 long bec1=1;
 
 #int_rtcc
 void clock_isr() {
 bec0--;
 bec1--;
 
 if(bec0<1) bec0=1;
 if(bec1<1) bec1=1;
 
 if(bec0>1)
 output_high(pin_b0);
 else
 output_low(pin_b0);
 if(bec1>1)
 output_high(pin_b1);
 else
 output_low(pin_b1);
 }
 
 void main()
 {
 set_rtcc(0);
 setup_counters (RTCC_INTERNAL, RTCC_DIV_1);
 enable_interrupts (INT_RTCC);
 enable_interrupts(GLOBAL);
 
 do {
 if(input_state(PIN_a0)==0)
 {
 bec0=19530; //3906*5 seconds
 bec1=1;
 }
 
 if(input_state(PIN_a1)==0)
 {
 bec1=19530; //3906*5 seconds
 bec0=1;
 }
 } while(1);
 }
 | 
 |  | 
	
		|  | 
	
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Sep 03, 2009 1:18 pm |   |  
				| 
 |  
				| You could look at Mark's multi-event switch driver: http://www.ccsinfo.com/forum/viewtopic.php?t=36222
 It will detect a simple button press, or if the button is held down.
 
 With this driver, you can tell the difference between the two types
 of button presses.  Then you can turn on the LED for different amounts
 of time, based on the type of button press.
 |  | 
	
		|  | 
	
		| wwwglro 
 
 
 Joined: 03 Sep 2009
 Posts: 17
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Sep 03, 2009 10:16 pm |   |  
				| 
 |  
				| Thank you very much. |  | 
	
		|  | 
	
		|  |