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

Quick timer program problem

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



Joined: 24 Jun 2005
Posts: 206

View user's profile Send private message Send e-mail

Quick timer program problem
PostPosted: Fri Sep 23, 2005 8:14 am     Reply with quote

Hi All, i am tring to write a very simple timer program, but am having some problems. It is ment to turn on a relay when i press and hold a buttion, and the delay the turnoff but some time (2 seconds in this example). This all works ok, however, if i repress the buttion within the timout priod it will not delay when i let go again. It will just stay on as long as i hold the buttion, but will turn off as soon as i let go. If i let the relay turn off before pushing the buttion, it will work OK.

My code is below

Thank you for your help

Mark

Code:

#include <12F629.h>
#use delay(clock=4000000)
#fuses NOWDT,INTRC_IO, NOCPD, NOPROTECT, NOMCLR, NOPUT, BROWNOUT

void main() {

OUTPUT_low(pin_A0);                           //make sure blower is off

   while(1)
   {
      while (input(pin_A2));                     //Wait untill buttion is pressed
         {
         output_low(pin_a0); 
         }
      while (!input(pin_A2));                     //turn blower on if buttion is pressed
         {
         output_high(pin_a0); 
         delay_ms(2000);
         }        
   }
}
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Sep 23, 2005 8:37 am     Reply with quote

You put ';' after the while statements. This is what your code actually looks like:

Code:
#include <12F629.h>
#use delay(clock=4000000)
#fuses NOWDT,INTRC_IO, NOCPD, NOPROTECT, NOMCLR, NOPUT, BROWNOUT

void main() {

  output_low(pin_A0);                           //make sure blower is off

  while(1)
  {
    while (input(pin_A2));                     //Wait untill buttion is pressed
    output_low(pin_a0); 
    while (!input(pin_A2));                     //turn blower on if buttion is pressed
    output_high(pin_a0); 
    delay_ms(2000);
  }
}


This is what you probably want
Code:
#include <12F629.h>
#use delay(clock=4000000)
#fuses NOWDT,INTRC_IO, NOCPD, NOPROTECT, NOMCLR, NOPUT, BROWNOUT

void main() {

  while(1)
  {
    // Blower off
    output_low(pin_a0); 

    // Wait until button is pressed
    while (input(pin_A2));                     

    // Blower on
    output_high(pin_a0); 

    // 2 second delay after button release
    while (delaycount < 2000)
    {
      delay_ms(1);

      // Keep delaying until button is released
      if (!input(pin_A2))
        delaycount = 0
      else
        delaycount++;
    }
  }
}
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