View previous topic :: View next topic |
Author |
Message |
spom
Joined: 12 Jul 2007 Posts: 32
|
10 minutes interrupt |
Posted: Mon Dec 03, 2007 5:39 am |
|
|
Hi,
sorry for that stupid question.
My program should do following:
first it should set a pin to high level, wait 10 minutes, and then to low level and wait 10 minutes.
How can I realize the 10 minutes of waiting with an interrupt?
Thanks! |
|
![](templates/subSilver/images/spacer.gif) |
SerialGmr8
Joined: 30 Nov 2007 Posts: 13
|
|
Posted: Mon Dec 03, 2007 6:41 am |
|
|
hey spom,
i got something similiar inquiring about in this thread.
http://www.ccsinfo.com/forum/viewtopic.php?t=32889
this might help you. im decoding for three minutes. your coding should be similiar except instead of decode for seconds = 180 (three minutes), you should decode for seconds = 600 ---> one min = 60 seconds. 10 mins = 60 * 10 |
|
![](templates/subSilver/images/spacer.gif) |
spom
Joined: 12 Jul 2007 Posts: 32
|
|
Posted: Mon Dec 03, 2007 8:19 am |
|
|
I still have some problems with the interrupt.
I don't know where I say my code "go now to the interrupt routine".
My code looks like this:
Code: |
#include <16f818.h>
#use delay(clock=8000000)
#fuses NOWDT,HS,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP
BYTE seconds; // A running seconds counter
BYTE int_count; // Number of interrupts left before a second has elapsed
#define INTS_PER_SECOND 76 // (20000000/(4*256*256))
#int_rtcc // This function is called every time
void clock_isr() { // the RTCC (timer0) overflows (255->0).
// For this program this is apx 76 times
if(--int_count==0) { // per second.
++seconds;
int_count=INTS_PER_SECOND;
}
}
void main() {
int_count=INTS_PER_SECOND;
set_timer0(0);
setup_counters( RTCC_INTERNAL, RTCC_DIV_256 | RTCC_8_BIT);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
while(TRUE)
{
if(seconds == 600)
{
output_high(PIN_A0);
seconds = 0;
}
}
}
|
I just want to have output_high for 10 minutes and then output_low for 10 minutes.
Thank you! |
|
![](templates/subSilver/images/spacer.gif) |
SerialGmr8
Joined: 30 Nov 2007 Posts: 13
|
|
Posted: Mon Dec 03, 2007 9:04 am |
|
|
*declare some variable for ex. ledstate
Code: |
#include <16f818.h>
#use delay(clock=8000000)
#fuses NOWDT,HS,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP
BYTE ledstate; //led state (on / of variable) see below
BYTE seconds; // A running seconds counter
BYTE int_count; // Number of interrupts left before a second has elapsed
#define INTS_PER_SECOND 76 // (20000000/(4*256*256))
#int_rtcc // This function is called every time
void clock_isr() { // the RTCC (timer0) overflows (255->0).
// For this program this is apx 76 times
if(--int_count==0) { // per second.
++seconds;
int_count=INTS_PER_SECOND;
}
}
void main() {
int_count=INTS_PER_SECOND;
set_timer0(0);
setup_counters( RTCC_INTERNAL, RTCC_DIV_256 | RTCC_8_BIT);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
while(TRUE)
{
if(seconds == 600)
{
if(ledstate==0) //this routine will keep switching the value of your
{ // each time the routine gets entered.
led_state=1;
output_low(PIN_A0);
}
else
{
ledstate=0;
output_high(PIN_A0);
}
seconds = 0;
}
}
}
|
you dont have to worry about calling the interrupt routine. it does its thing in the back ground and keeps incrementing seconds. in your main program, the number of seconds are collected til it reaches your limit (600 or 10 minutes), and then weill output a state to your LED. |
|
![](templates/subSilver/images/spacer.gif) |
spom
Joined: 12 Jul 2007 Posts: 32
|
|
Posted: Mon Dec 03, 2007 9:28 am |
|
|
Thanks,
it works fine! |
|
![](templates/subSilver/images/spacer.gif) |
Guest_7068 Guest
|
|
Posted: Tue Dec 04, 2007 12:01 am |
|
|
How does it work?
Seconds is declared as a byte, so it will roll over after 255. How can you compare it to 600? Make sure you declare it as an int16 |
|
![](templates/subSilver/images/spacer.gif) |
|