8051_Interfacing Using RS232
This project shows 8051 interfacing using RS232. To simulate circuit in this project, initially activate Mixed Mode simulator from the Schematic Editor window. Simulation can be performed by selecting Run Transient analysis (Oscillograph) or Analysis -> Transient Analysis from Simulation menu.
The circuit has two modules, the transmitter and the receiver. Both the transmitter and receiver contains 8051 chips and MAX 232. The 8051 microcontroller sends and receives data through RS232 interface. RS232 uses MAX232 as a level converter, since standard serial interfacing of microcontroller (TTL) with RS232C Standard device, requires TTL to RS232 Level converter.
In this circuit, Port P2 (P2.0 - P2.7) of 8051 chip in the transmitter is set as the input port. The TxD pin of 8051 transmits the serial data to the receiver's RxD pin using RS232 interface and the data is output through port P2 (P2.0 -P2.7) of 8051 in the receiver ,which is set as the output port.
The source code is written Assembly language and can be viewed from the
code editor window.
The program is as shown below:
Transmitter Module:
MOV TMOD,#0x20 ;TIMER1,MODE 2,AUTO RELOAD
MOV TH1,#-6 ;4800 BAUD RATE
MOV SCON,#0x50 ;8-BIT,1 STOP,REN ENABLED
SETB TR1 ;START TIMER 1
AGAIN:
MOV SBUF,P2 ;P2 TO BE TRANSFERRED
HERE:
JNB TI,HERE ;WAIT FOR THE LAST BIT
Receiver Module
MOV TMOD,#0x20 ;TIMER1,MODE2
MOV TH1,#-6 ;4800 BAUD
MOV SCON,#0x50 ;8-BIT,1 STOP,REN ENABLED
SETB TR1 ;START TIMER1
HERE:
JNB RI,HERE ;WAIT FOR CHAR TO COME
MOV A,SBUF ;SAVE INCOMING BYTE IN A
MOV P2,A ;SEND TO PORT1
The source code in the
code editor window
has to be
compiled
after making any modifications
(editing).
Also the code can be
debugged
during
simulation.