Timer.

Slides:



Advertisements
Similar presentations
The 8051 Microcontroller and Embedded Systems
Advertisements

8051 Core Specification.
CSC Timers Since this is a microcontroller it mainly finds itself in embedded devices Quite often embedded devices need to synchronize events The.
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.
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.
The 8051 Microcontroller architecture
UNIT V INTERFACING MICROCONTROLLER
NATIONAL TAIWAN OCEAN UNIVERSITY 國立台灣海洋大學 2002/4/8 Microcomputers and Microprocessors Chapter 9 COUNTER/TIMER PROGRAMMING IN THE 8051.
CHAPTER TIMER PROGRAMMING Timers The 8051 has two timers/counters, they can be used as ◦ Timers to generate a time delay ◦ Event counters.
8051 timer/counter.
1 Chapter 4 Timer Operation (I. Scott MacKenzie).
Chapter 9 Counter/Timer Programming in the 8051
Chapter 4 TIMER OPERATION
CoE3DJ4 Digital Systems Design Chapter 4: Timer operation.
Timers /Counters Programming  The 8051 has 2 timers/counters: ○ timer/counter 0 ○ timer/counter 1 They can be used as 1. The timer is used as a time.
1. Registers Used in Timer/Counter  TH0, TL0, TH1, TL1  TMOD (Timer mode register)  TCON (Timer control register) 2.
8051 Timer/Counter Lec note 7.
8051 Micro controller. Architecture of 8051 Features of 8051.
8254 Timer.
Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,
The 8051 Microcontroller Prepared By, R-THANDAIAH PRABU M.E.,
Jump, Loop, and Call Instructions
The Silicon Laboratories C8051F020
8051 Aula 02 Prof Afonso Ferreira Miguel. Microcontrolador 8051 (MCS-51)  Timers do MCS51 Two 16-bit Counter/Timers: Two 16-bit Counter/Timers: Up counters,
Lecture 41 CSE 341 – Microprocessors Lecture 4 Md. Omar Faruqe UB 1228
EE/CS-352: Embedded Microcontroller Systems Part V The 8051 Assembly Language Interrupts.
kashanu.ac.ir Microprocessors Interrupts Lec note 8.
Timer Programming in Assembly and C Prepared By:
HJD Institute of Technical Education & Research- Kera(Kutch) The 8051 Microcontroller architecture PREPARED BY: RAYMA SOHIL( )
DEPARTMENT OF ELECTRONICS ENGINEERING V-SEMESTER MICROPROCESSOR & MICROCONTROLLER 1 CHAPTER NO microcontroller & programming.
Serial I/O Port.
CHAPTER ADDRESSING MODES.
80C51 Block Diagram ECE Overview.
Assembly Language * * * * * * * 8051 Timer
Source: Serial Port Source:
8051 Timers Timers are the peripherals of the 8051 Microcontroller.
Timer Source: under
Programmable Interval Timer
Programmable Interval Timer
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.
Timer Operations and Programming
EMT 348: Microcontroller Timer/counter
Source: Serial Port Source:
8051 Timers Prof. Rajiv R Bhandari.
Interrupt.
Introduction to Micro Controllers & Embedded System Design Timer Operation Department of Electrical & Computer Engineering Missouri University of Science.
8254 Timer and Counter (8254 IC).
Introduction to Micro Controllers & Embedded System Design Addressing Mode Department of Electrical & Computer Engineering Missouri University of Science.
8051 Timers / Counters It has two timers Timer 0 and Timer 1.
Programmable Interval timer 8253 / 8254
8051 Microcontroller.
Timer Source: under
Introduction to Micro Controllers & Embedded System Design Instruction set Department of Electrical & Computer Engineering Missouri University of Science.
Interrupt Source: under
Programmable Interval timer 8253 / 8254
Interrupt.
Important 8051 Features On chip oscillator 4K bytes ROM 128 bytes RAM
Interrupt Source: under
INTRODUCTION TO 8051, A 8-BIT MICROCONTROLLER
Source: Serial Port Source:
Timer Source: under
8253 – PROGRAMMABLE INTERVAL TIMER (PIT). What is a Timer? Timer is a specialized type of device that is used to measure timing intervals. Timers can.
Interrupts of 8051 Introduction 8051 Interrupt organization
Source: Serial Port Source:
Presentation transcript:

Timer

The basic 8051 has two on-chip timers that can be used for controlling timing durations or for counting external events.

SFRs for timers TH1 High byte of timer 1 TH0 High byte of timer 0 TL1 Low byte of timer 1 TL0 Low byte of timer 0 TMOD Timer Mode Register TCON Timer Control Register

Timer Mode Register (TMOD) Bit Name Timer Description 7 Gate 1 Gate bit; when set, timer only runs while INT-bar is high. This bit is used in conjunction with interrupts and will be dealt with later. 6 C/T-bar Counter/timer select bit; when set timer is an event counter, when cleared timer is an interval timer. 5 M1 Mode bit 1 4 M0 Mode bit 0 3 Gate bit; when set, timer only runs while INT-bar is high. 2

Timer MODE M1 M0 Mode Description 13-bit timer mode (this mode exists simply to keep the 8051 backwards compatible with its predecessor, the 8048, which had a 13-bit timer) - we will not be using mode 0. 1 16-bit timer mode 2 8-bit auto-reload mode 3 Split timer mode - this mode will be dealt with at a later stage

Timer 1 TH1 TL1 … 1111 1111 1111 1111 0000 0000 0000 0000 0000 0000 0000 0001 TL1 … 1111 1111 0011 1010 (TH1 content) 0011 1011 0011 1100

Timer Control Register TCON Bit Symbol Bit Address Description 7 TF1 8FH Timer 1 overflow flag; set by hardware upon overflow, cleared by software. 6 TR1 8EH Timer 1 run-control bit; manipulated by software - setting starts timer 1, resetting stops timer 1. 5 TF0 8DH Timer 0 overflow flag; set by hardware upon overflow, cleared by software. 4 TR0 8CH Timer 0 run-control bit; manipulated by software - setting starts timer 0, resetting stops timer 0. 3 IE1 8BH The bottom four bits of TCON are used in conjunction with interrupts - they will be dealt with at a later stage. 2 IT1 8AH 1 IE0 89H IT0 88H

MOV TMOD, #16H SETB TR0 SETB TR1 CLR TR0; stop timer 0 CLR TR1; stop timer 1 MOV R7, TH0; move the high byte of timer 0 into R7 MOV R6, TL0; move the low byte of timer 0 into R6

Clock Source The timers are triggered by a negative edge to their clock inputs. Used as Clock source Interval timer the internal clock (12 MHz/12 = 1 MHz) Event counter an external source connected to pin T0 (port 3, pin 4) for timer 0 and pin T1 (port 3, pin 5) for timer 1

Generating Pulse Trains Program function: to generate a 4k Hz pulse train on pin 5 of port 1. Resource usage: Timer 0 TMOD regiter bit value note Timer 1 7 since we are not using timer 1 we can put all four upper bits to 0 6 5 4 Timer 0 3 gate (set when using interrupts, reset otherwise) 2 C/T-bar (0 because timer 0 is to be an interval timer) 1 mode bits (10 for mode 2, i.e., 8-bit auto-reload)

MOV TMOD, #02H ; set up timer 0 as 8-bit auto-reload interval timer MOV TH0, #83H ; put reload value into timer 0 high byte SETB TR0 ; start timer 0 waitForOverflow: JNB TF0, $ ; repeat this line while timer 0 overflow flag is not set CLR TF0 ; timer 0 overflow flag is set by hardware on transition from FFH - the flag must be reset by software CPL P1.5 ; complement (invert) pin 5 on port 1 - this instruction toggles the specified bit JMP waitForOverflow ; go back and wait for overflow again

If the high byte contains 00H, the counter goes through the full 256 states (00H to FFH). Therefore, an overflow occurs every 256us. We require a 4KHz pulse train on pin 5 of port 1; in other words, P1.5 must toggle every 125us (4KHz signal - one cycle every 250us - one half cycle every 125us). We need to load the high byte with a suitable value to result in an overflow every 125us. To find the value, we subtract the required time from the maximum time (256us - 125us = 131). Changing this value to HEX gives 83H.  

A One Second Delay using 0 ... MOV TMOD, #10H; set up timer 1 as 16-bit interval timer ...   fiftyMsDelay: CLR TR1 ; stop timer 1 (in case it was started in some other subroutine) MOV TH1, #3CH MOV TL1, #0B0H ; load 15,536 (3CB0H) into timer 1 SETB TR1 ; start timer 1 JNB TF1, $; repeat this line while timer 1 overflow flag is not set CLR TF1; timer 1 overflow flag is set by hardware on transition from FFFFH - the flag must be reset by software CLR TR1 ; stop timer 1 RET oneSecDelay: PUSH PSW PUSH AR0 ; save processor status MOV R0, #20 ; move 20 (in decimal) into R0 loop: CALL fiftyMsDelay ; call the 50 ms delay DJNZ R0, loop ; 20 times - resulting in a 1 second delay POP AR0 POP PSW ; retrieve processor status RET