Initially, read the serial port data for processing as follows:
While (1)
{
Data = receivebyte ();
Switch (data)
{
Case 'A ':
Function1 ()...
Break;
Case 'B ':
...
Break;
Case 'C ':
...
Break;
Default:
Break;
}
}
In this way, the data can only be read once, and then how to write data to the serial port cannot be read.
Once it enters the display status, it is stuck in an infinite loop and cannot jump out. Refer to the lpc1114 manual to find information about the serial port.
When UART receives data, it can receive data in query or interrupt mode.
Table 4-1 how data is received
Query Method |
The query register u0lsr [0] is used. As long as the data is received, the u0lsr [0] bit is set |
Interrupt mode |
1. Set UART interrupt enable register (u0ier) so that u0ier [0] = 1 2. Open System interruption If the data in the receiving FIFO reaches the trigger point set in u0lsr, the interrupt-RDA is triggered. If data is received but the number of received data is smaller than the trigger point, a character timeout interruption occurs after a period of time-CTI |
When receiving data in the interrupt mode, if RDA is interrupted, the data can be read cyclically from u0rbr. If a character timeout interrupt occurs-CTI, you can use u0lsr [0] to determine whether the FIFO contains valid data.
Solution: You can use the interrupt mode to read data multiple times.