|
|
View previous topic :: View next topic |
Author |
Message |
renato
Joined: 02 Sep 2005 Posts: 5
|
Contador and TIMER0 in C |
Posted: Sun Sep 25, 2005 1:13 pm |
|
|
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
|
|
Posted: Sun Sep 25, 2005 2:57 pm |
|
|
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
|
|
Posted: Thu Nov 17, 2005 12:17 pm |
|
|
very thanks |
|
|
|
|
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
|