View previous topic :: View next topic |
Author |
Message |
John Mayer Guest
|
please check this small code! |
Posted: Fri Jun 03, 2005 12:22 pm |
|
|
I want to check the state of time. If timer reaches 1 hour triggerMe shoud be activated. Timer is counting correctly and all is working but i can't activate the triggerMe part... Chip is 16f877 on 4 mHZ.
Part of the code:
Code: | int triggerMe=0;
#INT_TIMER1
void clock_isr()
{
if(--int_count==0)
{
++sec;
int_count = INTS_PER_SECOND;
if(sec==60)
{
sec=0;
min++;
}
if(min==60)
{
triggerMe=1;
}
}
if (triggerMe==1)
{
min=0;
printf(lcd_putc,"f You reach one hour");
}
void main ()
{
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
enable_interrupts(INT_TIMER1);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
DragonPIC
Joined: 11 Nov 2003 Posts: 118
|
|
Posted: Fri Jun 03, 2005 1:25 pm |
|
|
your missing a closing brace '}' after your first if statement in the ISR. Also, make sure
Code: | if (triggerMe==1)
{
min=0;
printf(lcd_putc,"f You reach one hour");
} |
is within the braces of the ISR funtion. _________________ -Matt |
|
![](templates/subSilver/images/spacer.gif) |
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Fri Jun 03, 2005 2:36 pm |
|
|
I changed your clock to match my 16MhZ and changed 2sec/min and 2min/hr
but this now works
Code: |
#include <16F877.h>
#device *=16
#use delay(clock=16000000)
#fuses HS,NOWDT,NOLVP,PROTECT,PUT,BROWNOUT
#use rs232(baud=19200,xmit=PIN_A3,INVERT,stream=DEBUG) // STDERR(same as DEBUG)
#case
#zero_ram
#define VER_MAJOR 1
#define VER_MINOR 02
#define INTS_PER_SECOND 200
int8 int_count;
int8 sec,min;
int1 triggerMe=FALSE;
void main ()
{
int_count=INTS_PER_SECOND;
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
fprintf(DEBUG,"Starting\n\r");
while (TRUE){
if (triggerMe)
{
triggerMe=FALSE;
fprintf(DEBUG,"You reach one hour\n\r");
}
}
}
#INT_TIMER1
void clock_isr()
{
//fprintf(DEBUG,"-");
if(--int_count==0)
{
sec++;
int_count = INTS_PER_SECOND;
fprintf(DEBUG,".");
if(sec==2)
{
sec=0;
min++;
}
if(min==2)
{
triggerMe=TRUE;
min=0;
}
}
}
|
notice.
1-enable interupts (gloabal)
2-a while(true) loop so your code doesn't drop out to 'no-mans-land' and restart
3-take out the printf in the ISR, it is just for debugging |
|
![](templates/subSilver/images/spacer.gif) |
John Mayer Guest
|
|
Posted: Sat Jun 04, 2005 7:22 am |
|
|
Nice solution but there is small problemm in my case. Im triggering this action (*You have reached 1 our or more*) only then when user clicks some button ( status check ), so i can not wait in while till the time is out.
If i take while out then nothing happens.
Do you have some solution for that?
John |
|
![](templates/subSilver/images/spacer.gif) |
libor
Joined: 14 Dec 2004 Posts: 288 Location: Hungary
|
|
Posted: Sat Jun 04, 2005 8:23 am |
|
|
You then put the 'if (triggerMe)...' to the code block executed when the user clicks those buttons. |
|
![](templates/subSilver/images/spacer.gif) |
John Mayer Guest
|
|
Posted: Sat Jun 04, 2005 9:37 am |
|
|
:--))
Yes i did that but then time is counting like there is no block.
Example: If i start counting at 0 and wenn i reach 5 minutes i press status button, but there is no message. Time is counting further like nothing happens.. |
|
![](templates/subSilver/images/spacer.gif) |
|