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

10 minutes interrupt

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



Joined: 12 Jul 2007
Posts: 32

View user's profile Send private message

10 minutes interrupt
PostPosted: Mon Dec 03, 2007 5:39 am     Reply with quote

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!
SerialGmr8



Joined: 30 Nov 2007
Posts: 13

View user's profile Send private message

PostPosted: Mon Dec 03, 2007 6:41 am     Reply with quote

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
spom



Joined: 12 Jul 2007
Posts: 32

View user's profile Send private message

PostPosted: Mon Dec 03, 2007 8:19 am     Reply with quote

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!
SerialGmr8



Joined: 30 Nov 2007
Posts: 13

View user's profile Send private message

PostPosted: Mon Dec 03, 2007 9:04 am     Reply with quote

*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.
spom



Joined: 12 Jul 2007
Posts: 32

View user's profile Send private message

PostPosted: Mon Dec 03, 2007 9:28 am     Reply with quote

Thanks,

it works fine!
Guest_7068
Guest







PostPosted: Tue Dec 04, 2007 12:01 am     Reply with quote

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