On this page
Serial Communication - Transmit
This program demonstrates how to transmit data via UART serial communication on the 8051.
Description
The program configures the serial port and continuously transmits the character ‘V’ followed by a space at 9600 baud rate.
Configuration
- Baud Rate: 9600 bps
- Mode: 8-bit UART, variable baud rate
- Timer 1: Used as baud rate generator
Code
| |
Explanation
Initialization
- MOV TMOD, #20H: Configure Timer 1 in mode 2 (8-bit auto-reload)
- MOV TH1, #0FDH: Set baud rate to 9600 bps
- With 11.0592 MHz crystal
- MOV SCON, #50H: Configure serial port
- Mode 1: 8-bit UART
- REN = 1: Enable reception (can receive if needed)
- SETB TR1: Start Timer 1
Main Loop
- MOV A, #‘V’: Load character ‘V’ (56H)
- ACALL TRANS: Call transmit subroutine
- MOV A, #’ ‘: Load space character (20H)
- ACALL TRANS: Call transmit subroutine
- SJMP AGAIN: Repeat continuously
Transmit Subroutine (TRANS)
- MOV SBUF, A: Load data into serial buffer (starts transmission)
- JNB TI, HERE: Wait for transmit interrupt flag
- TI = 1 when transmission is complete
- CLR TI: Clear transmit interrupt flag
- RET: Return to caller
Output
The program continuously sends: V V V V ... over the serial port.
Baud Rate
With 11.0592 MHz crystal and TH1 = 0FDH:
- Baud Rate = Crystal / (384 × (256 - TH1))
- Baud Rate = 11,059,200 / (384 × 3) = 9600 bps
This is a common baud rate for serial communication with PCs and other devices.