Steps To Receive Data Serially in 8051
Steps To Receive Data Serially in 8051
1. Configure Timer 1: Load the TMOD register with the value 20H. This sets Timer 1 in
Mode 2 (8-bit auto-reload mode) for baud rate generation.
2. Set Baud Rate: Load the TH1 register with an appropriate value to configure the baud
rate. For example, TH1 = FDH sets the baud rate to 9600.
3. Initialize the Serial Port: Load the SCON register with the value 50H. This sets the
microcontroller to Serial Mode 1, enabling 8-bit UART communication with start and
stop bits.
4. Start Timer 1: Set TR1 to 1 using the SETB TR1 instruction to start Timer 1 for
generating the required baud rate.
5. Clear the Receive Interrupt (RI) Flag: Use the CLR RI instruction to ensure that the
RI flag is cleared before starting the data reception process.
6. Monitor the RI Flag: Continuously check the RI flag using an instruction like JNB
RI, xx. This flag is set when a full character byte is received.
7. Retrieve the Received Data: When the RI flag is raised, the received byte will be in
the SBUF register. Move the byte into a safe location, such as the accumulator or a
specific memory address.
8. Prepare for Next Character: To receive the next character, return to step 5 to clear
the RI flag and continue monitoring for incoming data.
RECEIVE:
JNB RI, RECEIVE ; Wait for RI flag (character received)
MOV A, SBUF ; Move received data into accumulator
CLR RI ; Clear RI flag for next byte
; Process the data in A here
SJMP RECEIVE ; Repeat for the next character