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

Timer problem

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



Joined: 11 Jul 2006
Posts: 42
Location: Minden, Germany

View user's profile Send private message

Timer problem
PostPosted: Mon Jul 30, 2007 1:46 am     Reply with quote

Hello dear frends!

I have one problem. I have to program this situation, but i have no idea how i can realize it. It should work so:

If i push a button AND i hold it pushed for 5 sec. a LED should start lighting.

Any suggestions?

Thank you. Dennis
inservi



Joined: 13 May 2007
Posts: 128

View user's profile Send private message

PostPosted: Mon Jul 30, 2007 2:12 am     Reply with quote

Hello,

I think that a good way is to use an interrupt for counting the time.

For example, set one timer for about 0.76 second and use a int16 counter in the interrupt. when the counter count at least 380 the the 5 second are past
You can check if the button is pushed in he interrupt. If the button is not pushed then set the counter to 0.
In the main loop you can testing if the counter is greater than 380 then set the led on...

Code:

 ...
 int16 sec5 = 0 ;
 ...
  #INT_TIMERx
  void interrupt_proc() {  // called n time by sec (for example)
 
   if (button_pushed) ++sec5 ;
     else sec5 = 0 ;

  }

...

void main() {

  until(true) {
    if ( sec5 >= ( n*5 ) ) { // n is the number of time that the interrupt is called by second
      // your code for led ...
      ...
    }

   }



}




Witch pic do you use ? (i suppose that you use a pic16f873 ?)

dro.
_________________
in médio virtus
deniska_gus



Joined: 11 Jul 2006
Posts: 42
Location: Minden, Germany

View user's profile Send private message

PostPosted: Mon Jul 30, 2007 2:17 am     Reply with quote

Thank you very much. I will test it. I use PIC16F877A
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