View previous topic :: View next topic |
Author |
Message |
wwwglro
Joined: 03 Sep 2009 Posts: 17
|
delay interrupts rtcc inside main program... |
Posted: Mon Sep 07, 2009 7:13 am |
|
|
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
|
|
Posted: Mon Sep 07, 2009 10:17 am |
|
|
You are certainly allowed to enable and disable interrupts inside main(). |
|
|
wwwglro
Joined: 03 Sep 2009 Posts: 17
|
|
Posted: Mon Sep 07, 2009 2:19 pm |
|
|
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
|
|
|
wwwglro
Joined: 03 Sep 2009 Posts: 17
|
|
Posted: Mon Sep 07, 2009 2:53 pm |
|
|
Hello.
My question was: if a port changes state, interrupt occurs?
Thank you |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Sep 07, 2009 3:01 pm |
|
|
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
|
|
Posted: Tue Sep 08, 2009 9:02 am |
|
|
Hello
No, I am using port A as input port. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Tue Sep 08, 2009 9:35 am |
|
|
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
|
|
Posted: Tue Sep 08, 2009 11:33 am |
|
|
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
|
|
Posted: Tue Sep 08, 2009 3:18 pm |
|
|
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
|
|
Posted: Tue Sep 08, 2009 11:42 pm |
|
|
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
|
|
Posted: Wed Sep 09, 2009 9:19 am |
|
|
So, the interrupt occurs when the button is pressed or released or both? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Sep 09, 2009 4:53 pm |
|
|
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
|
|
Posted: Sat Sep 12, 2009 8:12 am |
|
|
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
|
|
Posted: Sat Sep 12, 2009 11:11 am |
|
|
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. |
|
|
|