|
|
View previous topic :: View next topic |
Author |
Message |
X!ndY M@riE Guest
|
millisecond using timer2 |
Posted: Thu Jan 24, 2008 10:13 pm |
|
|
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
|
|
Posted: Fri Jan 25, 2008 12:43 am |
|
|
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
|
|
Posted: Fri Jan 25, 2008 2:14 am |
|
|
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.. |
|
|
|
|
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
|