To answer the question literally, yes, the 8051 UART data frame is configurable.
But as you found, the 8051 UART cannot be configured for all these parameters and in any combination. Let's look at them separately and consider solutions.
The documentation is the best source of information. The 8051 ecosystem is extensively documented in the internet.
Word Length
The 8051 UART sends 8 data bits in mode 1, and 9 data bits in mode 2 and mode 3. Let's ignore mode 0, as it is not an asynchronous mode.
The mode 1 is best applicable, if you want 8 data bits and no parity.
You can send less than 8 data bits, if you fill the most significant bits of the value to send with ones. For example, if you want 6 bits, bit-or the value with 0xC0 (C) / 0C0H (assembly), and you have the stop bit in bit 6 (0x40) and additional idle bits.
However, for this example, on reception the UART needs these additional idle bits to catch the following transmission correctly. If the communication partner sends only the stop bit and no idle bit, the following transmission could be lost, depending on its value and the configuration.
Stop Bits
The sending part can only send exactly 1 stop bit.
If you use less than 8 data bits, you inevitably send more than 1 stop bit, because you "fill" the value with the stop bit and potentially idle bits.
If you need 8 data bits and 2 stop bits, use one of the 9-bit modes and set TB8
unconditionally to 1. (But see below for parity.)
If you really need to send 1.5 stop bits, you need to time the write to SBUF
exactly and accordingly, because the start of the transmission depends on the moment of that write access.
Anyway, each UART receiver accepts more stop bits than configured. The additional stop bits are regarded as idle period. So you can always send more stop bits than the receiver is configured for.
The receiving part expects always 8 or 9 data bits and 1 stop bit. If the communication partner sends more stop bits, they are regarded as idle period.
But you are out of luck, if you need to receive less than 8 data bits (or 7 data bits and a parity bit) and only 1 stop bit without any idle period.
Parity Bit
The modes 2 and 3 are provided for 8 data bits plus even or odd parity. If you have the value to send in ACC
, simply move the parity bit from the PSW
into TB8
. Depending on the required parity, you will invert it in the move. On reception, the parity bit will be in RB8
.
If you use less than 8 data bits, use the next-higher bit for parity. For example, with 7 data bits, use bit 7 (0x80) for the parity bit.
Luckily, all bits of ACC
, PSW
(for P
), and SCON
(for TB8
and RB8
) are bit-addressable for easy bit manipulation.
Please be aware that you need to insert some idle period in software, if you want to send 8 data bits, an even or odd parity bit, and more than 1 stop bit. This idle period will output more ones, which the receiving communication partner will regard as the expected additional stop bits.
Final Lines
Don't make things more complicated than necessary. These days you will most certainly not need the majority of the combinations. In more than 40 years of programming I rarely encountered other modes than 8-N-1 (more than 95% of all applications), 7-E-2, or 8-E-1. I never saw usages of 5 or 6 data bits, or 1.5 stop bits.
Implement just what you really need.
Read the documentation. Write experimental programs to learn the details. Use an oscilloscope, logic analyzer, or protocol analyzer to verify your configuration.
Oh, and withstand the usage of interrupts until you really understand the implications. Especially in your experimental programs avoid them.