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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
ORG 0000H
	MOV TMOD , #20H
	MOV TH1, #0FDH ; 9600 Baud Rate
	MOV SCON , #50H
	SETB TR1
	
	AGAIN:
	
	MOV A , #'V';
	ACALL TRANS
	MOV A , #' ';
	ACALL TRANS
	
	SJMP AGAIN
	
	TRANS: MOV SBUF , A
	HERE: JNB TI , HERE
	CLR TI
	RET
END

Explanation

Initialization

  1. MOV TMOD, #20H: Configure Timer 1 in mode 2 (8-bit auto-reload)
  2. MOV TH1, #0FDH: Set baud rate to 9600 bps
    • With 11.0592 MHz crystal
  3. MOV SCON, #50H: Configure serial port
    • Mode 1: 8-bit UART
    • REN = 1: Enable reception (can receive if needed)
  4. SETB TR1: Start Timer 1

Main Loop

  1. MOV A, #‘V’: Load character ‘V’ (56H)
  2. ACALL TRANS: Call transmit subroutine
  3. MOV A, #’ ‘: Load space character (20H)
  4. ACALL TRANS: Call transmit subroutine
  5. SJMP AGAIN: Repeat continuously

Transmit Subroutine (TRANS)

  1. MOV SBUF, A: Load data into serial buffer (starts transmission)
  2. JNB TI, HERE: Wait for transmit interrupt flag
    • TI = 1 when transmission is complete
  3. CLR TI: Clear transmit interrupt flag
  4. 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.