This blog post summarize how to interface UART with 8051 using assembly programming
PS-TRAINER-8051 trainer kit is proposed to smooth the progress of learning and developing designs of MCU from Intel and NXP. It has the facility to connect PC’s 101/104 Keyboard, to enter user programs in Assembly languages. Serial communication achieved using 8051. It also supports C & assembly language in standalone kit (P89V51RD2). It’s designed as to facilitate On-board Programmer for NXP 8051 MCU through ISP on serial port.
UART
UART (Universal Asynchronous Receiver Transmitter) are one of the basic interfaces which provide a cost effective simple and reliable communication between one controller to another controller or between a controller and PC.
Rs-232 level converter
Usually all the digital ICs work on TTL or CMOS voltage levels which cannot be used to communicate over RS-232 protocol. So a voltage or level converter is needed which can convert TTL to RS232 and RS232 to TTL voltage levels. The most commonly used RS-232 level converter is MAX232.
This IC includes charge pump which can generate RS232 voltage levels (-10V and +10V) from 5V power supply. It also includes two receiver and two transmitters and is capable of full-duplex UART/USART communication.
- RS-232 communication enables point-to-point data transfer. It is commonly used in data acquisition applications, for the transfer of data between the microcontroller and a PC.
- The voltage levels of a microcontroller and PC are not directly compatible with those of RS-232, a level transition buffer such as MAX232 be used.
Interface UART
Interface UART with 8051
We now want to display a text in PC from 8051 Trainer Board by using UART module. In 8051 Trainer Board contains two serial interfaces that are UART0 & UART1. Here we are using UART0. The Transmitter pins send the data into PC and the receiver pin receives the data from PC. The PC and microcontroller speed are denoted by using baud rate. When the baud rates of both PC and Microcontroller are same, then only the data transmit and receive correctly otherwise not.
Pin assignment with 8051
Circuit diagram to interface UART with 8051
Assembly program to interface UART with 8051
MEMORY ADDRESS | OPCODE | MNEMONICS |
8500 | 75,89,21 | MOV TMOD,#21 |
8503 | 75 8D FD | MOV TH1,#FD |
8506 | 75 98 52 | MOV SCON,#52 |
8509 | D2 8E | SETB TR1 |
850B | 74 41 | H:MOV A,#41 |
850D | B1 11 | ACALL TXMT |
850F | 80 FA | SJMP H |
8511 | 30 99 FD | TXMT:JNB TI,TXMT |
8514 | C2 99 | CLR TI |
8516 | F5 99 | MOV SBUF,A |
8518 | 22 | RET |