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

I need to communicate between an RS232 and the UART of an 80C2051 microcontroller in order to program another 8051 chip. I have configured the correct settings for the UART set up, all I would really like to do is send a character from RS232 and view it in hyperterminal, writing the software in C language as opposed to Assembly. does any one know the correct way to do this? I have looked at many code examples and they dont really give much as to how this is done for example sending the character '$' and how it is recieved on UART, and how you can check this is correct using Hyperterminal.

Parents Reply Children
  • communicate between an RS232 and the UART of an 80C2051
    .... but you can communicate between the UART and a MAX232(equivalent) and between the MAX232(equivalent) and RS232.

    Erik

  • Hi

    Thanks for your quick responses. I have previously read the RS232 guide before now, however it gives the code in assembler and whenever i write assembly language in Keil, Keil kicks out a load of errors even though I have adhered to everything I have read in books, on the net etc. so i really would prefer this to be written in C if anyone could still help on that?

    I am using a Max232 taken from the RS232, and I have taken a Transmit line and a Recieve line from the max232 to the Tx and Rx lines of the 80C2051. from this I am using the MOSI, MISO and SCK lines to program a 89S4051. i really would be grateful if anyone could shed further light on the matter

  • whenever i write assembly language in Keil, Keil kicks out a load of errors even though I have adhered to everything I have read in books

    either Keil missed writing something or you missed reading something.

    Post the .lst (if it is very long just post from the beginning to after ~10 errors) and someone (maybe me) will tell you what is wrong.

    Erik

  • Hi Erik

    the following assembly code kicks out errors in keil:

    MOV SCON,#50h
    MOV TMOD,#20h
    MOV TH1,#253
    SETB TR1
    
    JNB RI,$
    MOV A,SBUF
    CLR RI
    CLR TI
    MOV SBUF,A
    JNB TI,$
    SJMP
    

    Please bear in mind I have used #include<REG51.h> and #include<stdio.h> and saved the file as an A51 file. When built the error message is 'C:\Keil\C51\INC\ATMEL REG51.H: error A10: ATTEMPT TO DEFINE AN ALREADY DEFINED SYMBOL, and it appears to do this for all the UART configurations as shown above. Any suggestions?

  • based on the little you give, I can only guess

    1) Look in the .lst file, you may see that inadvertently you define something twice.

    2) You should never include stdio in an assembler file GET RID OF IT

    Erik

    If this does not solve the problem, then post the whole .lst file, I know it will fill up some spece here, but so be it.

    Erik

  • "the following assembly code kicks out errors in keil"

    No, it doesn't!

    Read the message carefully, and think about what it is telling you:

    'C:\Keil\C51\INC\ATMEL REG51.H: error A10: ATTEMPT TO DEFINE AN ALREADY DEFINED SYMBOL
    


    The message refers specifically to the REG51.H file - not to the code that you posted!

    Remember that REG51.H is a 'C' header file: it defines the 8051 SFRs, because 'C' knows nothing of SFRs - but the Assembler has these definitions built-in. Thus using the 'C' header tries to re-define things that are already built-in to the assembler; ie, it attempts to define already-defined symbols - just as the message says!

    See: http://www.keil.com/support/man/docs/a51/a51_xb.htm

    And, as Erik says, stdio.h has no place in an assembler file!

  • "it gives the code in assembler ... I really would prefer this to be written in C"

    The assembler explains what you need to do; once you understand that, it should be easy to write it in 'C'

    eg, reading & writing SFRs is a doddle:

         MOV  SCON, #50h
         MOV  TMOD, #20h
         MOV  TH1,  #253
         SETB TR1
    

    just becomes

         SCON = 0x50;
         TMOD = 0x20;
         TH1  = 253;
         TR1  = 1;
    

    doesn't it?!

    And the "Hello World" examples are in 'C':
    http://www.keil.com/support/man/docs/uv3/uv3_ex_hello.htm

    And there's interrupt-driven 'C' code in the downloads...

  • so your saying i should remove the REG51.H file. Im not too experienced with keil as you may have guessed

  • there are two methods
    1) if you are happy with the definitions for the old steam driven original '51 do not include a "SFR definition file" and the 'default' will be there.
    2) if you want a specific set of SFR defs do like this

    $NOMOD51 ;;// this removes the 'standard defs'
    $INCLUDE (cyf120.h)
    

    Erik

  • Thanks a lot guys, you've been a great help :D

  • Actually, what I was really saying was that the fact that the examples are provided in assembler should not be an obstacle to you creating corresponding code in 'C' - you shouldn't need to build the examples just to be able to read & understand them.

    Of course, building them may well be a useful exercise in itself, so:

    "you're saying i should remove the REG51.H file"

    No: I said that you can't have both the built-in definitions and the header file - you need to choose just one.

    As Erik said, whether or not you choose to keep the header file depends largely on whether you think there's anything else in it that's worth having...