I need to start a function and it must run continiosly until i press a key. I have tested it using "getchar()", but it doesn't work, becuase i need to press something to continue running the software. So, I think that i should start a process that only waits for a key to be pressed, but i don't know how to do this. What can i do?
"I need to start a function and it must run continiosly until i press a key."
Where is this key? Is it connected directly to the 8051, or is it on a remote keyboard connected via RS232 (eg, on a PC), I2C, or somesuch?
"I have tested it using "getchar()", but it doesn't work, becuase i need to press something to continue running the software."
Of course you do - that is exactly what getchar() does! Read the description of getchar: http://www.keil.com/support/man/docs/c51/c51_getchar.htm You will, of course, also need to read the description of the function used by getchar...
The key is from the PC's keyboard. The software must run, until i press 'return' for example.
So getchar() doesnt work, what can i do?
The key is from the PC's keyboard.
But how does it get into your '51 microcontroller ?
via rs-232, i forgot to write it before...
"So getchar() doesnt work"
No - getchar does work; it is doing exactly what it says it should do!
If this is not the behaviour that you require, then you have two choices:
1. Use something else that does do what you require;
2. Modify getchar to do what you require. (The manual tells you how to do this - see the link I gave you earlier!)
rs-232, i forgot to write it before....
Sorry about the triplicate(!) reply - the forum was giving an error:
ERROR TYPE Microsoft VBScript compilation (0x800A03E9) Out of memory /forum/docs/thread8233.asp
but, apparently, it was still doing the post!!
It just did it again - I wonder how many times this one will turn up...
In that case, a simple approach might just poll the UARTs RI bit.
"rs-232, i forgot to write it before...."
This is fundamental!
So, in fact, your 8051 knows nothing about keypresses at all!
All your 8051 knows is when a character has arrived at its serial port - it doesn't know and cannot tell whether that came from a PC, or any other device that could send characters over RS232, nor what caused the character to be sent.
As Christoph hints, the RI bit indicates when the 8051's UART has received a character. For details of how this works, you need to study the so-called "bible" for the 8051:
Chapter 1 - 80C51 Family Architecture: www.semiconductors.philips.com/.../80C51_FAM_ARCH_1.pdf
Chapter 2 - 80C51 Family Programmer's Guide and Instruction Set: www.semiconductors.philips.com/.../80C51_FAM_PROG_GUIDE_1.pdf
Chapter 3 - 80C51 Family Hardware Description: www.semiconductors.philips.com/.../80C51_FAM_HARDWARE_1.pdf
Here are some other introductory & reference materials: http://www.keil.com/books/8051books.asp www.8052.com/books.phtml www.8052.com/tutorial.phtml
Thanks to everybody!!!
Finally i used RI flag and the programm runs perfectly