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

sending string with parity

hello to all !!!

I am using ADUC841 and i want do sent a string
in that format (8 bit ,1 stop bit, odd - parity)
I am writing in C51

how can i set the my MCU to output this string with parity ?????

how i a setup the UART to send with parity ???

my program

void main(void)
{ T3CON = 0x86; // Configure the baud rate 9600
T3FD = 0x08;
SCON = 0x52;

printf("hello"); // the string i want to set with // odd pariy
}

thanks in advance to the helpers

mayer

  • Dude,
    I am not a C51 guy, ok? But I have done exactly the same thing for an STR9 just yesterday. You know how? I read the manual and configured my UART appropriately. It works like magic!
    Conclution: Read the manual and it will work like magic for you, too !

  • In this case, "The Manual" means the Datasheet for the particular chip you are using.

    For technical details applicable to the 8051 architecture in general, study the so-called "bible" for the 8051:

    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

    The Keil manuals are here:
    http://www.keil.com/support/man_c51.htm

    And here are some other introductory & reference materials:
    http://www.keil.com/books/8051books.asp
    www.8052.com/books.phtml
    www.8052.com/tutorial.phtml

  • hey you know it is ez for to doing

    void main(void)
    {
      char i;
    
      set_communication_parameters ( DATA_8, STOP_1, PARITY_ODD );
    
      printf ( "here is my message" );
    
      for ( i = 1 ; i < 256 ; ++ i )
        ;
    }
    

  • /b thanks man for the help /b

    could you send me a code example that set the UART
    to sent with parity(odd/ even)

    how you implemented it on your STR9

    thanks

    mayer

  • How it is implemented on an STR9 is almost certainly totally irrelevant to how it would be implemented on an 8051!

    It is extremely unlikely that the UART on the STR9 is the same as the UART on an 8051!

    You must study the data sheet for the device you are actually using!

    Have you actually done that yet?
    Have you looked at the configuration options that are available?
    If you haven't done that, there's no point in sending sample code - because you won't understand it!

  • It is not so easy. The 8052 does not do parity. You will have to calculate it. With 7 bits you would put it as the last bit. But with 8 bits you can try using the 9th bit (TB8 and RB8) in the SCON register.

  • The 8052 does not do parity
    it does; however there is no means of using that feature in C.

    When parity is required, I just write the ISR in assembler and take advantage of the 'P' bit.

    Erik

  • Correct me if I'm wrong (and I'm not feeling too chipper today), but a way to control the parity of the transmitted byte can be done in "C" and does not require an assembly source file. (Seriously, correct me if I'm wrong).

    By assigning the ACC with the byte to be transmited, the PSW is updated.

    A direct ACC = Byte_Value will load the accumulator with the value without [executable] side effects.

    The PSW contains the a parity bit in the bit-addressable and defined sbit "P". This bit can then be transfered into the 9th bit by assigning the pre-defined sbit "TB8" the correct value for parity for your odd/even requirements.

    
    #define PARITY_STATUS   P   // "P" is a pre-defined bit in the PSW SFR for parity.
                                // (I'm just giving it a better name that just P)
        // bit     parity;
        // u8 data the_byte;
        // ...pre-code
    
        ACC    = the_byte; // Actually loads the ACC with no side effects
                           // (YOU MUST check the resulting code to make sure
                           //  that your data-stores behave similarly)
    
        parity = PARITY_STATUS; // Set to 1 when the ACC contains
                                // an odd number of 1 bits
    
        if( parity == 1 ) // based upon the P status, assign your 9th bit
        {
            TB8 = 1; // either 1 or 0 depending upon your parity requirements
        }
        else
        {
            TB8 = 0;
        }
    
        SBUF = the_byte; // then send your byte out
    
        // post-code...
    
    

    Generates the following assembly code:

    
    ; FUNCTION Send_With_Parity (BEGIN)
    
              MOV     A,the_byte
    
              MOV     C,P
              MOV     parity,C
    
              JNB     parity,?C0050
    
    
              SETB    TB8
    
              SJMP    ?C0051
    ?C0050:
              CLR     TB8
    ?C0051:
              MOV     SBUF,the_byte
    
              RET
    
    ; FUNCTION Send_With_Parity (END)
    
    

    It is best to inspect the compiler's output to ensure this is working in your own application.

    --Cpt. Vince Foster
    c/o VRWC (founding member)
    2nd Cannon Place
    Fort Marcy Park, VA

  • This is the code to send with parity
    i tesed on the hyper terminal and it work great !!

    sending:

    ACC = in_string[i]; // P = Even
    TB8 = ~P; // ~p = Odd
    SBUF = ACC;
    while (! TI); // while (TI == 0);
    TI = 0;

    reciving :

    while (RI == 0); // while (! RI);
    RI = 0;
    ACC = SBUF;
    RB8 = P;
    input_line[i] = ACC;

    mayer

  • I would not use the ACC to make an assignment to a variable: don't use ACC as an rvalue...

    sending:
    
    ACC = in_string[i]; // P = Even
    TB8 = ~P; // ~p = Odd
    SBUF = in_string[i]; // changed from ACC
    while (! TI); // while (TI == 0);
    TI = 0;
    
    reciving :
    
    while (RI == 0); // while (! RI);
    RI = 0;
    temp = SBUF;
    ACC = SBUF;
    RB8 = P;
    input_line[i] = temp; // changed from ACC
    
    

    You aren't too sure what the actual accumulator (ACC) will contain by the time you choose to use it as an rvalue. "ACC" is not to be treaded like a 'normal' variable.

    --Cpt. Vince Foster
    c/o VRWC (founding member)
    2nd Cannon Place
    Fort Marcy Park, VA

  • Oops..

    while (RI == 0); // while (! RI);
    RI = 0;
    temp = SBUF;
    ACC = temp;
    

  • it does; however there is no means of using that feature in C.

    Every time this subject comes up on the forum you state that it cannot be done in 'C', in spite of it being well documented in the Keil knowledge base. You have even been corrected on the forum by a member of Keil staff.

    Why, then, do you persist in posting this misinformation?

    In the forlorn hope that you might actually read some documentation and learn something here is a link:

    http://www.keil.com/support/docs/1619.htm