| |||||
Technical Support Support Resources
Product Information | C251: OBTAINING THE PARITY OF A CHARACTERInformation in this article applies to:
QUESTIONIs there a convenient way to obtain the parity of a char value? In assembly language, I can examine the parity bit in the PSW just after loading it into the Accumulator. Is this possible in C51 and C251, too? ANSWERYes. You may use the ACC SFR to access the accumulator in the C language. The following example shows how to get the parity of a character:
#include <reg51.h> // use the header file for the CPU that you are using
// variant 1: global variables
unsigned char c;
bit parity;
void get_parity (void) {
ACC = c; // you may use this code within your function
parity = P;
}
// variant 2: a deticated function to get the parity bit.
bit get_parity2 (unsigned char uc) {
ACC = uc;
return (P);
}
Last Reviewed: Tuesday, June 20, 2000 | ||||
| |||||