Review: Interrupts & Timers

Slides:



Advertisements
Similar presentations
4-1 Timers Timers can be used for  timing  event counting  pulse width measurement  pulse generation  frequency multiplication There are 8 Timers.
Advertisements

C Examples 1.
The 8051 Microcontroller Chapter 5 SERIAL PORT OPERATION.
UBC104 Embedded Systems Review: Introduction to Microcontrollers.
CSC Timers Since this is a microcontroller it mainly finds itself in embedded devices Quite often embedded devices need to synchronize events The.
Interrupts What is an interrupt? What does an interrupt do to the “flow of control” Interrupts used to overlap computation & I/O – Examples would be console.
Eng. Husam Alzaq The Islamic Uni. Of Gaza
USART and Asynchrono us Communica tion The USART is used for synchronous and asynchronous serial communication. USART = Universal Synchronous/Asynchronous.
7-1 Digital Serial Input/Output Two basic approaches  Synchronous shared common clock signal all devices synchronised with the shared clock signal data.
Architecture of the 8051 INTERNAL DATA BUS Oscillator & Timing Programmable I/O (32 Pins) 80C51 CPU 64K byte Expansion Control Serial I/O 4K Program Memory.
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.
ECE 371- Unit 11 Introduction to Serial I/O. TWO MAJOR CLASSES OF SERIAL DATA INTERFACES ASYNCHRONOUS SERIAL I/O - USES “FRAMING BITS” (START BIT AND.
1.  8051 Timers “count up,” incrementing the Timer’s respective “count register” each time there is a triggering clock pulse. 2  When the “count register”
Lecture 9 Timer Operations and Programming. 2  Introduction  Summary of timers  Timer programming sequence  Summary of timer SFRs  Timer 0: 8-bit.
University of Tehran 1 Interface Design Serial Communications Omid Fatemi.
Serial Communication ETEC 6416.
The 8051 Microcontroller and Embedded Systems
UART and UART Driver B. Ramamurthy.
Lecture Set 9 MCS-51 Serial Port.
“Describe the overview of hardware interfacing and the serial communication interface. Describe the PIC18 connections to RS232. Explain the serial port.
Universal Asynchronous Receiver/Transmitter (UART)
CHAPTER SERIAL PORT PROGRAMMING. Basics of Serial Communication Computers transfer data in two ways: ◦ Parallel  Often 8 or more lines (wire conductors)
1 Lab 1: Introduction. 2 Configure ATMEL AVR Starter Kit 500 (STK500), a prototyping/development board for Lab1. ATmega16 ( V) is the chip used.
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)
 8251A is a USART (Universal Synchronous Asynchronous Receiver Transmitter) for serial data communication.  Programmable peripheral designed for synchronous.
MICROCONTROLLER SYSTEMS Part 1. Figure 1.1Elements of a digital controller CPU Central Processing Unit Input Peripherals Output Peripherals ROM Read Only.
Universal Asynchronous Receiver/Transmitter (UART)
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.
The Silicon Laboratories C8051F020
Chapter Microcontroller
CE-2810 Dr. Mark L. Hornick 1 Serial Communications Sending and receiving data between devices.
Networked Embedded Systems Pengyu Zhang & Sachin Katti EE107 Spring 2016 Lecture 4 Timers and Interrupts.
Timer Programming in Assembly and C Prepared By:
80C51 Block Diagram 1. 80C51 Memory Memory The data width is 8 bits Registers are 8 bits Addresses are 8 bits – i.e. addresses for only 256.
DEPARTMENT OF ELECTRONICS ENGINEERING V-SEMESTER MICROPROCESSOR & MICROCONTROLLER 1 CHAPTER NO microcontroller & programming.
1. PIC ADC  PIC18F877 has 8 analog input channels i.e. port A pins(RA0 to RA5) and port E pins(RE1 and RE2). These pins are used as Analog input pins.
1 4-Integrating Peripherals in Embedded Systems. 2 Introduction Single-purpose processors  Performs specific computation task  Custom single-purpose.
Chapter 10 Interrupts. Basic Concepts in Interrupts  An interrupt is a communication process set up in a microprocessor or microcontroller in which:
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.
Embedded Microcontroller Systems
Serial mode of data transfer
80C51 Block Diagram ECE Overview.
Assembly Language * * * * * * * 8051 Timer
Embedded Microcontroller Systems
Homework Reading Machine Projects Labs
Source: Serial Port Source:
Timer and Interrupts.
8051 Timers Timers are the peripherals of the 8051 Microcontroller.
Embedded Systems Prepared By:
SERIAL PORT PROGRAMMING
BVM Engineering College Electrical Engineering Department : Microprocessor and Microcontroller Interfacing Interrupts of 8051 Prepared by:
Interrupt Source: under
Source: Serial Port Source:
Serial Communication Interface
Interrupt Source: under
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Important 8051 Features On chip oscillator 4K bytes ROM 128 bytes RAM
UNIT-VIII 8051 Microcontroller Architecture Register set of 8051
Interrupt Source: under
8051 Micro Controller.
Source: Serial Port Source:
CHAPTER SERIAL PORT PROGRAMMING. Basics of Serial Communication Computers transfer data in two ways: ◦ Parallel  Often 8 or more lines (wire.
Source: Serial Port Source:
PIC Serial Port Interfacing
8051SERIAL PORT PROGRAMMING
PIC Serial Port Interfacing
Presentation transcript:

Review: Interrupts & Timers UBC104 Embedded Systems Review: Interrupts & Timers

Block Diagram UBC 104 Embedded Systems

Definition of ‘Interrupt’ Interrupts Definition of ‘Interrupt’ Event that disrupts the normal execution of a program and causes the execution of special instructions UBC 104 Embedded Systems

Interrupt Handling Code that deals with interrupts: Interrupt Handler or Interrupt Service Routines (ISRs) Possible code: void ISR(void) interrupt 1 { ++interruptcnt; } Interrupt number UBC 104 Embedded Systems

Interrupt Overheads Interrupt Latency Interrupt Termination Interrupt arrives Complete current instruction Save essential register information Vector to ISR Save additional register information Execute body of ISR Restore other register information Return from interrupt and restore essential registers Resume task Interrupt Latency Interrupt Termination UBC 104 Embedded Systems

SFR Map – Timer UBC 104 Embedded Systems

Timer Code Initialization Start of Timer Interrupt Service Routine void TimerInit(void) { T2CON = 0x04; // Load Timer 2 control register TH2 = 0xFC; // Load Timer 2 high byte RCAP2H = 0xFC; // Load Timer 2 reload capt. reg. high byte TL2 = 0x18; // Load Timer 2 low byte RCAP2L = 0x18; // Load Timer 2 reload capt. reg. low byte ET2 = 1; // Enable interrupt TR2 = 1; // Start Timer 2 running } void handleTimer2 (void) interrupt 5 { /* execute interrupt code */ Start of Timer Interrupt Service Routine UBC 104 Embedded Systems

Calculation of Register Settings Oscillator = 24 MHz Timer clock= (24 / 12) MHz = 2 MHz Timer cycle = = 500ns Delay count = delay time / cycle time 1 ms / 500 ns = 2000 Base number= 213-2000 = 8192-2000 = 6192 = 0x1830 2 MHz 1 UBC 104 Embedded Systems

Summary: Interrupts & Timers Event that disrupts the normal execution of a program and causes the execution of special instructions Interrupt Latency: Time from event to execution of service routine Interrupt Response Time: Interrupt latency + Time for service routine Interrupt Termination: Time taken after interrupt service routine Timer: Counter that causes interrupt at overflow UBC 104 Embedded Systems

UBC104 Embedded Systems RS232 Communication

Overview Basics of serial communications RS232 details 8051-support for serial communication UBC 104 Embedded Systems

SFR Map – UART Registers UBC 104 Embedded Systems

UART Registers UBC 104 Embedded Systems

Serial Interface Basics Also called Universal Asynchronus Receiver/ Transmitter (UART) or after the I standards: RS232 (-C) or EIA232 UBC 104 Embedded Systems

Serial Interface Basics also called Universal Asynchronus Receiver/ Transmitter (UART) or the relevant standards: RS232 (-C) or EIA232 2 Receive Data 3 Transmit Data 5 Signal Ground UBC 104 Embedded Systems

Typical 3-wire Interface 2 5 UBC 104 Embedded Systems

uController Pin-Out UBC 104 Embedded Systems

RS232 Signals Signals between +25V and -25V; some say ±15V usually +12V to -12V UBC 104 Embedded Systems

RS232 Signals Signals between +25V and -25V; some say ±15V usually +12V to -12V Logic ‘0’ Logic ‘1’ UBC 104 Embedded Systems

RS232 Signals Signals between +25V and -25V; some say ±15V usually +12V to -12V UBC 104 Embedded Systems

RS232 Signals Signals between +25V and -25V; some say ±15V usually +12V to -12V 8051 runs on 3V or 5V UBC 104 Embedded Systems

RS232 Signals Signals between +25V and -25V; some say ±15V usually +12V to -12V 8051 runs on 3V or 5V Driver chip translates between voltages UBC 104 Embedded Systems

Valid Signals UBC 104 Embedded Systems

Valid Signals Figure courtesy of http://www.camiresearch.com UBC 104 Embedded Systems

MCBx51 Board 3 2 TX0 RX0 UBC 104 Embedded Systems

Basic 3-Wire Connection of Machines TXD RXD GND UBC 104 Embedded Systems

Basic 3-Wire Connection of Machines TXD RXD GND What goes over these wires? UBC 104 Embedded Systems

RS-232 Frame Every RS-232 consists of: 1 start bit 8 data bits 1 stop bit (optional 1 parity bit) UBC 104 Embedded Systems

RS-232 Frame Every RS-232 consists of: 1 start bit 8 data bits 1 stop bit (optional 1 parity bit) Start D0 D1 D2 D3 D4 D5 D6 D7 Stop UBC 104 Embedded Systems

RS-232 Frame Every RS-232 consists of: ‘a’= 0x61 = 0110 0001 1 start bit 8 data bits 1 stop bit (optional 1 parity bit) ‘a’= 0x61 = 0110 0001 Start D0 D1 D2 D3 D4 D5 D6 D7 Stop UBC 104 Embedded Systems

RS-232 Frame Every RS-232 consists of: ‘a’= 0x61 = 0110 0001 1 start bit 8 data bits 1 stop bit (optional 1 parity bit) ‘a’= 0x61 = 0110 0001 Start D0 D1 D2 D3 D4 D5 D6 D7 Stop 1 1 1 1 1 UBC 104 Embedded Systems

RS-232 Frame Every RS-232 consists of: ‘a’= 0x61 = 0110 0001 1 start bit 8 data bits 1 stop bit (optional 1 parity bit) ‘a’= 0x61 = 0110 0001 Start D0 D1 D2 D3 D4 D5 D6 D7 Stop 1 1 1 1 0 1 UBC 104 Embedded Systems

RS-232 Frame Every RS-232 consists of: ‘a’= 0x61 = 0110 0001 1 start bit 8 data bits 1 stop bit (optional 1 parity bit) ‘a’= 0x61 = 0110 0001 Start D0 D1 D2 D3 D4 D5 D6 D7 Stop 1 1 1 1 0 1 0 0 0 0 1 1 0 1 UBC 104 Embedded Systems

RS-232 Frame Every RS-232 consists of: ‘a’= 0x61 = 0110 0001 1 start bit 8 data bits 1 stop bit (optional 1 parity bit) ‘a’= 0x61 = 0110 0001 Start D0 D1 D2 D3 D4 D5 D6 D7 Stop 1 1 1 1 0 1 0 0 0 0 1 1 0 0 1 UBC 104 Embedded Systems

RS-232 Frame Every RS-232 consists of: ‘a’= 0x61 = 0110 0001 1 start bit 8 data bits 1 stop bit (optional 1 parity bit) ‘a’= 0x61 = 0110 0001 Start D0 D1 D2 D3 D4 D5 D6 D7 Stop 1 1 1 1 0 1 0 0 0 0 1 1 0 0 1 1 1 UBC 104 Embedded Systems

Signal Timing ? 1 1 1 1 0 1 0 0 0 0 1 1 0 0 1 1 1 1 Start D0 D1 D2 D3 Stop 1 1 1 1 0 1 0 0 0 0 1 1 0 0 1 1 1 1 ? UBC 104 Embedded Systems

Signal Timing (continued) Start D0 D1 D2 D3 D4 D5 D6 D7 Stop 1 1 1 1 0 1 0 0 0 0 1 1 0 0 1 1 1 1 ? bit period UBC 104 Embedded Systems

Baud Rate Baud specifies the inverse of the bit-period e.g. 9600 Baud = a bit-period of 1/9600 second = 104.2 microseconds Typicall data rates: 75, 110, 300, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 33600, 56000, 115000 and (rarely) 330000 baud. UBC 104 Embedded Systems

Serial I/O with bare hands #define BIT_PERIOD 1042 sendByte(unsigned char content) { unsigned char mask; mask= 1; P3.1= 0; // Start bit wait (BIT_PERIOD); for (i= 0; i<8; i++) { // Send content P3.1= (content&mask) ? 1 : 0; mask<= 1; } P3.1= 0; // Stop bit P3.1= 1; UBC 104 Embedded Systems

Serial I/O with bare hands #define BIT_PERIOD 1042 sendByte(unsigned char content) { unsigned char mask; mask= 1; P3.1= 0; // Start bit wait (BIT_PERIOD); for (i= 0; i<8; i++) { // Send content P3.1= (content&mask) ? 1 : 0; mask<= 1; } P3.1= 0; // Stop bit P3.1= 1; UBC 104 Embedded Systems

Serial I/O with bare hands You do not need to do this!!! #define BIT_PERIOD 1042 sendByte(unsigned char content) { unsigned char mask; mask= 1; P3.1= 0; // Start bit wait (BIT_PERIOD); for (i= 0; i<8; i++) { // Send content P3.1= (content&mask) ? 1 : 0; mask<= 1; } P3.1= 0; // Stop bit P3.1= 1; UBC 104 Embedded Systems

UART modes Mode 0: 8 data bits (LSB first) are transmitted/received at a fixed baud rate of 1/12 of the oscillator frequency. (synchronus mode) UBC 104 Embedded Systems

UART modes Mode 0: 8 data bits (LSB first) are transmitted/received at a fixed baud rate of 1/12 of the oscillator frequency. (synchronus mode) Mode 1: 10 bits are transmitted (through TXD) or received (through RXD): a start bit (0), 8 data bits (LSB first), and a stop bit (1) at a variable baud rate. UBC 104 Embedded Systems

UART modes Mode 0: 8 data bits (LSB first) are transmitted/received at a fixed baud rate of 1/12 of the oscillator frequency. (synchronus mode) Mode 1: 10 bits are transmitted (through TXD) or received (through RXD): a start bit (0), 8 data bits (LSB first), and a stop bit (1) at a variable baud rate. Mode 2: 11 bits are transmitted (through TXD) or received (through RXD): a start bit (0), 8 data bits (LSB first), a programmable 9th data bit, and a stop bit (1). On transmit, the 9th data bit (TB8 in SCON) can be assigned the value of 0 or 1 (for example, the parity bit (P, in the PSW) could be moved into TB8). On receive, the 9th data bit goes into RB8 in Special Function register SCON. The baud rate is programmable to either 1/32 or 1/64 the oscillator frequency. Mode 3: Mode 3 is the same as Mode 2 in all respects except the baud rate is variable. UBC 104 Embedded Systems

UART modes Mode 0: 8 data bits (LSB first) are transmitted/received at a fixed baud rate of 1/12 of the oscillator frequency. (synchronus mode) Mode 1: 10 bits are transmitted (through TXD) or received (through RXD): a start bit (0), 8 data bits (LSB first), and a stop bit (1) at a variable baud rate. Mode 2: 11 bits are transmitted (through TXD) or received (through RXD): a start bit (0), 8 data bits (LSB first), a programmable 9th data bit, and a stop bit (1). On transmit, the 9th data bit (TB8 in SCON) can be assigned the value of 0 or 1 (for example, the parity bit (P, in the PSW) could be moved into TB8). On receive, the 9th data bit goes into RB8 in Special Function register SCON. The baud rate is programmable to either 1/32 or 1/64 the oscillator frequency. Mode 3: Mode 3 is the same as Mode 2 in all respects except the baud rate is variable. Mode 0 Baud Rate = 12 Oscillator Frequency Mode 2 Baud Rate = 2 SMOD1 x 64 Oscillator Frequency Mode 1/3 Baud Rate = 2 SMOD1 x 32 Timer Overflow Rate UBC 104 Embedded Systems

SMOD1 SMOD1: Double Baud rate SMOD0: Enables framing error detection UBC 104 Embedded Systems

Framing Error Detection UBC 104 Embedded Systems

Timer 1 http://www.keil.com/c51/baudrate.asp Timer Overflow Rate Mode 1/3 Baud Rate = 2 SMOD1 x 32 2 SMOD1 Oscillator Frequency Mode 1/3 Baud Rate = x 32 12 x [256 – TH1] 2 SMOD1 Oscillator Frequency [256 – TH1] = x 32 12 x Baud Rate 2 SMOD1 Oscillator Frequency TH1 = 256 – x 32 12 x Baud Rate http://www.keil.com/c51/baudrate.asp UBC 104 Embedded Systems

Timer 1 Commonly Used BAUD Rates UBC 104 Embedded Systems

SCON Documentation UBC 104 Embedded Systems

SCON & SBUF SCON controls the functionality of the UART device: SM0&SM1 = Determine the mode SM2 = Multiprocessor Flag REN = Receive Enable Flag TB8/RB8 = Transmit/Receive Parity Flag TI/RI = Transmit/Receive Interrupt Flag SBUF is the transmit&receive buffer UBC 104 Embedded Systems

SBUF SBUF is actually two separate registers: a transmit buffer and a receive buffer register: When data is moved to SBUF, it goes to the transmit buffer where it is held for serial transmission; moving a byte to SBUF initiates the transmission. When data is moved from SBUF, it comes from the receive buffer. UBC 104 Embedded Systems

SBUF and TI/RI TRANSMITTER HALF RECEIVER HALF UBC 104 Embedded Systems 8 data SBUF 8 TI Stop bit Start bit Send 8-bit data Transmitter Buffer is empty 10 bit parallel to serial conversion Serial data transmit TRANSMITTER HALF 8 data bits start bit stop Tx bit 8 data SBUF 8 RI Start bit Stop bit Receive 8-bit data data is available 10 bit serial to parallel conversion Serial data receive RECEIVER HALF 8 data bits stop start Rx UBC 104 Embedded Systems

SBUF and Parity Bit in TB8/RB8 UBC 104 Embedded Systems

Timer 1 Example Set T1 for Mode 2 Load TH1 with the initial value Set SCON for Mode 1 Start Timer1 Clear TI Load SBUF with the byte to be transferred Wait until TI becomes 1 Go back to Step5 for next byte TCON= 0x20; TH1= 0xF5; SCON|= 0x50; TR1= 1; TI= 0; do { SBUF= byte[i]; while (!TI); } while(more_bytes); UBC 104 Embedded Systems

Timer 1 Example (continued) Set T1 for Mode 2 Load TH1 with the initial value Set SCON for Mode 1 Start Timer1 Clear RI Wait for byte to be received Copy received byte out of SBUF Return received byte TCON= 0x20; TH1= 0xF5; SCON|= 0x50; TR1= 1; RI= 0; while (!RI); result= SBUF; return SBUF; UBC 104 Embedded Systems

Possible Configurations UBC 104 Embedded Systems

T2CON Documentation UBC 104 Embedded Systems

Timer 2 Commonly Used BAUD Rates UBC 104 Embedded Systems

Timer 2 Calculation Mode 1/3 Baud Rate = (RCAP2H,RCAP2L) = 65535 – Oscillator Frequency Mode 1/3 Baud Rate = 32 x [65536 – (RCAP2H, RCAP2L)] Oscillator Frequency (RCAP2H,RCAP2L) = 65535 – 32 x Baud Rate UBC 104 Embedded Systems

Timer2 Example Set T1 for Mode 2 Load RCAP high/low with the initial value Set SCON for Mode 1 Start Timer1 Clear TI Load SBUF with the byte to be transferred Wait until TI becomes 1 Go back to Step5 for next byte T2CON|= 0x30; RCAP2H = 0xFF; RCAP2L = 0xB2; SCON|= 0x50; TR2= 1; TI= 0; do { SBUF= byte[i]; while (!TI); } while(more_bytes); UBC 104 Embedded Systems

Internal Baud-Rate Generator UBC 104 Embedded Systems

BDRCON UBC 104 Embedded Systems

Using BRL to Transmit Set T1 for Mode 2 Load TH1 with the initial value Set SCON for Mode 1 Start Timer1 Clear TI Load SBUF with the byte to be transferred Wait until TI becomes 1 Go back to Step5 for next byte BDRCON= 0x0E; BRL= 0xF5; SCON|= 0x50; BDRCON|= 0x10; TI= 0; do { SBUF= byte[i]; while (!TI); } while(more_bytes); UBC 104 Embedded Systems