View previous topic :: View next topic |
Author |
Message |
DaveKush
Joined: 10 Jan 2006 Posts: 6
|
Timed getchar() using INT_TIMER1 ISR |
Posted: Thu Jan 12, 2006 12:10 pm |
|
|
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
|
|
Posted: Thu Jan 12, 2006 12:49 pm |
|
|
OK, forget it. I figured it out. kbhit() is your friend!
Dave |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jan 12, 2006 1:03 pm |
|
|
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 |
|
|
|