8051 Serial Communication
8051 Serial Communication
Introduction
Computer stores data in two ways: serial and parallel. In parallel data transfer:
8 or more wire conductors are used Distance: a few feet away Example: printer and hard disk
Cont..
Serial data communication use two methods:
Asynchoronous (transfer a single byte of data) Synchronous (transfer a block of data)
Simplex transmission: one way communication such as computer only send data to printer.
RS232 standars
To allow compatability among data communication equipment made by various manufacturer, an interfacing standard called RS232 was set by the Electronic Industries Association in 1960. The standard was set before the advent of the TTL logic, its input and output voltage are not TTL compatible. In RS232, a 1 is represented by -3 to -25V while 0 bit is +3 to +25V. Voltage converter must be used such as MAX232 IC
SBUF register
SBUF is an 8 bit register for serial communication in 8051. For data to be transfered, it must be placed in SBUF register. Example:
MOV SBUF, #D MOV SBUF, A MOV A, SBUF
The moment a byte is written into SBUF, it is framed with the start and stop bit and tranfered serially. When the bits are received, 8051 deframed it by eliminating the stop bit and start bit and placing it in SBUF register.
SCON register
is an 8 bit register used to program the start bit, stop bit and data bits of data framong. SM0 SM1 SM2 REN TB8 RB8 TI RI SM0 =0 SM1= 0 Serial mod 0 SM0=0 SM1=1 serial mod 1, 8 bit data, 1 stop bit, 1 start bit SM0=1 SM1=0 mode 2 SM0=1 SM1=1 mode 3
Mode 1 is our interest
example
MOV TMOD, #20H MOV TH1, #-6 MOV SCON, #50H SETB TR1 AGAIN: MOV SBUF, #A HERE: JNB T1, HERE CLR TI SJMP AGAIN
Cont..
SM2: is not use, is set to 0. REN: receive enable, must be set to 1, 0 = disable TB8: used for mode 2 and mode 3. not used in our application. RB8: is used in mode 2 and 3 TI: transmit interrupt. When 8051 finished the transfer of the 8 bit character, it raise the TI flag to indicate that it is ready to transfer next data. RI: receive interrupt: after 8051 receive data, the RI is raised to indicate that the data should be pick up.
SMOD -- -- --- GF1 GF0 PD IDL SMOD must be set to 1. SMOD is not bit addressable
MOV A, PCON SETB ACC.7 MOV PCON,A