View previous topic :: View next topic |
Author |
Message |
ShellTox
Joined: 25 Jul 2007 Posts: 16
|
kbhit with get_string problem |
Posted: Sun May 24, 2009 1:09 pm |
|
|
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 |
|
|
Ttelmah Guest
|
|
Posted: Sun May 24, 2009 2:58 pm |
|
|
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
|
|
Posted: Sun May 24, 2009 3:23 pm |
|
|
Thank you for your advices Ttelmah and quick answer
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
|
this is known to work |
Posted: Mon May 25, 2009 8:57 am |
|
|
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
|
|
Posted: Mon May 25, 2009 9:51 am |
|
|
Thank you for your replies
It's indeed a very useful link, with very good ideas. |
|
|
|