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

newbeee who needs rtcc "timeout" help

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



Joined: 23 Mar 2004
Posts: 2

View user's profile Send private message Send e-mail

newbeee who needs rtcc "timeout" help
PostPosted: Tue Mar 23, 2004 7:32 am     Reply with quote

hi,
16f877
4mhz
pcm 3.174
i need a simple program that will "timeout." I using a keypad and i want it to stop reading in values from a user after a given time (10 seconds) tried looking at some examples of timer0 and interupts but couldn't see how i could make it stop a particular function. Any help is greatly appreciated
thanks jon
SteveS



Joined: 27 Oct 2003
Posts: 126

View user's profile Send private message

timeout
PostPosted: Tue Mar 23, 2004 8:19 am     Reply with quote

If you want to use a timer and an interrupt do this:

Set up the timer and timer interrupt (per examples) for some reasonable period - in your case probably long since you want a ten second timer. I don't think you can get ten seconds directly since that's too long for the counters you have available at your crystal rate. So you will have a global variable that gets counted up (or down) in the interrupt routine. Lets see -with a 4Mhz clock, Timer0 set up with /256 prescale and run the full 256 counts, you will interrupt every 1/( 4e6/4/256/256) =~ 65msec, so 10sec/.065 =~ 152 counts. In the function that you want a timeout for, set the global counter to 0. The interrupt fires every 65 msec in which you will increment your counter. During your 'wait for user entry' code, look to see if the counter has passed 152. If so your ten seconds are up.

A simpler, non-interrupt method would be to add a delay_ms() in your wait loop - someting like

Code:

for( waitcnt = 0; waitcnt < 100; waitcnt++)
{
   if( /* insert user input test here */) break;  // quit loop if user input
   delay_ms(100);  // wait 100msec before trying again
}
if( waitcnt >= 100 )
   // no user input occured
else
  // handle user input

 


but during the delay_ms() nothing else can be done.

- SteveS
mvaraujo



Joined: 20 Feb 2004
Posts: 59
Location: Brazil

View user's profile Send private message

PostPosted: Tue Mar 23, 2004 11:31 am     Reply with quote

If you want to later expand the code and implement other features, consider implementing the interrupt driven suggestion by SteveS. You can use the TMR0 counter as general counter to the system i known basis, for example, 1ms and work some math to count and set flags of process timeout.

Marcus
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Tue Mar 23, 2004 11:57 am     Reply with quote

I'm sure I have seen this before.

http://www.ccsinfo.com/forum/viewtopic.php?t=18681&highlight=10+second
Guest








PostPosted: Tue Mar 23, 2004 5:12 pm     Reply with quote

thanks guys for all the help, got it working just fine Razz Razz Twisted Evil Razz Razz
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