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

problem button 16F88

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



Joined: 28 May 2012
Posts: 24
Location: france

View user's profile Send private message AIM Address

problem button 16F88
PostPosted: Sat Feb 23, 2013 10:12 am     Reply with quote

Hello
I do a small program on a 16F88.

When I press a button it lights a LED LED RED then GREEN (10 seconds each example).
And when I release the button it flashes a blue.

The problem is when I release my button, the program continues its cycle (red and 10 seconds 10 seconds GREEN) before flashing the blue LED.

I want that when I release the button the program goes directly to the LED blinks blue.

if you can help me. An interrupt can be, but I'm not good. You can help me?

Thank you very much.
Code:

#include <16F88.h>                             
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP           
#use delay(clock=20000000)
#use standard_io (B)

#define led_red  PIN_A2
#define led_verte  PIN_A3
#define led_bleu  PIN_A4
#define button  PIN_B1
 
#int_TIMER1
TIMER1_isr()
{

while (1)
   {
      if (input(PIN_B0))
      {
         output_toggle(pin_B1);
      }
      else
      { 

                        output_high(PIN_A2);
         delay_ms(10000);
                        output_low(PIN_A2);
      
         output_high(PIN_A4);
         delay_ms(10000);
         output_low(PIN_A4);


      }      
   }   
}

}

 
void main()
{
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);
   while(1)
       {
   
  }   
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19383

View user's profile Send private message

PostPosted: Sat Feb 23, 2013 10:54 am     Reply with quote

The reason, is that you are sitting in two ten second delays.
You don't need an interrupt, just break the delays down into smaller bits.
So:

Code:

//small part only
    int8 count;
   

    else {
        output_high(PIN_A2);
        for (count=0;count<100;count++) {
           if (!input(PIN_B0)) break;
           delay_ms(100);
        }
        output_low(PIN_A2);
        for (count=0;count<100;count++) {
           if (!input(PIN_B0)) break;
           delay_ms(100);
        }
    }

If the button releases, it'll terminate within 0.1seconds.

Not as fast as an interrupt response, but as fast as a 'human' needs.

Best Wishes
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