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

60s interrupt

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



Joined: 12 Mar 2006
Posts: 20

View user's profile Send private message

60s interrupt
PostPosted: Mon May 05, 2008 8:12 am     Reply with quote

i want to make my system interrupt for every 60s, but my code seem like not working correctly, anyone can tell me?
code:
Code:
#include <16f877a.h>
#fuses hs, nowdt, nolvp, noprotect, noput, nobrownout,nocpd, nodebug, nowrt
#use delay(clock=4000000)
#include <flex_lcd.c>

boolean  msBool = false;



void clearLCD()
{
    printf(lcd_putc, "\f");
   delay_ms(1000);
}

//===================================
void main()
{
   set_TRIS_A(0xff);
   set_TRIS_D(0x00);
   setup_adc_ports(all_analog);   //Set all ADC ports to analogue input
   setup_adc(adc_clock_div_32);
   setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_8 );
   set_timer1 (29000);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(global);
   lcd_init();
   
     lcd_gotoxy(1,1);
    lcd_putc("hello");
   while(1)
   {
     
       if(msBool == true)
        {
            lcd_gotoxy(1,2);
            printf(lcd_putc,"hello int");
            delay_ms(1000);
            clearLCD();
            msBool = false;
          }
         
    }
}
 
 
// Timer ISR overflows every 1 ms
#INT_TIMER1                       
void clock_isr()
{
   msBool=true;
     
   
}
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: 60s interrupt
PostPosted: Mon May 05, 2008 8:20 am     Reply with quote

Can you tell us what you are seeing? You say it is "not working correctly". Does that mean your LCD display that indicates an interrupt is never showing up? Or that it is showing up at the wrong rate? Don't make us guess what you mean.

Robert Scott
Real-Time Specialties
Ttelmah
Guest







PostPosted: Mon May 05, 2008 8:44 am     Reply with quote

Well, simple calculation says:
Master clock 4MHz.
/4 (peripheral clock)
/8 (prescaler)
/65536 (timer 1 division)

Will give an interrupt about twice per second (1.907*/sec). Not 'every mSec' as noted, or every '60s' as in the comment.
Setting it forward to 29000, brings this down to about a quarter second after this point, but you only do this once.

Best Wishes
handsprince



Joined: 12 Mar 2006
Posts: 20

View user's profile Send private message

PostPosted: Mon May 05, 2008 9:15 am     Reply with quote

the program was not overflow for every 60s, it overflow for every 1s only.what actually the "set_timer1 (29000)" do?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon May 05, 2008 2:24 pm     Reply with quote

handsprince wrote:
what actually the "set_timer1 (29000)" do?
translates to:
Quote:
I have copied a program from the internet and have no clue how it works. The program uses a command that I don't understand and I'm too lazy to look it up in the manual. Who is willing to waste precious spare time to help me?
Sorry, I'm going to watch a movie. Rolling Eyes
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Mon May 05, 2008 5:31 pm     Reply with quote

handsprince wrote:
the program was not overflow for every 60s, it overflow for every 1s only.what actually the "set_timer1 (29000)" do?


With the settings you have, it is impossible to make an interrupt occur just once in 60 seconds. But why bother? It is just as easy to allow interrupts to occur once a second and then count 60 of those interrupts to get your one minute event. In answer to your question, set_timer1(29000) loads the value 29000 into the TMR1H,TRM1L register pair.

Robert Scott
Real-Time Specialties
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