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

Timer2 Placement

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



Joined: 03 Sep 2021
Posts: 39

View user's profile Send private message

Timer2 Placement
PostPosted: Sat Sep 04, 2021 11:43 pm     Reply with quote

Hi, I am using the timer0 in Micro. I wanted to replace with timer 2 instead.
Thanks for the tips on how to write the values and how to calculate them.
I want that prescaler 4 for timer 2, and micro clock 8 MHz.
Code:
#INT_TIMER0
void count_overflow()
{
set_timer0(131);
counter++;                     
clear_interrupt(INT_TIMER0);
}

void calculate_time()
{//---------------------------Calculate_time-------------------------//
if (counter>=2000){
   second++;
   counter=0;
  }
if (second>=59){
   minute++;
   second=0;
  }
if (minute>=59){
   hour++;
  }
if (hour>=23){
   hour=minute=second=0;
  }
}

void main(){
  Setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8);
  enable_interrupts(INT_TIMER0);
  enable_interrupts(GLOBAL); 
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Sep 05, 2021 1:44 am     Reply with quote

Look in the 16F1939.h file. Look in the section for Timer2.
It shows you what parameters are for setup_timer_2().

Also look in the CCS manual. Download it here:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
Look on pages 562 and 563 for setup_timer_2().
temtronic



Joined: 01 Jul 2010
Posts: 9093
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Sep 05, 2021 5:08 am     Reply with quote

Also, if you're creating a 'real time clock', see the software 'zero drift RTC' program in the 'code library'. It works for any PIC, any clock.......

Jay
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