|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
Timer0 question - what should I do? |
Posted: Thu Feb 18, 2010 11:52 am |
|
|
need help plz
Hi, I'm using timer0. I need to show real time elapsed time on lcd.
This is my code...
Code: |
#include <16F877A.h>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=20000000)
#include <lcd flex driver.c>
int main()
{
float dt;
lcd_init();
SETUP_TIMER_0(0);
set_timer0(0);
while(1)
{
dt=get_timer0();
printf(lcd_putc,"\fX:%3.2f",dt);
}
return 0;
} |
Code can be compiled, but when simulated with Proteus, the highest value is only 250++, then it will restart.
I already tried playing with setting here --> set_timer0(0);
but it didn't work.
I want it work as stopwatch. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 18, 2010 12:31 pm |
|
|
Quote: | then it will restart. |
You are testing it in a loop. When Timer0 counts up to 0xFF, then it rolls
over to start again at 0x00. That's the normal behavior of the timer.
Also, your printf() statement takes a large amount of time to execute.
During that time, many counts of the timer will be skipped. You won't
see them in the display.
CCS has stopwatch examples for Timer0, Timer1, and Timer2.
See these files in the CCS compiler directory:
Quote: |
c:\program files\picc\examples\ex_stwt.c
c:\program files\picc\examples\ex_stwt1.c
c:\program files\picc\examples\ex_stwt2.c
|
|
|
|
|
|
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
|