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

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
renato



Joined: 02 Sep 2005
Posts: 5

View user's profile Send private message

Contador and TIMER0 in C
PostPosted: Sun Sep 25, 2005 1:13 pm     Reply with quote

my English this horrivel oks?!!! :)

Hello .... im with an enormous difficulty in program in C; i'm using 16f628A and I have to make an accountant of 10ms that it must be gone starter to give 1 I beat in the pulse of the sensor, and to go counting counting counting and to each time that to pass 10ms one variavel any must be developed (type an accountant of 10ms where he goes to count how many times 10ms had been counted) and I go to have q to give more 4 pulses to apartir of the detonation to armaznar the value of instantaneo time of how many the 10 times ms had been counted..... these values must be stored in different variaveis... stop later I presenting in the display....... I am no obtaining well to make a routine in C using timer0..... if they alguem will have some similar thing q can help or to a good ideia I to me tanks.
thanks Renato Z.
Obs ** im not work the IC2 protocolo !!!

thanks sorry for my english :)
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