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

millisecond using timer2

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
X!ndY M@riE
Guest







millisecond using timer2
PostPosted: Thu Jan 24, 2008 10:13 pm     Reply with quote

hi guys.. im trying to learn different things about timers. i have already generated a seconds counter using timer0. Now im planning to create a seconds counter using milliseconds with timer2. its like im counting in milliseconds then everytime i reach 1000 it will count 1 second. but my code seems to be counting so fast. can anybody help me figure out whats wrong with my code? here it is.. thanks everyone.
Code:

#include<16f877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)

byte millisecond;
byte second;

#int_timer2
void time_isr()
{
   if (++millisecond==1000)
      {millisecond = 0;
      ++second;
      printf("%d\n\r",second);
      }
}

void main()
{
   setup_timer_2 ( T2_DIV_BY_4, 250, 5);
   enable_interrupts(INT_TIMER2);
   enable_interrupts(GLOBAL);
   printf("Press any key");
   getch();
   while (1){

      }

   }

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 25, 2008 12:43 am     Reply with quote

Quote:
byte millisecond;
byte second;

#int_timer2
void time_isr()
{
if (++millisecond==1000)
{millisecond = 0;
++second;
printf("%d\n\r",second);
}
}

What's the largest value a byte variable can hold ?
What data type should you use to declare 'millisecond', so that it
can hold a value of 1000 ?
Guest








PostPosted: Fri Jan 25, 2008 2:14 am     Reply with quote

yah.. the moment i clicked the submit button, thats when i realized what is wrong with my code.. it was so stupid of me.. thanks anyway..
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