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
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;
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.
Oops..
while (RI == 0); // while (! RI); RI = 0; temp = SBUF; ACC = temp;