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

TIMER operation

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








TIMER operation
PostPosted: Sat Sep 10, 2005 6:03 am     Reply with quote

Hi all,
Im a newbie and wanted to start, stop timer1 when certain events occur, i saw the example ex_patg.c. I wanted to know how can we start,stop the timer1. Plz guide
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Mon Sep 12, 2005 8:30 am     Reply with quote

It depends on which PIC you are using. Since you didn't specify which one you have I will show you how I control an 18F452.

First you need to define some registers..

Code:

/////////////////////////
//  register definitions
/////////////////////////
#byte T0CON = 0xFD5  // register that has Timer0's ON/OFF bit in it
#byte T1CON = 0xFCD  // register that has Timer1's ON/OFF bit in it

// TOCON bits
#bit TMR0ON = T0CON.7  // Timer0's ON/OFF bit

// T1CON bits
#bit TMR1ON = T1CON.0  // Timer1's ON/OFF bit


Now, somewhere in your code you will turn the timer on or off...

Code:

TMR0ON = 1; // turn on Timer0(start the counter counting)

TMR0ON = 0; // turn off Timer0

TMR1ON = 1; // turn on Timer1

TMR1ON = 0; // turn off Timer1


Remember, this is for the 18F452. Not all timers, on all PIC's, have this bit available. You'll need to examine the spec. sheet in the timer section.

Ronald
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Mon Sep 12, 2005 10:03 am     Reply with quote

For the 18F45X (e.g. 458 or 452), I have used the following library functions in the beginning of my main() to set up the timers and set them to zero. They are automatically running from that point.

Code:

    setup_timer_0(RTCC_INTERNAL | RTCC_DIV_64);
    set_timer0(0);

    setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
    set_timer1(0);

    setup_timer_3(T3_INTERNAL | T3_DIV_BY_1);
    set_timer3(0);
   
    enable_interrupts(INT_TIMER3);
    enable_interrupts(INT_TIMER1);
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