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

delay interrupts rtcc inside main program...
Goto page 1, 2  Next
 
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

delay interrupts rtcc inside main program...
PostPosted: Mon Sep 07, 2009 7:13 am     Reply with quote

Hello.
uC pic 16f84A

I have the following program:
Code:

int_rtcc
void isr()
{
instruction made when interrupt occurs;
}


void main()
{
set_rtcc(0);
setup_counters (RTCC_INTERNAL, RTCC_DIV_1);
enable_interrupts (INT_RTCC);
disable_interrupts(GLOBAL);

some_instructions;

do
{

if (condition);
   some_instructions;
else
//this is where i want to activate the interrupt
   enable_interrupt(global); //then jump to interrupt function

} while(1)
}

Can I use the interrupt this way? (enable and disable interrupts ) ?

Thank you.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 07, 2009 10:17 am     Reply with quote

You are certainly allowed to enable and disable interrupts inside main().
wwwglro



Joined: 03 Sep 2009
Posts: 17

View user's profile Send private message

PostPosted: Mon Sep 07, 2009 2:19 pm     Reply with quote

I have another question.

If I press a button, interrupt occurs when the button is pressed or released or both. (I think both...).

Thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 07, 2009 2:26 pm     Reply with quote

This thread has some links for pushbutton debouncing code:
http://www.ccsinfo.com/forum/viewtopic.php?t=36222
wwwglro



Joined: 03 Sep 2009
Posts: 17

View user's profile Send private message

PostPosted: Mon Sep 07, 2009 2:53 pm     Reply with quote

Hello.
My question was: if a port changes state, interrupt occurs?
Thank you
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 07, 2009 3:01 pm     Reply with quote

Are you using Port B interrupt-on-change interrupts ?
You will get an interrupt on both edges, with that type of interrupt.
wwwglro



Joined: 03 Sep 2009
Posts: 17

View user's profile Send private message

PostPosted: Tue Sep 08, 2009 9:02 am     Reply with quote

Hello
No, I am using port A as input port.
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Tue Sep 08, 2009 9:35 am     Reply with quote

Read section 6.8 of the DATASHEET for information on what interrupts are available. There are no interrupts on Port A of the 16F84A

Datasheet:
http://ww1.microchip.com/downloads/en/devicedoc/35007b.pdf
_________________
Google and Forum Search are some of your best tools!!!!
wwwglro



Joined: 03 Sep 2009
Posts: 17

View user's profile Send private message

PostPosted: Tue Sep 08, 2009 11:33 am     Reply with quote

If I enable internal interrupts, they do not occur if I press a button on port A? I thought they did... (I mean tmr0 overflow).

When I want an interrupt to occur if I press a buttton (to do an action), and if I press another button (for doing another action and the first action to stop); isn't this a good way to do this or I should use external interrupts?

Thank you
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 08, 2009 3:18 pm     Reply with quote

Tell us the overall purpose of your project. What is your project
(your program and hardware) supposed to do ?
wwwglro



Joined: 03 Sep 2009
Posts: 17

View user's profile Send private message

PostPosted: Tue Sep 08, 2009 11:42 pm     Reply with quote

Hello.
The overall purpose of my project is to light two leds with two buttons...one of a time. When one of them lights and I push the other button, the other one starts to light for a specified time. If any of the buttons is kept pressed, the corresponding led should light until the button is released.

Thank you.
wwwglro



Joined: 03 Sep 2009
Posts: 17

View user's profile Send private message

PostPosted: Wed Sep 09, 2009 9:19 am     Reply with quote

So, the interrupt occurs when the button is pressed or released or both?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 09, 2009 4:53 pm     Reply with quote

Here's a little program that does some of the things you want,
but not all of them. You can study it and learn how it works.
The Button.c code comes from here:
http://www.ccsinfo.com/forum/viewtopic.php?t=23837

Code:

#include <16F877.H>
#fuses XT, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

// These are the "Bvar" variables required by Button.c
int8 A4 = 0;   // For the button on pin A4
int8 B0 = 0;   // For the button on pin B0
#include <Button.c>

#define LED0_PIN  PIN_B1    // This pin drives the LED

//======================================
void main()
{
int16 led0_timer = 0;


while(1)
  {
   // If first button is pressed, turn on LED0 for 2 seconds.
   if(button(PIN_A4, 0, 50, 10, A4, 1))   
     {
      led0_timer = 200;  // 200 x 10 ms = 2 seconds
     }

   // If the 2nd button is pressed, then turn off the LED.
   if(button(PIN_B0, 0, 50, 10, B0, 1))   
     {
      led0_timer = 0;   
     }

// If the LED0 timer has a non-zero value, then
// decrement it.
   if(led0_timer)
     {
      led0_timer--;
     }
     
// If the LED timer is running, then turn on the LED.
// If the timer is not running (is 0), then turn off the LED.
   if(led0_timer)
      output_high(LED0_PIN);
   else
      output_low(LED0_PIN); 

   // You must use a delay statement in the loop.
   // A good value to use is 10 ms.
   delay_ms(10);
  }   

}
wwwglro



Joined: 03 Sep 2009
Posts: 17

View user's profile Send private message

PostPosted: Sat Sep 12, 2009 8:12 am     Reply with quote

Hello
How can I use this function (button.c) to test if the key is pressed more then 1 second?
Thank you.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Sep 12, 2009 11:11 am     Reply with quote

It doesn't have that ability. You need to use Mark's driver, which is
given in the first link that I posted in this thread.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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