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

Long serial timeout

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








Long serial timeout
PostPosted: Fri Jun 22, 2007 3:37 am     Reply with quote

Hi,
Have done many searches but couldn't find answer I was looking for.
PIC is 16LF877 4Mhz. Compiler. 3.181

I am using the code below to read in a serial string.
This works fine.
What I want to to be able to time out if nothing is received for about 10 seconds.
All other timeout routines seem to be too short.
Thanks in advance
Steve

Code:
#include "C:\PIC_C_Code\Smart Modem\Smart Modem.h"
#include <string.h>



void Get_String2();
void get_string(char* s, int max);

#define MAX_BUFFER 10


void main()
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_counters(RTCC_INTERNAL,RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   //Get_Char();
   Get_String2();
   return;

}


void Get_String2()
{
  char string[MAX_BUFFER];

  while(1)
  {
    printf("please type a string: ");

    // Wait for a key press
    while(!kbhit(MODEM));

    get_string(string, MAX_BUFFER);
    fprintf(RDTG,"%s",string);
  }
}


void get_string(char* s, int max)
{
   int len;
   char c;

   --max;
   len=0;
   do {
     c=fgetc(MODEM);
   //  if(c==8) {  // Backspace
   //     if(len>0) {
   //       len--;
   //       putc(c);
   //       putc(' ');
   //       putc(c);
   //     }
   //  } else
     if ((c>=' ')&&(c<='~'))
       if(len<max) {
         s[len++]=c;
         putc(c);
       }
   } while(c!=13);
   s[len]=0;
}
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sat Jun 23, 2007 9:56 pm     Reply with quote

V3.181 is quite old, I´m not sure if in the Examples folder you have the EX_TGETC.C
program that shows exactly what you need.


Humberto
Guest








PostPosted: Thu Jun 28, 2007 2:28 am     Reply with quote

Many Thanks Humberto.
I do have that piece of code.
Was reluctant to use it as I didn't think it would be possible to achieve the 10 seconds I would like?
Is it possible?
(I will play in the meantime)
Thanks again
Steve
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Thu Jun 28, 2007 6:56 am     Reply with quote

Steve,

With the pointed example, I wish you get the way, how to do it. The program
was used widely and I´m not aware of something wrong using it. Of course you
will need to adapt it to your 10 sec timeout application.


Humberto
kevcon



Joined: 21 Feb 2007
Posts: 142
Location: Michigan, USA

View user's profile Send private message

PostPosted: Thu Jun 28, 2007 7:29 am     Reply with quote

Setup a timer to interrupt every 1ms and count to 10000

Code:


voidt main( void )
{
   unsigned int16 timeOutCounter = 0;

   set_rtcc( SomeValue );

   while( !kbhit( MODEM ) && ( timeOutCounter < 10000 ) );

   if ( timeOut Counter > 10000 ) }
      timeOutCounter = 0;
      ///timout code goes here
   }
   else {
      //kbhit code goes here
   }


#pragma INT_RTCC
void ms_timer( void )
{
   set_rtcc( SomeValue );

   timeOutCounter++

}
Guest








PostPosted: Thu Jun 28, 2007 8:36 am     Reply with quote

Getting there. Thanks to all.
Just adapting the example code to suit works fine.
newbie_1974



Joined: 04 Jul 2007
Posts: 4

View user's profile Send private message

timeout
PostPosted: Thu Jul 05, 2007 12:05 am     Reply with quote

hi, would it be possible to get a copy of your time out code, 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