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

18F252 getc() and timed_getc()

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



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

18F252 getc() and timed_getc()
PostPosted: Thu Jul 01, 2004 12:38 pm     Reply with quote

If I use getc() my program works but the timed_getc() always return the 0xff that I have defined. I got this example right out of the help files. I am already using the interrupt driven uart for another function and this is a simple 1 byte receive from pin_a5. I get the data once a second. I don't want to get hung-up with getc(). I've tried longer delays but it always times out.

Code:
char timed_getc() {
   long timeout;
   char rc;
   timeout=0;
   while(!kbhit()&&(++timeout<10000)){
          delay_us(10);
   }

   if(kbhit()){
          rc = getc();
          rccnt++;
          return(rc);
   }
   else {
          xccnt++;
          return(0xff);
   }
}
ljbeng



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

PostPosted: Thu Jul 01, 2004 12:52 pm     Reply with quote

Another clue...

timed_getc works if I put it in-line and do not call it as a subroutine.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 01, 2004 1:09 pm     Reply with quote

I don't see that you're using "streams" to identify the two different
USARTS (soft and hard) that you have in your program.

So, you must be using the method where all code associated with
one USART is placed after the #use rs232() statement for that USART.

I suspect that you were using an #include statement to include the
timed_getc() function in your program. Where was that #include
statement placed ? If it was placed in your program just after the
line for the hardware USART, then the compiler would generate code
for the hardware USART for getc() in that function. (Instead of for
the soft USART, as you desired).

When you placed the timed_getc() function inline, I assume you copied
it from the file and pasted it into your program. You probably put
it after the #use statement for the soft USART. That's why it worked.
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