CoE3DJ4 Digital Systems Design. Chapter 5: Serial Port Operation

Similar documents
MCS-51 Serial Port A T 8 9 C 5 2 1

8051 Serial Communication

8051 Serial Port. EE4380 Fall02 Class 10. Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas

8051 Timers and Serial Port

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: Serial Port Programming in Assembly Module No: CS/ES/12 Quadrant 1 e-text

Serial I-O for Dinesh K. Sharma Electrical Engineering Department I.I.T. Bombay Mumbai (version 14/10/07)

Serial communication

MICROPROCESSORS AND MICROCONTROLLERS MATERIAL. Features of 8051:

Interrupt Programming: Interrupts vs. Polling Method:

ELEG3923 Microprocessor Ch.10 Serial Port Programming

SRL0 Serial Port Unit

Mod-3: Interrupts,Timer operation,serial communication 1


CoE3DJ4 Digital Systems Design. Chapter 6: Interrupts

Experiment# 8: Photo-Interrupter Control

Timer-1 can be run using the internal clock, fosc/12 (timer mode) or from any external source via pin T1 (P3.5) (Counter mode).

8051SERIAL PORT PROGRAMMING

The Timers/Counters The Serial Interface The Interrupt System Reset P0.0-P0.7 P2.0-P2.7. Port 2 Drivers. Port 2 Latch

ISSI. IS89C51 CMOS SINGLE CHIP 8-BIT MICROCONTROLLER with 4-Kbytes of FLASH ISSI IS89C51 NOVEMBER 1998 FEATURES GENERAL DESCRIPTION

WINTER 14 EXAMINATION

Rev. No. History Issue Date Remark

EE6502- MICROPROCESSOR AND MICROCONTROLLER

Chapter C2051 Architecture and Serial Communication Link

UNIT IV MICROCONTROLLER

Chapter 6 Interrupts. (I. Scott Mackenzie) By: Masud-ul-Hasan

Microcontroller and Embedded Systems:

CS 320. Computer Architecture Core Architecture

Lecture 10. Serial Communication

8051 MICROCONTROLLER

Embedded Controller Programming

The Final Word on 8051 Microcontroller

8XC51RA RB RC Hardware Description

The 8051 microcontroller has two 16-bit timers/counters called T0 and T1.

Chapter 09. Programming in Assembly

Vidyalankar T.E. Sem. V [ETRX] Microprocessors and Microcontrollers I Prelim Question Paper Solution

Migrating from the 8XC251Sx to the 8XC251Tx

VRS540-4kB Flash, 128B RAM, 25~40MHz, 8-Bit MCU

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: 8051 Architecture Module No: CS/ES/5 Quadrant 1 e-text

Understanding the basic building blocks of a microcontroller device in general. Knows the terminologies like embedded and external memory devices,

EEE3410 Microcontroller Applications Department of Electrical Engineering Lecture 4 The 8051 Architecture

Microcontroller and Applications

INTEGRATED CIRCUITS DATA SHEET. P89C738; P89C739 8-bit microcontrollers Dec 15. Product specification File under Integrated Circuits, IC20

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

Department of EIE / Pondicherry Engineering College. Timer/Counters. Department of EIE / Pondicherry Engineering College 1

VRS550-8kB Flash, 256B RAM, 25~40MHz, 8-Bit MCU VRS560-16kB Flash, 256B RAM, 40MHz, 8-Bit MCU

8-bit Microcontroller with 8K Bytes In-System Programmable Flash AT89S52

ELEG3923 Microprocessor Ch.9 Timer Programming

CHAPTER TIMER PROGRAMMING

CPEG300 Embedded System Design. Lecture 8 Timer

8051 Microcontroller

APPLICATION NOTE 600 Ultra High Speed Microcontroller Hardware Enhances Serial Port Capability

EC Microprocessor and Microcontroller

How to use the PSoC based 16C450 Replacement

CPEG300 Embedded System Design. Lecture 6 Interrupt System

Fig.12.5 Serial Data Line during Serial Communication

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) Summer 2016 EXAMINATIONS.

THE 8051 MICROCONTROLLER Simple comparison: Pentium vs. 8051

8051 microcontrollers

SUMMER 13 EXAMINATION

Q.1. A) Attempt any THREE of the following:

MODEL ANSWER SUMMER 17 EXAMINATION Subject Title: Microcontroller Subject Code:

DATA SHEET. P80CL31; P80CL51 Low voltage 8-bit microcontrollers with UART INTEGRATED CIRCUITS Apr 15

8051 Microcontroller

UNIT 5. Microcontrollers. Syllabus

ENE 334 Microprocessors

Software Serial Port Implemented with the PCA

Module I. Microcontroller can be classified on the basis of their bits processed like 8bit MC, 16bit MC.

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: Serial Port Communication Module No: CS/ES/11 Quadrant 1 e-text

Timers and interrupts


8051 Microcontroller memory Organization and its Applications

MAHALAKSHMI ENGINEERING COLLEGE TIRUCHIRAPALLI UNIT- IV

Introduction To MCS-51

8051 Microcontrollers

Serial Communication Prof. James L. Frankel Harvard University. Version of 2:30 PM 6-Oct-2015 Copyright 2015 James L. Frankel. All rights reserved.

Q 1 a) Attempt any THREE of the following: 12 TMOD.7 TMOD.6 TMOD.5 TMOD.4 TMOD.3 TMOD.2 TMOD.1 TMOD.0 GATE C/T M1 M0 GATE C/T M1 M0

Fig 1. Block diagram of a microcomputer

Maxim > Design Support > Technical Documents > Application Notes > Microcontrollers > APP 4465

3. (a) Explain the steps involved in the Interfacing of an I/O device (b) Explain various methods of interfacing of I/O devices.

8051 Timers. Class 7 EE4380 Fall Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas

Hello, and welcome to this presentation of the STM32 Low Power Universal Asynchronous Receiver/Transmitter interface. It covers the main features of

Hardware Setups for Communication with a DS1267

Department of Electronics and Instrumentation Engineering Question Bank

Interrupts. EE4380 Fall 2001 Class 9. Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas

Hello, and welcome to this presentation of the STM32 Universal Synchronous/Asynchronous Receiver/Transmitter Interface. It covers the main features

INTERRUPTS PROGRAMMING

MCS -51 Programmer s Guide and Instruction Set

The Microcontroller. Lecture Set 3. Major Microcontroller Families. Example Microcontroller Families Cont. Example Microcontroller Families

Sender Receiver Sender

MODEL ANSWER SUBJECT- MICROCONTROLLER(12187) CLASS-EJ5E CLASS TEST-02 Q1.)Attempt any THREE of the following.

W77E058A Data Sheet 8-BIT MICROCONTROLLER. Table of Contents-

80C51 family programmer s guide and instruction set. 80C51 Family. PROGRAMMER S GUIDE AND INSTRUCTION SET Memory Organization. Philips Semiconductors

C51 Family. C51 Family Programmer s Guide and Instruction Set. Summary

CHAPTER 11 INTERRUPTS PROGRAMMING

UNIT MICROCONTROLLER AND ITS PROGRAMMING

P89V52X2. 1. General description. 2. Features. 8-bit 80C51 low power 8 kb flash microcontroller with 256 B RAM, 192 B data EEPROM

Legacy documentation refer to the Altium Wiki for current information. TSK51x MCU

8051 MICROCONTROLLER

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

8051 Peripherals. On-Chip Memory Timers Serial Port Interrupts. Computer Engineering Timers

Transcription:

CoE3DJ4 Digital Systems Design Chapter 5: Serial Port Operation

Serial port 8051 includes an on-chip serial port Hardware access to the port is through TXD and RXD (Port 3 bits 1 and 0) Serial port is full duplex (simultaneous transmission and reception) Note: In Mode 0, it is half duplex Serial port has a receiving buffering allowing one character to be received and held in a buffer while a second character is received Two registers SBUF and SCON provide access to the serial port Serial buffer (SBUF) is in fact two buffers one write only for transmission and one read-only for receiving

The SCON Register MSB LSB SM0 SM1 SM2 REN TB8 RB8 TI RI Bit SCON.7 SCON.6 SCON.5 SCON.4 SCON.3 SCON.2 SCON.1 SCON.0 Name SM0 SM1 SM2 REN TB8 RB8 TI RI Description Serial Port Mode bit 0 Serial Port Mode bit 1 Multiprocessor Communication Enable Receive Enable Set to enable reception. CLR to disable reception. Bit 8 of message to transmit Used to transmit optional parity bit Bit 8 of received message Receives optional parity bit Transmit Interrupt Flag Set when Byte in SBUF is completely transmitted. Receive Interrupt Flag Set when a valid byte is received into SBUF

The SCON Register SMO, SM1, SM2 Serial Mode Control Bits SM0 SM1 Mode Baud Rate Description 0 0 0 f osc /12 8-bit shift register 0 1 1 variable 8-bit UART 1 0 2 f osc /32 or f osc /64 9-bit UART 1 1 3 variable 9-bit UART SM2 Multiprocessor Mode Control Bit 1 = Multi-processor mode 0 = Normal mode REN Receiver Enable Bit 1 = Receive Enable 0 = Receive Disabled TB8 9th Transmit Bit Enabled only in modes 2 and 3 RB8 9th Bit Received Used in modes 2 and 3 RI, TI Serial Interrupts RI is set to indicate receipt of a serial word and TI is set to indicate completion of a serial transmission.

Modes Mode of operation of serial port is set by writing to SCON. Serial port has four modes of operation selected by writing 1s and 0s to SM0 and SM1 bits in SCON Mode 0 puts the serial port in 8-bit shift register mode Serial data enter and exit through RXD. TXD serves as clock (outputs shift clock) Eight bits are transmitted or received with the LSB first Baud rate is fixed at 1/12 th of on-chip oscillator Transmission is initiated by any instruction that writes data to SBUF Data are shifted out on RXD line with clock pulses sent out the TXD

Mode 0 Each transmitted bit is valid on RXD pin for one machine cycle Reception is initiated as soon as REN bit is set to 1 and the receive interrupt (RI) bit is cleared. Usually, REN is set at the beginning of the program to initialize the serial port, then RI is cleared to start a data input operation. As soon as RI is cleared, the shift clock will be produced on the TxD pin. At the beginning of the following machine cycle, data will be clocked in from the RxD line. The clocking occurs on the rising edge of the TxD line. After the 8 th clocking cycle, the data is copied to SBUF and the RI bit is set. It is up to the attached circuitry to provide data on RXD line synchronized by the clock signal on TXD.

Mode 1 Mode 1 is an 8-bit UART with variable baud rate UART (universal asynchronous receiver/transmitter): a device that receives and transmits serial data with each data character preceded by a start bit (low) and followed by a stop bit (high) In mode 1, 10 bit are transmitted on TXD or received on RXD These consist of a start bit (always 0), eight data bits (LSB first) and stop bit (always 1) For receive operation, stop bit goes into RB8 in SCON Baud rate is set by timer 1.

Framing An 8-bit message needs to be framed so that the receiver can detect correctly its beginning and end. Standard framing: Start bit always 0, Stop bit always 1. Optional parity bit The message now becomes: Start bit (1 0), LSB,, MSB, <parity bit>, Stop bit (1), Start 0 1 2 3 4 5 6 7 <P> Stop <St> Time

Mode 1 Transmission is initiated by writing to SBUF Shifted data are outputted on the TXD line beginning with start bit and followed by eight bit data bits then stop bit The transmit interrupt (TI) flag is set as soon as the stop bit appears on TxD.

Mode 1 Reception is initiated by a 1 to 0 transition on RXD (assuming REN is 1). The start bit is skipped and eight data bits are clocked into the serial port shift register When all eight bits have been clocked in, the following occur: 1. Ninth bit (stop bit) is clocked into RB8 in SCON 2. SBUF is loaded with eight data bits 3. Receiver interrupt flag (RI) is set These only occur if following conditions exist: 1. RI=0 (ensures software has read the previous character) 2. SM2=0 (applies in multiprocessor communications)

Modes 2 & 3 Mode 2: 9-bit UART with fixed baud rate Eleven bits are transmitted or received: a start bit, eight data bits, a programmable ninth bit and a stop bit On transmission, the ninth bit is whatever has been put in TB8 in SCON On reception, the ninth bit received is placed in RB8 Baud rate in mode 2 is either1/32 nd or 1/64 th on-chip oscillator Mode 3: 9-bit UART with variable baud rate Mode 3 is same as Mode 2 except baud rate is programmable and provided by Timer 1

Initialization and Accessing Receiver enable bit REN in SCON must be set by software to enable reception of characters This is done at the beginning of a program when port is initialized SETB REN MOV SCON, #xxx1xxxxb Ninth data bit transmitted in modes 2 and 3 must be loaded into TB8 by software Ninth bit received is placed in RB8

Initialization and Accessing A common use for ninth data bit is to add parity to a character P bit in PSW is set or cleared every machine cycle to establish even parity with bits in accumulator Example: transmitting eight bits in accumulator with an even parity added in ninth bit: MOV C,P MOV TB8,C MOV SBUF,A Odd parity MOV C,P CPL C MOV TB8,C MOV SBUF, A

Initialization and Accessing RI and TI in SCON play an important role in 8051 serial communications Both bits are set by hardware but must be cleared by software Typically RI is set at the end of character reception and indicates receive buffer full If software wishes to input a character from the device connected to serial port, it must wait until RI is set, then clear RI and read character from SBUF WAIT: JNB RI, WAIT CLR RI MOV A, SBUF

Initialization and Accessing TI is set at the end of character transmission and indicates transmit buffer empty. If software wishes to send a character to the device connected to the serial port, it must first check that the serial port is ready. WAIT: JNB TI, WAIT CLR TI MOV SBUF, A

Baud rate Baud rate is fixed in modes 0 and 2 In mode 0 it is always on-chip oscillator frequency divided by 12 Default baud rate for mode 2 (after system reset) is oscillator frequency divided by 64 Bit 7 of PCON is the SMOD bit Setting SMOD doubles the baud rate in mode 2 to 1/32 nd of oscillator frequency Since PCON is not bit-addressable, setting SMOD has to be done using the following approach: MOV A, PCON SETB ACC.7 MOV PCON,A

Baud rate The baud rates in Modes 1 and 3 are determined by Timer1overflow rate Since timer operates at a relatively high frequency, it is further divided by 32 (or 16 if SMOD=1) before driving the serial port The usual technique for baud rate generation is to initialize TMOD for 8-bit auto-reload mode (mode 3) and put the correct reload value in TH1 to yield proper overflow rate for baud rate

Example: 1200 baud operation: Serial port BAUD RATE=TIMER 1 OVERFLOW RATE / 32 TIMER 1 OVERFLOW RATE =1200*32=38.4kHz If a 12 MHz oscillator is used, timer 1 is clocked at 1 MHZ (1000 khz). Since the timer must overflow at a rate of 38.4 khz and the timer is clocked at 1000 khz, an overflow is required every 1000/38.4=26.04 clocks. Since timer counts up and overflows on FF to 00 transition, 26 counts less than 0 is the required reload value for TH1: MOV TH1, #-26 Table 5-3 gives reload values for different baud rates

Steps to Transmit a Byte 1. Program T1 for Mode2 (TMOD 0x20) 2. Load TH1 and TL1 with the initial value (baud rate dependant) (TH1 FD / FA / F4 / E8) 3. Program SCON for Mode1 (SCON 0x50) 4. Start Timer1 (SETB TR1) 5. Clear TI 6. Load SBUF with the byte to be transferred (SBUF byte) 7. Wait until TI becomes 1 (a wait loop using: JNB TI) 8. Go back to Step5 for next byte

Examples: Transmit a character Transfer ASCII A serially at 9600 baud continuously START: MOV TMOD, #20H ;Put T1 in mode2 MOV TH1, #-7 ;9600 baud MOV SCON, #50H ;8b, 1stop, 1start, REN enabled SETB TR1 ;start timer T1 AGAIN: CLR TI ;ready to transmit MOV SBUF, # A ;letter A is to be transmitted HERE: JNB TI, HERE ;poll TI until all the bits are transmitted SJMP AGAIN ;loop (forever loop)

Steps to Receive a Byte 1. Program T1 for Mode2 (TMOD 0x20) 2. Load TH1 and TL1 with the initial value (baud rate dependant) (TH1 FD / FA / F4 / E8) 3. Program SCON for Mode1 (SCON 0x50) 4. Start Timer1 (SETB TR1) 5. Clear RI 6. Wait until RI becomes 1 (a wait loop using JNB RI) 7. Store SBUF (A SBUF) 8. Go back to Step5 for next byte

Example: Receive Data Receive bytes serially and display them on P1, continuously. START: MOV TMOD, #20H ;T1 in mode 2 MOV TH1, #-7 ;9600 baud MOV SCON, #50H ;8b, 1start, 1stop SETB TR1 ;start T1 AGAIN: CLR RI ;ready to receive a byte HERE: JNB RI, HERE ;wait until one byte is Rx-ed MOV A, SBUF ;read the received byte from SBUF MOV P1, A ;display on P1 SJMP AGAIN ;loop forever