User: alciro    User
 Original    Translate to:  Deutsch  English  Français  中文  
 

Microcontroladores 8051

7.2.3. Example UART configuration

Suppose you have to configure the UART to transmit data in mode 1 (8-bit UART) with a speed of 9600 baud, 1 stop bit. Have to follow the following steps:

Configuration 1, TIMER 1

The TMOD register is set to auto reload mode and timer.

MSB LSB
GATE C / T M1 M0 GATE C / T M1 M0
0 0 1 0 x x x x
Timer 1 Timer 0

  • GATE = 0 Internal Control
  • C / T = 0 Mode Timer
  • M1, M0 = 1, 0 8-bit Counter Auto-Recharge

In the record set TCOM flag state control of TR1. TR1 bit starts the timer and allows the UART to work, so it is best to enable this bit at the end of the configuration used as a control to start or stop communications.

2 ° Set the communication speed.

According to the frequency of the microcontroller sets the value of counters TL1 and TH1 registers. Looking at the communication speed table in paragraph 7.1, for 9600 baud with a crystal of 11.0592 MHz counter value is FDH.

3 º UART Settings

In SCON register is set UART mode 1 enables the reception with REN = 1, sets the state flags of TB8, Rb8, 0 and TI interrupt flan, RI to 0.

MSB LSB
SM0 SM1 SM2 REN TB8 Rb8 IT RI
0 1 0 1 0 0 0 0

  • SM0, SM1, SM2 = 0, 1, 0 Mode 1 8-bit UART
  • REM = 1 Enables reception
  • TB8, Rb8 = 0, 0 not used in this way
  • TI = 0 transmission Flag
  • RI = 0 Receive Flag

Configuration example in assembler.

;-----------------------------------
; Iniciar el puerto serie
;-----------------------------------
InitSerial: ORL TMOD,#00100000B ; Timer 1 en modo 2 (auto recarga)
MOV TL1,#0FDH ; Velocidad de 9600 Bauds
MOV TH1,#0FDH
MOV SCOM,#50H ; Configuración de la UART en modo 2
SETB TR1 ; Arrancar el Timer1 y la UART
RET

C. Configuration Example

 //---------------------------------------
/ / Start the serial port
//---------------------------------------
InitSerial void (void) {
	TMOD | = 0x20 / / Timer 1 in mode 2 (auto reload)
	TL1 = 0xFD / / 9600 baud rate
	TH1 = 0xFD;
	SCON = 0x50, / / Setup UART mode 2
	TR1 = 1, / / Start Timer1 and UART

} 
Loading
copyright © 2007-2024  www.alciro.org  All rights reserved.         
Share |