Serial I/O Port.

Slides:



Advertisements
Similar presentations
The 8051 Microcontroller and Embedded Systems
Advertisements

Autumn 2012C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh Department of Electronic Engineering.
The 8051 Microcontroller Chapter 5 SERIAL PORT OPERATION.
Serial I/O - Programmable Communication Interface
CSC Timers Since this is a microcontroller it mainly finds itself in embedded devices Quite often embedded devices need to synchronize events The.
7-1 Digital Serial Input/Output Two basic approaches  Synchronous shared common clock signal all devices synchronised with the shared clock signal data.
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.
INTERRUPTS PROGRAMMING
Microcontroller 8051.
UNIT V INTERFACING MICROCONTROLLER
1 EKT 225 MICROCONTROLLER I CHAPTER 3 I/O PORT PROGRAMMING.
The 8051 Microcontroller and Embedded Systems
CHAPTER TIMER PROGRAMMING Timers The 8051 has two timers/counters, they can be used as ◦ Timers to generate a time delay ◦ Event counters.
1 Chapter 4 Timer Operation (I. Scott MacKenzie).
Chapter 4 TIMER OPERATION
CoE3DJ4 Digital Systems Design Chapter 4: Timer operation.
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.
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,
Jump, Loop, and Call Instructions
Unit 1 Lecture 4.
8051SERIAL PORT PROGRAMMING
Timer Programming in Assembly and C Prepared By:
DEPARTMENT OF ELECTRONICS ENGINEERING V-SEMESTER MICROPROCESSOR & MICROCONTROLLER 1 CHAPTER NO microcontroller & programming.
The 8085A is a general-purpose microprocessor with low hardware overhead requirements. Within the 8085A are contained the functions of clock generation,
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 mode of data transfer
Source: Serial Port Source:
8051 Timers Timers are the peripherals of the 8051 Microcontroller.
Timer Source: under
Serial I/O and Data Communication.
SERIAL PORT PROGRAMMING
BVM Engineering College Electrical Engineering Department : Microprocessor and Microcontroller Interfacing Interrupts of 8051 Prepared by:
Interrupt Source: under
Introduction to Micro Controllers & Embedded System Design Interrupt
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
Data bus CPU General Purpose microprocessor RAM ROM I/O Port Timer
DIGITAL DATA COMMUNICATION TECHNIQUES
EMT 348: Microcontroller Timer/counter
Source: Serial Port Source:
Interrupt.
Introduction to Micro Controllers & Embedded System Design Timer Operation Department of Electrical & Computer Engineering Missouri University of Science.
Timer.
Serial Communication Interface: Using 8251
Serial Communication Interface
8051 Timers / Counters It has two timers Timer 0 and Timer 1.
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.
Prof Afonso Ferreira Miguel
Source: Serial Port Source:
8051SERIAL PORT PROGRAMMING
Serial Communications
Presentation transcript:

Serial I/O Port

Synchronous communication Asynchronous communication

Because serial communication requires less physical wires, it is more suitable for transmitting data over longer distances. Advantage: Fewer wires Longer distance Disadvantage:Lower data rate

Baud rate: the data rate in serial communication; the number of bits transmitted per second. The 8051 serial port is full duplex. In other words, it can transmit and receive data at the same time. The serial port can be transmitting data down the TXD line while it is at the same time receiving data on the RXD line.

SBUF register At location 99H is the serial buffer special function register (SBUF). Unlike any other register in the 8051, SBUF is in fact two distinct registers - the write-only register and the read-only register. To transmit data along the serial line you simply write to the serial buffer. To access data received on the serial port you simply read data from the serial buffer. For example: MOV SBUF, #45H ; This sends the byte 45H down the serial line MOV A, SBUF ; This takes whatever data was received by the serial port and puts it in the accumulator

Transmitted data is sent out from the write-only register. Received data is stored in the read-only register.

How do we know when the complete data byte has been sent? The serial port control register (SCON) contains a bit which alerts us to the fact that a byte has been transmitted The transmit interrupt flag (TI) is set by hardware once an entire byte has been transmitted down the line. Since SCON is bit-addressable we can test this bit and wait until it is set. In the following instruction sequence, the initial character will be overwritten before it was completely shifted down the line. MOV SBUF, #23H MOV SBUF, #56H MOV SBUF, #23H ; send the first byte down the serial line JNB TI, $ ; wait for the entire byte to be sent CLR TI ; the transmit interrupt flag is set by hardware but must be cleared by software MOV SBUF, #56H ; send the second byte down the serial line

How do we know when data has been received? The receive interrupt flag (RI) in SCON is set by hardware when an entire byte is received by the serial port. The code below shows how you would program the controller to wait for data to be received and to then move that data into the accumulator. JNB RI, $ ; wait for an entire byte to be received CLR RI ; the receive interrupt flag is set by hardware but must be cleared by software MOV A, SBUF ; move the data stored in the read-only buffer to the accumulator Once an entire byte is received (ie; shifted along RXD into the shift register) the RI bit is set and the data byte is moved into the read-only buffer.

Bit 4, as indicated, must be set if data is to be received. Therefore, the above code for reading a byte from the serial port into the accumulator would first have to include a line for setting REN, as shown below. SETB REN ; set bit 4 of SCON so that data can be received JNB RI, $ ; wait for an entire byte to be received CLR RI ; the receive interrupt flag is set by hardware but must be cleared by software MOV A, SBUF ; move the data stored in the read-only buffer to the accumulator

Bits 7 and 6 are used for putting the serial port into one of the four modes, as detailed in the table below.

MODE 0

MODE 1

In mode 1, the baud rate is determined by the overflow of timer 1 In mode 1, the baud rate is determined by the overflow of timer 1. However, since the timer operates at a relatively high frequency (compared to serial port baud rates) the timer 1 overflow frequency is divided by either 32 or 16, as shown in the diagram below.

How does TH1 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. To find the correct value to load into TH1 we use the following formula: 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 value 230 in TH1 will result in timer 1 counting continuously from 230 to 255. TF1 will be set every time the count rolls over from 255 back to 230. Since we are using a system clock frequency of 12MHz, the timer changes state every 1us (remember, the timer clock frequency is the system clock frequency divided by 12 - hence the divide by 12 in the above equation). This results in an overflow every 26us which implies a timer overflow frequency of 1 / 26us = 38.46kHz. The baud rate is the timer overflow frequency divided by 32 (hence the divide by 32 in the above equation) which, in this case is 38.46kHz / 32 = 1202 bits/sec. 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

How do we set SMOD? SMOD is the MSB of the PCON register. However, if you look at the memory map you will notice that PCON, at address 87H, is not bit addressable. Therefore we cannot simply use the SETB instruction to set SMOD. The code below shows how you read-modify-write PCON in order to set SMOD without changing the other seven bits in the register. MOV A, PCON ;copy PCON to the accumulator SETB ACC.7 ;set the accumulator MSB MOV PCON, A ;copy the accumulator back to PCON

Baud rate table

Adding a Parity Bit to ASCII Data 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. How to transmit and receive ASCII characters with even parity: MOV A, 30H ; move the ASCII character stored in location 30H to the ACC MOV C, P ;copy the parity bit to the carry bit MOV ACC.7, C ;then move it from the carry bit to the ACC MSB MOV SBUF, A ;transmit the character along with the parity bit down the serial line JNB TI, $ ; wait for the byte to be sent CLR TI

Timer 1