To send the value of the serial port register, you first need to store the value of the register in a variable, and then use the serial port send function to send the value of the variable.
The steps are as follows:
1. Read the value of the register into a variable.
2. Use the serial port send function to send the value of this variable.
Here is an example of C, assuming you want to send out the value of register TDR:
c
#include < stdio.h>
\/\/ Define TDR register address
unsigned int *TDR = (unsigned int *)0x40008000;
\/\/ Define the serial port sending function
void send_serial_data(unsigned int data) {
\/\/ The data to be sent is stored in the TDR register
*TDR = data;
}
int main() {
unsigned int register_value = 0x55; \/\/ Suppose the initial value of the register is 0x55
\/\/ Send the register value
send_serial_data(register_value);
return 0; In the above code, we first define the address of the TDR register and define a function, send_serial_data, to send serial data. In the main function, assign the value of the register to the register_value variable and call send_serial_data to send the value of register_value.
This is just an example, in reality, according to the specific single-chip microcomputer model and serial communication protocol to write the corresponding code.
Normal transmission on the line, such as using the computer's serial port wizard, the MCU will automatically send 8-bit data into the SBUF register after receiving, and set the serial port receiving flag bit RI to 1, directly read from it