Source: http://www.edsim51.com/8051Notes/8051/serial.html Serial Port Source: http://www.edsim51.com/8051Notes/8051/serial.html.

Slides:



Advertisements
Similar presentations
Autumn 2012C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh Department of Electronic Engineering.
Advertisements

ECT 357 Ch 18 UART. Today’s Quote: Be careful that your marriage doesn’t become a duel instead of a duet. Be careful that your marriage doesn’t become.
The 8051 Microcontroller Chapter 5 SERIAL PORT OPERATION.
Hierarchy of I/O Control Devices
7-1 Digital Serial Input/Output Two basic approaches  Synchronous shared common clock signal all devices synchronised with the shared clock signal data.
Chapter 6 Serial Communications Objectives Introduce the RS232 standard and position it within the crowded field of serial communications standards. Configure.
Embedded Systems UNIT 3. Pin Details of 8051 Pins 1-8: Port 1 Each of these pins can be configured as an input or an output. Pin 9: The positive voltage.
Lecture 10 Serial Communication.
Chapter 6 Serial Communications Objectives Introduce the RS232 standard and position it within the crowded field of serial communications standards. Configure.
Microcontroller 8051.
The 8051 Microcontroller and Embedded Systems
1 Chapter 4 Timer Operation (I. Scott MacKenzie).
CoE3DJ4 Digital Systems Design Chapter 4: Timer operation.
CoE3DJ4 Digital Systems Design Hardware summary. Microprocessors vs. Microcontrollers Microprocessors are single-chip CPU used in microcomputers Microcontrollers.
Lecture Set 9 MCS-51 Serial Port.
CHAPTER SERIAL PORT PROGRAMMING. Basics of Serial Communication Computers transfer data in two ways: ◦ Parallel  Often 8 or more lines (wire conductors)
Serial Communication Lec note 9.
1. Registers Used in Timer/Counter  TH0, TL0, TH1, TL1  TMOD (Timer mode register)  TCON (Timer control register) 2.
Advanced Microprocessor1 I/O Interface Programmable Interval Timer: 8254 Three independent 16-bit programmable counters (timers). Each capable in counting.
Example. SBUF Register SCON Register(1) SCON Register(2)
MCS51 - lecture 4. Lecture 3 1/27 Serial ports MCS51 Standard SIO Some extensions and modifications.
8051 Micro controller. Architecture of 8051 Features of 8051.
Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,
Serial Communications Interface Module Slide #1 of 19 MC68HC908GP20 Training PURPOSE -To explain how to configure and use the Serial Communications Interface.
8051SERIAL PORT PROGRAMMING
Tiva C TM4C123GH6PM UART Embedded Systems ECE 4437 Fall 2015 Team 2:
Serial Communications
The HCS12 SCI Subsystem A HCS12 device may have one or two serial communication interface. These two SCI interfaces are referred to as SCI0 and SCI1. The.
Serial I/O Port.
Chapter 6 Serial Communications
Serial mode of data transfer
Assembly Language * * * * * * * 8051 Timer
The 8085 Microprocessor Architecture
8051 Timers Timers are the peripherals of the 8051 Microcontroller.
Timer Source: under
The 8085 Microprocessor Architecture
Serial I/O and Data Communication.
SERIAL PORT PROGRAMMING
Interrupt Source: under
Introduction to Micro Controllers & Embedded System Design Interrupt
UNIT 5 TIMRERS/COUNTERS
Introduction to Micro Controllers & Embedded System Design I/O Processing and Serial Port Operation Department of Electrical & Computer Engineering Missouri.
An Introduction to Microprocessor Architecture using intel 8085 as a classic processor
Timer Operations and Programming
EMT 348: Microcontroller Timer/counter
Source: Serial Port Source:
Memory Organisation Source: under
Interrupt.
Introduction to Micro Controllers & Embedded System Design Timer Operation Department of Electrical & Computer Engineering Missouri University of Science.
Timer.
Serial Communication Interface
UART Protocol Chapter 11 Sepehr Naimi
8051 Microcontroller.
Timer Source: under
Interrupt Source: under
Interrupt.
JANAKIRAMAN E G S PILLAY ARTS AND SCIENCE COLLAGE NAGAPATTINAM DEPARTMENT OF PHYSICS.
Interrupt Source: under
INTRODUCTION TO 8051, A 8-BIT MICROCONTROLLER
The 8085 Microprocessor Architecture
Source: Serial Port Source:
Timer Source: under
CHAPTER SERIAL PORT PROGRAMMING. Basics of Serial Communication Computers transfer data in two ways: ◦ Parallel  Often 8 or more lines (wire.
Compiled by Dr. N.Shanmugasundaram, HOD, ECE Dept, SECE.
EUSART Serial Communication.
Prof Afonso Ferreira Miguel
Source: Serial Port Source:
8051SERIAL PORT PROGRAMMING
Serial Communications
Introduction Communication Modes Transmission Modes
Presentation transcript:

Source: http://www.edsim51.com/8051Notes/8051/serial.html Serial Port Source: http://www.edsim51.com/8051Notes/8051/serial.html

Serial communication Asynchronous serial communication Tx Clk Gnd Rx Tx Gnd Rx Tx Rx Clk Gnd Tx Rx Gnd

Transmission modes Simplex Half-duplex Or Full-duplex Receiver Transmitter Transmitter/Receiver Transmitter/Receiver Transmitter/Receiver

Serial port in 8051 8051 Properties of 8051 serial port: *) Full duplex (i.e., it can transmit and receive data at the same time.) *) The data rate (baud rate, bit/sec) is controller by timer 1. *)

Serial Control Register (SCON) Bit Symbol Address Description 7 SM0 9FH serial port mode bit 0 6 SM1 9EH serial port mode bit 1 5 SM2 9DH serial port mode bit 2 - will be dealt with at a later date 4 REN 9CH receiver enable - this bit must be set to receive data 3 TB8 9BH transmit bit 8 - this is the ninth bit transmitted in the 9-bit UART modes 2 RB8 9AH receive bit 8 - this is the ninth bit received in the 9-bit UART modes 1 TI 99H transmit interrupt flag - this bit is set by hardware when an entire byte has been transmitted - it must be cleared by software RI 98H receive interrupt flag - this bit is set by hardware when an entire byte has been received - it must be cleared by software

Serial port modes SM0 SM1 Mode Description Baud Rate shift register shift register fixed - system clock frequency divided by 12 (machine cycle frequency) 1 8-bit UART variable - set by timer 1 2 9-bit UART fixed - system clock frequency divided by 12 or divided by 64 3 9-bit variable baud rate UART

Mode 1 --- 8-bit UART UART (Universal Asynchronous Receive/Transmit) This is asynchronous communication, therefore no clock signal is sent with the data. Instead, a single start bit (always logic 0) and a single stop bit (always logic 1) encapsulate the data (8 bits). Therefore, in total, ten bits are sent per byte of data.

Baud rate If the designer of an 8051 system is required to transmit data from the serial port to a device (eg; a monitor) he/she needs to discover what baud rate the device's serial port operates at and configure the 8051 serial port to operate at the same baud rate. In mode 1, the baud rate is determined by the overflow of timer 1. By default, the baud rate is equal to the timer 1 overflow frequency divided by 32.

How to control the baud rate? To configure the port to a specific baud rate we therefore need to configure timer 1 to give us an overflow at an appropriate interval. This can be achieved by setting up timer 1 as an 8-bit auto-reload interval timer. Then, if we put the correct value into TH1 the overflow signal will have the appropriate frequency to give us the baud rate we desire. The formula that determines the relationship between TH1 and baud rate: TH1 = 256 - ((system frequency / (12 * 32)) / baud) For example, to achieve a baud rate of 1200 using a system clock frequency of 12MHz and with SMOD = 0: TH1 = 256 - ((system frequency / (12 * 32)) / baud) TH1 = 256 - ((12MHz / (12 * 32)) / 1200) TH1 = 256 - 26.04 TH1 = 256 - 26 (rounding down => error of 0.04) TH1 = 230

The code below shows how to configure both timer 1 and the serial port to transmit data at 1200 baud. CLR SM0 SETB SM1 ;clear SM0 and set SM1 to put the serial port in mode 1 MOV TMOD, #20H ;put timer 1 in mode 2 interval timing MOV TH1, #230 ;put the reload value in TH1 - this results in a baud rate of 1200 SETB TR1 ;start timer 1 MOV SBUF, A ;send data in the accumulator down the serial line Once the timer is started the programmer does not need to do anything else with it. The serial port itself monitors (through hardware) the overflow signal and every 32nd overflow (16 if SMOD is set) a bit is transmitted.

Various standard baud rates The table shows some standard baud rates together with the required TH1 value to achieve this baud rate with the 8051 serial port in mode 1.

8051 instructions for transmitting and receiving data MOV SBUF, #45H MOV A, SBUF To transmit data along the serial line you simply write to the serial buffer and to access data received on the serial port you simply read data from the serial buffer. For example MOV SBUF, #45H ; to send the byte 45H down the serial line MOV A, SBUF ; to take data received by the serial port and puts it in the accumulator.

How do we know when the complete data byte has been sent? MOV SBUF, #23H MOV SBUF, #56H If the second byte is sent to SBUF immediately after the first by is sent, the second byte may be overwritten before it was completely shifted down the line MOV SBUF, #23H; JNB TI, $ CLR TI MOV SBUF, #56H; “JNB TI, $” is to wait for the byte to be transmitted down the line. The transmit interrupt flag (TI) is set by hardware once an entire byte has been transmitted. The flag TI must be clear by software.

How do we know when data has been received? JNB RI, $ CLR RI MOV A, SBUF “JNB RI, $” is to wait for an entire byte to be received The receive interrupt flag (RI) is set by hardware when an entire byte is received by the serial port. RI must be cleared by software.

Parity Instructions in program example 8 MOV C, P MOV ACC.7, C Purpose To make the Acc even parity Q1 How does the p flag change? (What causes it to change? To what does it change?) The 8051 maintains even parity with the accumulator, ie; the number of ones in the accumulator together with the parity bit (in the program status word) is always even. Q2 How can we make the Acc odd parity?

Bit-addressability of SFR SM0, SM1 bits in SCON register SMOD bit in PCON register Example instructions CLR SM0 SETB SM1 MOV A, PCON SETB ACC.7 MOV PCON, A Implication The bits in SCON is bit-addressable. The bits in PCON is NOT bit-addressable.

The ASCII codes go from 0 to 7FH The ASCII codes go from 0 to 7FH. Therefore, only seven bits are needed to code the basic ASCII characters. This leaves the 8th bit free - we can use this spare bit as a parity bit

The receiver must be able to count the number of ones in the received data. If an 8051 was being used to receive even parity ASCII data on the serial line it could test the data validity as shown below: waitForByte: JNB RI, $      ;wait for a byte to be received CLR RI MOV A, SBUF    ;move the received byte to the accumulator JB P, waitForByte   ;if the parity bit is set, data transmission error => ignore data CLR ACC.7      ;valid data - therefore clear the parity bit .