We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi. I'm using an eval board with C1610 (Phytec KC161). I know that KEIL doesn't have the function kbhit(). But I need somthing like that function, is it posible to make one? If does anyone know, please give me ideeas, or, the body of he function, even it is for over device. Thank you.
So why do you not receive the characters one by one, until you have enough characters to form a full command? I think the instruction scanf("%s", command) can read the command I want. What do you think about this code, the question is after code:
//........ bit kbhit(void){ //Return 1 if character available, otherwise 0 if ( S0RIR ) return ( 1 ); return ( 0 ); } void main(void){ char command[10]; unsigned int nr; serial_setup(); //like previous message //...ports init... /* ... some intructions dependent of which command I typed from hyper teminal ... */ if(kbhit()){ printf("Type a command: "); //I have defined some commands wich I use above scanf("%s", command); if(strncmp(command, train, 3)==0) // if the string I typed match a defined command // here I change some variables wich I use above } } The problem is that kbhit() is always true, why? Is it dependent of how many characteres I entered? How can I modify ?
Thank you.
I soleved the problem, I had to delete the S0RIR at the end of the body of if(kbhit()){...} It work fine , with scanf()...
I think the instruction scanf("%s", command) can read the command I want.
How large is the command buffer?
Try to send a couple of extra characters to the unit, and check what happens with your other RAM variables stored directly after the command buffer...
gets() and scanf() are two of the most dangerous functions available in the C library, and you specifically want to use them despite being warned?
Immediately plan for using the watchdog in the processor. You might need it sooner than you think. However, the watchdog can only help to restart a hung application. It will not protect the application from producing erroneous results, caused by buffer overruns.
If you really have decided to use scanf(), at least always specify a maximum field width when retrieving strings. Without a field width, scanf() will behave similar to gets() - trying to receive any number of characters, whatever the size of your buffer is!