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

pic 16f84A software problems

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



Joined: 03 Sep 2009
Posts: 17

View user's profile Send private message

pic 16f84A software problems
PostPosted: Thu Sep 03, 2009 8:29 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Sep 03, 2009 1:18 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Sep 03, 2009 10:16 pm     Reply with quote

Thank you very much.
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