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 support@ccsinfo.com

please check this small code!

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







please check this small code!
PostPosted: Fri Jun 03, 2005 12:22 pm     Reply with quote

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);
}
DragonPIC



Joined: 11 Nov 2003
Posts: 118

View user's profile Send private message

PostPosted: Fri Jun 03, 2005 1:25 pm     Reply with quote

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
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Fri Jun 03, 2005 2:36 pm     Reply with quote

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
John Mayer
Guest







PostPosted: Sat Jun 04, 2005 7:22 am     Reply with quote

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
libor



Joined: 14 Dec 2004
Posts: 288
Location: Hungary

View user's profile Send private message

PostPosted: Sat Jun 04, 2005 8:23 am     Reply with quote

You then put the 'if (triggerMe)...' to the code block executed when the user clicks those buttons.
John Mayer
Guest







PostPosted: Sat Jun 04, 2005 9:37 am     Reply with quote

:--))
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..
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