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

Contador and TIMER0 in C

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Sep 25, 2005 2:57 pm     Reply with quote

Here is sample code to generate a RTCC interrupt every 10 ms.
Code:
#include <16F628A.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
//#use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1, ERRORS)

int8 interrupt_flag;

// The rtcc interrupt occurs when the rtcc rolls over
// from FF to 00.
//
// RTCC interrupt rate =
//   Fosc / (4 * rtcc pre-scaler * rtcc pre-load)
//
//   = 4 MHz / (4 * 256 * 39)
//
//   = 100.16 Hz
//
// This gives us a timer tick approx. every 10 ms
// (9.98 ms actually).

#define RTCC_PRELOAD (256 - 39)

#int_rtcc
void rtcc_isr(void)
{
set_rtcc(RTCC_PRELOAD);

interrupt_flag = 1;

}

//===============================
void main()
{

// Setup the RTCC to increment at a rate of 3906.25 Hz.
// Then set the preload to 39 so that it will roll over
// after 39 clocks, which gives a 100 Hz interrupt rate.
setup_counters(RTCC_INTERNAL, RTCC_DIV_256); 
set_rtcc(RTCC_PRELOAD);

interrupt_flag = 0;
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);


while(1)
  {
// Create a 1 ms pulse each time the interrupt flag is set
// by the int_rtcc routine.
   if(interrupt_flag == 1)
     {
      output_high(PIN_B1);   
      delay_ms(1);
      output_low(PIN_B1);
   
      interrupt_flag = 0;   // Then clear the flag
    } 
  }
}
respected
Guest







PostPosted: Thu Nov 17, 2005 12:17 pm     Reply with quote

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