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

Delay Using Timer1

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



Joined: 09 Aug 2011
Posts: 6

View user's profile Send private message

Delay Using Timer1
PostPosted: Thu Aug 11, 2011 3:33 am     Reply with quote

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 Smile)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 11, 2011 1:47 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Aug 12, 2011 4:04 am     Reply with quote

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 =)))
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