how can the sbuf register be told to send a string that is received?
First of all, you do understand that SBUF is actually two separate registers, don't you?
There is a read-only SBUF, from which you read received bytes; There is a write-only SBUF, to which you write bytes to be transmitted.
Second, you must realise that these are just single-byte registers - therefore they cannot handle strings directly.
To handle strings, you need to write your own functions to handle the strings one byte at a time - or use the supplied library functions.
i tryed reading but it was not easy this is what i coded
main { SBUG="please send me a something" something=SBUF SBUF=soething+'my answer" }
but it does not work
please can you help me b4 monday
See: http://www.keil.com/forum/docs/thread11200.asp#msg54785
See the description of the Standard Serial Interface starting on p9 of Chapter 3 in the so-called "bible" for the 8051 - and pay particular attention to Figures 14-15
Chapter 1 - 80C51 Family Architecture: www.nxp.com/.../80C51_FAM_ARCH_1.pdf
Chapter 2 - 80C51 Family Programmer's Guide and Instruction Set: www.nxp.com/.../80C51_FAM_PROG_GUIDE_1.pdf
Chapter 3 - 80C51 Family Hardware Description: www.nxp.com/.../80C51_FAM_HARDWARE_1.pdf
i tryed reading but it was not easy
It's a technical document. It's not supposed to be light reading. To fully understand it, you'll probably have to read it several times, too !
this is what i coded
No, this is not what you coded, because it wouldn't even compile. "This" is something you re-typed in the text window. If you want to post something that you coded, you need to use copy&paste to avoid introducing more mistakes ! And while you're at it, please read the small print above the text window. It contains detailed instructions on how to post code so that it is legible.
Okay. SBUF is an 8-bit register - a char. In C, you cannot simply copy a string (array of chars) to a single char by using a simple assignment. You will have to write a function that a) reads the string character by character, b) copies each character to SBUF, and c) waits until the UART is actually read to transmit the next character !
Also, you might want to configure the UART before using it. How to do this can be found in the documents mentioned above.
Please read the instructions on posting source code: www.danlhenry.com/.../keil_code.png
Always use copy-and-paste - do not manually re-type into the forum; eg,
has clearly been manually re-typed, as it has basic syntax errors!
Please see my earlier comment about strings
i see you think my code is bad and here is the new one
main { SERIAL(9600,n,8,1,p); char SBUF[ "please send me a something" ]; char something[] = SBUF; char SBUF[ something ] + SBUF[ "my answer" ]; }
i know SBUF is not array and i need [] for array so i try but it still doesnt work
i thinkit is bettar so i only get 2 errors now :)
main() isn't an arreay either, but maybe I can try with [] to get an application suitable for an array processor...
You have already received an answer that says that since SBUF is not an array, you must write a function that iterates through all characters in a string and emits them one-by-one (by first checking if the UART is empty before you write the next character to the SBUF (write-mapped) register).
That same post also said that you - for input - will have to write a function that reads characters one-by-one from the SBUF (read-mapped) register.
No post has invalidated that comment - because it is correct. So you can not just assume that creative use of [ and ] will allow you to perform miracles no one else has managed. SBUF is hardware, and if the hardware SBUF is a single character large, then it doesn't matter how much you try to play around with the compiler. Your hardware will not suddenly grow an array-compatible version of SBUF.
No, it is not better - because you have still not understood that SBUF is only a single byte (in each direction).
Leaving the 8051 and Keil specifics aside, it is not even valid 'C' - eg, what do you think will happen when you use a string as the index to a 'C' array...?!
"i know SBUF is not array and i need [] for array so i try"
You just said it: SBUF is not an array - therefore you cannot use [ ] with it!
You need to spend some time studying a basic 'C' textbook.
"... not even valid 'C' - eg, what do you think will happen when you use a string as the index ..."
Actually, the compiler probably will allow this - as it is, in fact, valid within the syntax of the 'C' language. However, I very much doubt that it will do what you want it to do...
because you have still not understood that SBUF is only a single byte (in each direction).
You are trying to run before you have learned to walk You are trying to walk before you have learned to crawl
There are no shortcuts, sorry.
I know that 'read' is a 4 letter word and am thus sorry to use it, but the only way you will get anywhere is by reading "the bible" more than once. Then read the tutorials here and at http://www.8052.com and then and only then try coding something. Posting questions based on yout total lack of understanding will not get you anywhere.
Erik
"the only way you will get anywhere is by reading "the bible" more than once. Then read the tutorials here and at http://www.8052.com and then and only then try coding something."
Unfortunately not.
That will give you sufficient understanding of the 8051 - but you also need a basic understanding of the 'C' programming language.
So, in addition to the above, you will also need a 'C' textbook.
yes