View previous topic :: View next topic |
Author |
Message |
handsprince
Joined: 12 Mar 2006 Posts: 20
|
60s interrupt |
Posted: Mon May 05, 2008 8:12 am |
|
|
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
|
Re: 60s interrupt |
Posted: Mon May 05, 2008 8:20 am |
|
|
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
|
|
Posted: Mon May 05, 2008 8:44 am |
|
|
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
|
|
Posted: Mon May 05, 2008 9:15 am |
|
|
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
|
|
Posted: Mon May 05, 2008 2:24 pm |
|
|
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. |
|
|
RLScott
Joined: 10 Jul 2007 Posts: 465
|
|
Posted: Mon May 05, 2008 5:31 pm |
|
|
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 |
|
|
|