This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

8051 serial interfacing

hey frnds. i have problem in sending char serially in normal program. when i try to send 'A' it sends '?'. this is my program. plz help me guyz to solve this problem.

#include<reg51.h>
void main(void)
{
        TMOD=0x20;
        TH1=0xFD;
        SCON=0x50;
        TR1=1;
        while(1)
        {
        SBUF='A';
        while(TI==0);
        TI=0;
        }
}

  • .. when you do not give complete information
    which chip manufacturer and ALL numbers and letters?
    which clock speed ?
    do you have a MAX232(equivalent) between the uC and the PC?

    nobody can help you ....
    and few want to help you when you use gibberish like "plz help me guyz".

    Erik

  • i'm using at89c51. and simulate in proteus using vertual terminal. and also use max232 connection. All number and letters send different output like symbols. clock speed is 12MHz.

  • Are you sure that they are sending "different"?

    Maybe it's the receiving end which is interpreting them differently?

    Think about how that might happen...

  • TMOD=0x20; TH1=0xFD;

    clearly the author of the 'sample code' you used did not bother to mention oscillator speed (you must have used 'sample code' or you would never be here with this)

    as said many times "if you can not code it yourself, sample code is worthless"

    Erik

  • Lifting from a better example

    TMOD=0x20; // Timer 1 Mode 2
    TH1=0xFD; // Baud rate = 9600 for 11.0592 MHz XTAL

    So not 12 MHz then, oops

  • I think most people have learn lots of their skills from looking at other peoples code.

    But it really is 100% important to look at every single line and understand it. If it can't be understood with available documentation then the code is either for a black-magic processor (like some driver code in a Linux system, where the manufacturer did write the code based on undocumented knowledge) or the original author did something wrong. Or the code is just solving an advanced problem at a skill level too far ahead.

  • this is my program.

    No, it's not. It's clearly somebody else's program which you copy-pasted without knowing how it works.

    If this were actually your program, you would have had to ask yourself a lot of questions, and find answers to those questions before you could write a program. Along that way, you would have gathered the knowledge needed to understand why this program cannot do what you wanted yours to do. But you did none of that, which is why you have learned nothing from this homework exercise. In other words: you failed.