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

Serial Communication w/ AT89C51 or AT89C52

I want to have a simple program to print something out using hyperterminal. Also it would be nice to receive a character and echo it back. I have been able to do this in assembly but I can't get it to work in C. Here is the latest code I have tried:

#include <AT89X51.H> 
#include <CTYPE.H>
#include <STDIO.H>

int i;

void main()
{
SCON = 0x50; //SCON: mode 1, 8-bit UART, enable rcvr
TMOD = 0x20; //TMOD: timer 1, mode 2, 8-bit reload 
TH1 = 0xFD; //TH1: reload value for 9600 baud @ 11.0592MHz 
TR1 = 1; //TR1: timer 1 run 
TI = 1; //TI: set TI to send first char of UART 

while (1) 
{
P1 ^= 0x01; 
printf ("\n\nHello World\n\n"); 
i = _getkey();
putchar('$');
putchar(i); 
}
}

Is there anything wrong with my code? Or is there something in how I am compiling? I am confident my hardware is fine because I can get it to work in assembly. Any help would be appreciated. Thank you.

Parents
  • stdio.h will do.

    You can understand the #include - control as a substitute of
    pasting the Text of the included File into the including module.

    The preprocessor of C doesn't anything else.

    If you costumize the functions, you must add your
    custom object file(s) to the list of objects to be linked.

    You're maybe talking about the "left window" of your IDE.
    I don't use an IDE for 8051 Projects. I just hack the text into
    files, using a text editor. Then invoke compiler and linker directly
    via Windows-Explorer and entries in the Registry:

    [HKEY_CLASSES_ROOT\c_auto_file\shell\C51-Compiler_Emulator\command]
    @="C:\\C51\\BIN\\C51.EXE  %1 DEFINE ( TEST_CODE = 1 ) OE PP"
    

    Norbert

Reply
  • stdio.h will do.

    You can understand the #include - control as a substitute of
    pasting the Text of the included File into the including module.

    The preprocessor of C doesn't anything else.

    If you costumize the functions, you must add your
    custom object file(s) to the list of objects to be linked.

    You're maybe talking about the "left window" of your IDE.
    I don't use an IDE for 8051 Projects. I just hack the text into
    files, using a text editor. Then invoke compiler and linker directly
    via Windows-Explorer and entries in the Registry:

    [HKEY_CLASSES_ROOT\c_auto_file\shell\C51-Compiler_Emulator\command]
    @="C:\\C51\\BIN\\C51.EXE  %1 DEFINE ( TEST_CODE = 1 ) OE PP"
    

    Norbert

Children
No data