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

kbhit with get_string problem

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



Joined: 25 Jul 2007
Posts: 16

View user's profile Send private message

kbhit with get_string problem
PostPosted: Sun May 24, 2009 1:09 pm     Reply with quote

Hello


I'm trying to send some commands to a PIC18F4550 through RS232. At this point I'm able to send the commands and capture them in the PIC, but I'm using get_string to do this. I have other things to do while I'm waiting for the commands, but the program hangs in get_string.
I think I could solve this problem if I had the hardware UART free, but unfortunately it's being used for other peripherals. So I'm using a software UART.

My question is: Is there a way to solve this problem without using the #int_rda, only available with the hardware UART?

I've tried to use kbhit() with get_string, but apparently this idea doesn't solve the problem, because I can only receive the commands sometimes.

Code:

#include "input.c"
#include "string.h"

char store[5];

//+++++++++++++++++++++++++++++++++++++++++++++++++++
void search_command_string(){

   if(kbhit){
      get_string(store, sizeof(store));
   }
//+++++++++++++++++++++++++++++++++++++++++++++++++++



Compiler Version: 4.074
Any help is appreciated Smile
Ttelmah
Guest







PostPosted: Sun May 24, 2009 2:58 pm     Reply with quote

Multiple parts:
You can, if you have the pin available, use the conventional 'INT_EXT', as an interrupt to trigger the start of receiving a character on the software UART. A search here will find a lot about this.
Even the hardware UART, will have the same problem, using get_string. Get_string, _waits_ for a complete string. Get_string, is not 'rocket_science', it's source is in input.c, and is only about ten lines long. Rewrite this, to check kbhit, before retrieving a character, use global or static variables, to store the string, and a separate flag, to say that the string is complete. Then you can perform your other tasks, till the flag sets.

Best Wishes
ShellTox



Joined: 25 Jul 2007
Posts: 16

View user's profile Send private message

PostPosted: Sun May 24, 2009 3:23 pm     Reply with quote

Thank you for your advices Ttelmah and quick answer Smile

Fortunately I have a free external interrupt pin just beside my rx pin.
I'm going to see the source code of get_string. If I can solve this problem I'll give some feedback.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

this is known to work
PostPosted: Mon May 25, 2009 8:57 am     Reply with quote

here is a link to code that does work pretty much as you want - that had useful input from TTelmah and PCM prgrammer -


http://www.ccsinfo.com/forum/viewtopic.php?t=38922&highlight=


Last edited by asmboy on Mon May 25, 2009 11:41 am; edited 1 time in total
ShellTox



Joined: 25 Jul 2007
Posts: 16

View user's profile Send private message

PostPosted: Mon May 25, 2009 9:51 am     Reply with quote

Thank you for your replies Smile


It's indeed a very useful link, with very good ideas.
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