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

Timed getchar() using INT_TIMER1 ISR

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



Joined: 10 Jan 2006
Posts: 6

View user's profile Send private message Visit poster's website

Timed getchar() using INT_TIMER1 ISR
PostPosted: Thu Jan 12, 2006 12:10 pm     Reply with quote

Guys, do you know of any way to do a getchar() with a timeout occurring if no characters are received? In my code, I'm using INT_TIMER1 to track 1 second intervals, but when I call the soft serial read function, flow transfers to the ISR INT_TIMER1 and never returns. I'm guessing that this has something to do with the interrupts being disabled during a getchar(), but I can't figure out the work-a-round trick.

PIC18f6585, CCS: PCH version 3.218

Code:

#INT_TIMER1                       
void clock_isr() {                                           
  if(--int_count==0) {         
    ++seconds;
    int_count = INTS_PER_SECOND;
  }
}

#use rs232 (baud=9600, rcv=RS232_TO_MB_RCV)
int read_soft_serial(void) {
  while (seconds < 10) {
    getchar();
  }
}


while (1) {
  set_timer1(0);
  seconds = 0;
  result = read_soft_serial()
}
[/code]
DaveKush



Joined: 10 Jan 2006
Posts: 6

View user's profile Send private message Visit poster's website

PostPosted: Thu Jan 12, 2006 12:49 pm     Reply with quote

OK, forget it. I figured it out. kbhit() is your friend!

Dave
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 12, 2006 1:03 pm     Reply with quote

Also look at the timed_getc() function in the CCS example file EX_TGETC.C
It's in this folder:
c:\program files\picc\examples
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