8051 Serial Port. Crystal TXD. I/O Device RXD. Embedded Systems 1 5-1 8051 Peripherals



Similar documents
Flash Microcontroller. Memory Organization. Memory Organization

Serial Communications

CoE3DJ4 Digital Systems Design. Chapter 4: Timer operation

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC Microprocessor & Microcontroller Year/Sem : II/IV

USART and Asynchronous Communication

4 Character 5x7 LED Matrix Display

ARM Thumb Microcontrollers. Application Note. Software ISO 7816 I/O Line Implementation. Features. Introduction

Design and Implementation of Home Monitoring System Using RF Technology

AN108 IMPLEMENTING A REALTIME CLOCK. Relevant Devices. Introduction. Key Points. Overview

8051 hardware summary

Objectives. Basics of Serial Communication. Simplex vs Duplex. CMPE328 Microprocessors (Spring ) Serial Interfacing. By Dr.

Flash Microcontroller. Architectural Overview. Features. Block Diagram. Figure 1. Block Diagram of the AT89C core

TDA General description. 2. Features and benefits. Low power single card reader

8-bit Microcontroller with 2/4-Kbyte Flash AT89LP2052 AT89LP4052

a8251 Features General Description Programmable Communications Interface

Serial Communications

Microcomputer Components SAB 80515/SAB 80C515 8-Bit Single-Chip Microcontroller Family

RS-422/485 Multiport Serial PCI Card. RS-422/485 Multiport Serial PCI Card Installation Guide

AVR305: Half Duplex Compact Software UART. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

COMPUTER HARDWARE. Input- Output and Communication Memory Systems

1-Port R422/485 Serial PCIe Card

PART B QUESTIONS AND ANSWERS UNIT I

AVR317: Using the Master SPI Mode of the USART module. 8-bit Microcontrollers. Application Note. Features. Introduction

Introduction the Serial Communications Huang Sections 9.2, 10.2 SCI Block User Guide SPI Block User Guide

Hardware and Software Requirements

8-Bit Flash Microcontroller for Smart Cards. AT89SCXXXXA Summary. Features. Description. Complete datasheet available under NDA

INFORMATICA INDUSTRIALE

Microcomputer Protocol Implementation at Local Interconnect Network Georgi Krastev

80C51/87C51/80C52/87C52 80C51 8-bit microcontroller family 4 K/8 K OTP/ROM low voltage (2.7 V 5.5 V), low power, high speed (33 MHz), 128/256 B RAM

ENET-710. ENET Ethernet Module ENET-710 JAN / 06 FOUNDATION

8-bit Microcontroller with 12K Bytes Flash and 2K Bytes EEPROM AT89S8253

Software User Guide UG-461

LTM-1338B. Plus Communications Manual

Asynchronous Counters. Asynchronous Counters

DS87C520/DS83C520 EPROM/ROM High-Speed Micro

University of Portsmouth Faculty of Technology Department of Electronic and Computer Engineering. Content

Using Xbee in Serial Communication

DS1621 Digital Thermometer and Thermostat

USB TO SERIAL ADAPTER

AVR151: Setup and Use of the SPI. Introduction. Features. Atmel AVR 8-bit Microcontroller APPLICATION NOTE

SPI. Overview and Use of the PICmicro Serial Peripheral Interface. Getting Started: SPI

USB2.0 <=> I2C V4.4. Konverter Kabel und Box mit Galvanischetrennung

ETEC 2301 Programmable Logic Devices. Chapter 10 Counters. Shawnee State University Department of Industrial and Engineering Technologies

Using the HT46R46 I/O Ports to Implement Half-Duplex SPI Communication

CENTRONICS interface and Parallel Printer Port LPT

ALL-USB-RS422/485. User Manual. USB to Serial Converter RS422/485. ALLNET GmbH Computersysteme Alle Rechte vorbehalten

Appendix A. This Appendix includes the following supplemental material:

Microtronics technologies Mobile:

DS87C530/DS83C530. EPROM/ROM Micro with Real Time Clock PRELIMINARY FEATURES PACKAGE OUTLINE DALLAS DS87C530 DS83C530 DALLAS DS87C530 DS83C530

Implementing SPI Master and Slave Functionality Using the Z8 Encore! F083A

INFORMATICA INDUSTRIALE

Bluetooth Audio Data Transfer between Bluetooth chipset (PMB6752&PMB6625) and TriCore Host TC1920

UMBC. ISA is the oldest of all these and today s computers still have a ISA bus interface. in form of an ISA slot (connection) on the main board.

VMR6512 Hi-Fi Audio FM Transmitter Module

DECT Module UM-9802 Datasheet

Serial Communications / Protocol in AirTest Products

TERMINAL Debug Console Instrument

8-bit Microcontroller with 8K Bytes In-System Programmable Flash. AT89LP52 - Preliminary

2-Port RS232/422/485 Combo Serial PCI Card

Elettronica dei Sistemi Digitali Costantino Giaconia SERIAL I/O COMMON PROTOCOLS

DS1621 Digital Thermometer and Thermostat

Block 3 Size 0 KB 0 KB 16KB 32KB. Start Address N/A N/A F4000H F0000H. Start Address FA000H F8000H F8000H F8000H. Block 2 Size 8KB 16KB 16KB 16KB

8051 MICROCONTROLLER COURSE

Projector Control Command Reference Manual

Chapter 1 Lesson 3 Hardware Elements in the Embedded Systems Chapter-1L03: "Embedded Systems - ", Raj Kamal, Publs.: McGraw-Hill Education

Lab Experiment 1: The LPC 2148 Education Board

PFB366 Profibus-DP Gateway User Manual

Computer-System Architecture

Embedded Systems Design Course Applying the mbed microcontroller

Parallel IO. Serial IO. Parallel vs. Serial IO. simplex vs half-duplex vs full-duplex. Wires: Full Duplex. Wires: Simplex, Half-duplex.

The Programming Interface

Hello, and welcome to this presentation of the STM32L4 reset and clock controller.

NTE2053 Integrated Circuit 8 Bit MPU Compatible A/D Converter

Am186ER/Am188ER AMD Continues 16-bit Innovation

Microprocessor & Assembly Language

Develop a Dallas 1-Wire Master Using the Z8F1680 Series of MCUs

Section 17. UART HIGHLIGHTS UART. This section of the manual contains the following major topics:

8-bit Microcontroller with 2K/4K Bytes Flash AT89S2051 AT89S4051

Small Hardware Development and Prototyping Board for the SX28

TURBO PROGRAMMER USB, MMC, SIM DEVELOPMENT KIT

CONCEPT1 RS232 COMMUNICATION

Manual Serial PCI Cards

Interfacing Analog to Digital Data Converters

Embedded. Engineer s. Development. Tool (EEDT 5.0)

RL78/G12 APPLICATION NOTE. Serial Array Unit (CSI Master Communication) Introduction. Target Device. R01AN1369EJ0100 Rev Mar.

USB to serial chip CH340

Below is a diagram explaining the data packet and the timing related to the mouse clock while receiving a byte from the PS-2 mouse:

Using FPGAs to Design Gigabit Serial Backplanes. April 17, 2002

Example Programs for PLC Fatek equipped with FBs-CMGSM

HT1632C 32 8 &24 16 LED Driver

RN-131-PICTAIL & RN-171-PICTAIL Evaluation Boards

Keil C51 Cross Compiler

A DIY Hardware Packet Sniffer

UART IP Core Specification. Author: Jacob Gorban

Computer Performance. Topic 3. Contents. Prerequisite knowledge Before studying this topic you should be able to:

DS1104 R&D Controller Board

Section 14. Compare/Capture/PWM (CCP)

Experiment # 9. Clock generator circuits & Counters. Eng. Waleed Y. Mousa

Freescale Semiconductor, Inc. Product Brief Integrated Portable System Processor DragonBall ΤΜ

Remote PLC system using GSM network with application to home security system

Transcription:

8051 Serial Port The 8051 contains a UART Universal Asynchronous Receiver Transmitter The serial port is full-duplex It can transmit and receive simultaneously 2 Port 3 pins are used to provide the serial interface P3.0 is the receive pin (RXD) P3.1 is the transmit pin (TXD) Both synchronous and asynchronous transmission supported A synchronous transmission sends a clock signal with the data Adjustable baud rate and data frame size supported in asynchronous mode 8051 Crystal X1 X2 TXD RXD I/O Device Embedded Systems 1 5-1 8051 Peripherals

Asynchronous Data Transmission Data is transmitted in a frame consisting of a start bit, 8 or 9 data bits and a stop bit Start bit is always low Data is transmitted LSB first Stop bit is always high Data transmission/reception rate is controlled by baud rate generator clock Baud rate may be a division of the crystal frequency or programmed using a timer D0 D1 D2 D3 D4 D5 D6 D7 Line Idle Start Bit Stop Bit Embedded Systems 1 5-2 8051 Peripherals

Serial Port Modes Mode 0 Only synchronous mode Data transferred on RXD, clock on TXD Clock is fixed at 1/12 of the oscillator frequency Mode 1 Asynchronous mode 10-bit data frame (start bit, 8 data bits and a stop bit) Variable baud rate Stop bit is placed in RB8 bit of SCON register on reception of a frame Embedded Systems 1 5-3 8051 Peripherals

Serial Port Modes Mode 2 Asynchronous mode 11-bit data frame (start bit, 8 data bits, programmable 9 th bit and a stop bit) On transmission 9 th bit is TB8 bit of SCON On reception 9 th bit is placed in RB8 bit of SCON 9 th bit may be used for data or as a parity bit Baud rate may be 1/32 or 1/64 of oscillator frequency Mode 3 Same as Mode 2 but with a programmable baud rate Embedded Systems 1 5-4 8051 Peripherals

Data Transmission/Reception The register SBUF is used to hold both the transmit and receive serial port data To transmit data load the SBUF register MOV SBUF, source When transmission is complete the TI bit will be set in the SCON register When a data frame is received the RI bit in SCON is set high The received data may then be loaded from SBUF MOV destination, SBUF Data reception is double buffered Reception of a second data frame may commence before the previous data frame has been read The REN bit in SCON must be set to enable data reception Embedded Systems 1 5-5 8051 Peripherals

SCON Register Embedded Systems 1 5-6 8051 Peripherals

Configuring the Serial Port Configure the serial port mode in SCON Bits SM0 and SM1 determine the mode Set the REN bit if serial data reception is required Clear the RI and TI bits The RI flag is set when a character has been received by the serial port The TI flag is set after transmission of a character Both flags must be cleared by software Configure the serial port baud rates The baud rate is fixed for modes 0 and 2 For mode 0 the baud rate = f osc /12 For mode 2 the baud rate = 2 SMOD * f osc /64 SMOD is a bit in the PCON register (not bit addressable) For modes 1 and 3 the baud rate is configured by the timer 1 overflow rate Embedded Systems 1 5-7 8051 Peripherals

Baud Rate for Modes 1 and 3 Configure timer 1 for 8-bit auto-reload mode (timer mode 2) Upper 4 bits of TMOD register = 0010 Baud Rate = 2 32 SMOD x ( Timer 1Overflow Rate) Baud Rate = 2 32 SMOD x Oscillator Frequency 12x [ 256 TH1] Embedded Systems 1 5-8 8051 Peripherals

Common Baud Rates Embedded Systems 1 5-9 8051 Peripherals

Serial Program Example 1 ;Program to continually transmit the character A out the serial port ORG 0H MOV SCON, #40H ;serial port mode 1 ;configure timer 1 in auto-reload mode for 9600 baud MOV TMOD, #20H ;timer mode 2 MOV TH1, #0FDH ;reload value for 9600 baud MOV TL1, #0FDH SETB TR1 ;start timer LOOP: MOV SBUF, #'A' ;transmit character WAIT4TI: JNB TI, WAIT4TI ;wait for end of transmission CLR TI JMP LOOP ;re-transmit END Embedded Systems 1 5-10 8051 Peripherals

Serial Program Example 2 ; Program to echo characters received on serial port ORG 0H MOV SCON, #50H ;serial port mode 1, receiver enabled ORL PCON, #80H ;SMOD = 1, double baud rate ;configure timer 1 in auto-reload mode for 19200 baud MOV TMOD, #20H ;timer mode 2 MOV TH1, #0FDH ;reload value for 19200 baud with SMOD = 1 MOV TL1, #0FDH SETB TR1 ;start timer ;wait for a character to be received WAIT4RI: JNB RI, WAIT4RI ;wait for receive flag to go high CLR RI MOV A, SBUF ;read received character ;transmit received character MOV SBUF, A ;transmit character WAIT4TI: JNB TI, WAIT4TI ;wait for end of transmission CLR TI JMP WAIT4RI ;return and wait for next character END Embedded Systems 1 5-11 8051 Peripherals

Serial Program Example 3 ;Program to print the message "Hello" "Goodbye" on serial port ;A new line is placed between the strings MESSAGE EQU 100H ;address where string is stored ;define characters to move cursor to next line CR EQU 0DH LF EQU 0AH ORG 0H MOV SCON, #40H ;serial port mode 1 ;configure timer 1 in auto-reload mode for 9600 baud MOV TMOD, #20H ;timer mode 2 MOV TH1, #0FDH ;reload value for 9600 MOV TL1, #0FDH SETB TR1 ;start timer ;continued on next slide Embedded Systems 1 5-12 8051 Peripherals

Serial Program Example 3 (cont) ;loop to transmit message MOV DPTR, #MESSAGE TXMSG: CLR A MOVC A, @A+DPTR ;fetch character from string CJNE A, #'*', TRANSMIT ;check for end of message JMP DONE TRANSMIT: MOV SBUF, A ;transmit character WAIT4TI: JNB TI, WAIT4TI ;wait for end of transmission CLR TI INC DPTR ;point to next character JMP TXMSG DONE: ORG MESSAGE DB 'Hello' DB CR, LF DB 'Goodbye*' END ;string to be printed Embedded Systems 1 5-13 8051 Peripherals

Synchronous Serial Comms (Mode 0) The TXD pin is used to carry the clock Data is transmitted and received on the RXD pin (half duplex) Data Transmission Initiated by writing a character to the SBUF register Data shifted out RXD pin, LSB first (8 bits in total) 8 clocks shifted out TXD pin TI flag set after byte of data has been transmitted Data Reception Initiated by REN = 1 and RI = 0 8 clock pulses are outputted on TXD pin 1 bit of data shifted into RXD pin for each clock RI is set when 8 bits have been received into SBUF Embedded Systems 1 5-14 8051 Peripherals

Serial I/O Expansion A 74LS164 Serial In Parallel Out Shift Register may be used to expand the serial port to be used as 8 output pins A number of shift registers may be cascaded to increase the number of output pins gained Data Input Clock Reset 8 Parallel Outputs Embedded Systems 1 5-15 8051 Peripherals

Serial Output Pin Expansion P1.0 will clear the shift register outputs when brought low 8 output pins generated from 3 8051 pins Connect Q7 of 74LS164 to the data input of a second 74LS164 to generate 15 outputs from 3 8051 pins 8051 74LS164 P1.0 RXD TXD MR DIN CLK Q0 Q1 Q2 Q3 Q4 Q5 Q6 Q7 8 Output Ports Embedded Systems 1 5-16 8051 Peripherals

Serial Input Pin Expansion A 74LS165 Parallel In Serial Out Shift Register may be used to allow the 8051 serial port to provide additional input port pins A number of shift registers may be cascaded to increase the number of output pins gained Embedded Systems 1 5-17 8051 Peripherals

Serial Input Pin Expansion P1.0 will load the register parallel inputs when brought low 8 input pins generated from 3 8051 pins Connect data output pin of a second 74LS165 to the data input pin of another to generate 16 inputs from 3 8051 pins 74LS165 8 Input Ports QA QB QC QD QE QF QG QH INHIB OUT CLK LOAD 8051 RXD TXD P1.0 INPUT Embedded Systems 1 5-18 8051 Peripherals

Multi-Processor Communication Modes 2 and 3 can be configured to allow serial communication between a master 8051 and a number of slave 8051s The TXD pin of the master connects to the RXD pin of the slave 8051s In modes 2 and 3 a 9 th data bit is transmitted This bit is received into the RB8 bit of the SCON register If the SM2 bit of SCON is set, the RI flag will only be set when a serial frame is received with the 9 th bit = 1 This 9 th bit can be set/cleared to specify an address/data frame TXD Master 8051 RXD RXD RXD Slave 8051 #1 Slave 8051 #2.. Slave 8051 #n Embedded Systems 1 5-19 8051 Peripherals

Multi-Processor Communication On initialisation all slaves set the SM2 bit in the SCON register Each slave has a unique 8-bit address stored in non-volatile memory Master 8051 sends an address frame 9 th bit TB8 = 1 The address frame contains the 8-bit address of the destination slave All slaves will see the received address frame RI bit will be set because the 9 th bit RB8 = 1 Each slave checks the received address against it s own address The addressed slave will now clear it s SM2 bit in SCON to 0 The master will now send some data frames with the 9 th bit = 0 Only the addressed slave will see the data frames No RI flag will be set in the other slaves because the RB8 bit is 0 On completion of data reception the addressed slave will set the SM2 bit to await another address frame Embedded Systems 1 5-20 8051 Peripherals