View previous topic :: View next topic |
Author |
Message |
raflab
Joined: 09 Aug 2011 Posts: 6
|
Delay Using Timer1 |
Posted: Thu Aug 11, 2011 3:33 am |
|
|
I'm trying to create a delay with N minutes using timer 1 .. I found the following code
Code: |
#include <16F628A.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
//======================
void main()
{
int16 delay = 0;
SET_TIMER1(delay);
SETUP_TIMER_1(T1_INTERNAL | T1_DIV_BY_8);
while(TRUE)
{
if(GET_TIMER1() <32768)
OUTPUT_LOW(PIN_A1);
if(GET_TIMER1() >32768)
OUTPUT_HIGH(PIN_A1);
}
}
|
So if is it possible I want to replace the 0.5 sec by 2 minutes ( for example )
( I said N minutes because that's related to the user that he will be able to send it through VB interface using Serial port communication )
I won't use the delay_ms because it will be imprecise
Thanks ) |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 11, 2011 1:47 pm |
|
|
Most people would do the counting in a Timer1 interrupt routine.
And maybe some people would put a 32.768 KHz watch crystal (with
capacitors) on the Timer1 oscillator pins and have it interrupt once
per second, and count seconds in the interrupt routine.
There is a somewhat complicated example here of the 1st method
(ie. no watch crystal):
http://www.ccsinfo.com/forum/viewtopic.php?t=26177 |
|
|
raflab
Joined: 09 Aug 2011 Posts: 6
|
|
Posted: Fri Aug 12, 2011 4:04 am |
|
|
PCM programmer wrote: | Most people would do the counting in a Timer1 interrupt routine.
And maybe some people would put a 32.768 KHz watch crystal (with
capacitors) on the Timer1 oscillator pins and have it interrupt once
per second, and count seconds in the interrupt routine.
There is a somewhat complicated example here of the 1st method
(ie. no watch crystal):
http://www.ccsinfo.com/forum/viewtopic.php?t=26177 |
it's really very helpful !!! Thanks =))) |
|
|
|