kb:8051_uart

UART on the 8051

In order to configure the following registers must be initialized:

Configuration: 01010000

  • SM0, SM1: 01
    • Mode 1 (8-bit UART)
  • SM2: 0
    • Disable multiprocessor communication (modes 2/3 only)
  • REN: 1
    • Enable serial reception
  • TB8: 0 - 9th data bit to be sent - not used for 8-bit UART
  • RB8: 0
    • 9th received data bit
    • Not used for 8-bit UART
  • TI: 0
    • Transmit interrupt flag
    • Set by hardware when byte has been transmitted
    • Must be cleared by software
  • RI: 0
    • Receive interrupt flag
    • Set by hardware when byte has been received
    • Must be cleared by software

Since UART uses Timer 1, we only need to configure the upper nibble.

Configuration: 0010XXXX

  • Timer 1 configuration
    • GATE: 0
      • Disable gating control
    • C/T#: 0
      • Select timer operation
    • M1, M0: 10
      • Select mode 2 (auto reload)
  • Timer 0 configuration
    • Don't care

Configuration: 01XX0XXX

  • TCON.7: 0
    • Timer 1 overflow flag
    • Set by hardware, should be cleared by software
  • TCON.6: 1
    • Timer 1 run control bit
    • Set by software to start timer
  • TCON.3: 0
    • Interrupt 1 edge flag
    • Set by hardware, should be cleared by software
  • TCON.2: X
    • Interrupt 1 type control bit - we are not using interrupts on timer 1.

$$ TH1 = 256 - \frac{K(f_{OSC})}{384f_{BAUD}} $$

  • For $f_{BAUD}=9600$, $K=1$, and $f_{OSC}=11.0592MHz$, $TH1=253$.
  • To receive a byte through UART, move the contents of the SBUF register to another register.
mov A, SBUF ; Store the received byte in the accumulator.
  • To transmit a byte through UART, move some data to the SBUF register.
mov SBUF, A ; Transmit the byte stored in the accmulator.
  • kb/8051_uart.txt
  • Last modified: 2024-04-30 04:03
  • by 127.0.0.1