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 CCS Technical Support

Timer0 question - what should I do?

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








Timer0 question - what should I do?
PostPosted: Thu Feb 18, 2010 11:52 am     Reply with quote

Sad 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

View user's profile Send private message

PostPosted: Thu Feb 18, 2010 12:31 pm     Reply with quote

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
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