Chapter 09. Programming in Assembly

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

ELEG3923 Microprocessor Ch.9 Timer Programming

CHAPTER TIMER PROGRAMMING

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

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

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

Timers and interrupts

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

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: Interrupt Handling Module No: CS/ES/13 Quadrant 1 e-text

Chapter 09. Programming in Assembly


CoE3DJ4 Digital Systems Design. Chapter 6: Interrupts

CPEG300 Embedded System Design. Lecture 8 Timer

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

Timer Counter and Interrupt. Equation (16 bits counter, Mode 1, 16MHz):

Chapter 6 PROGRAMMING THE TIMERS

Chapter 2. Overview of Architecture and Microcontroller-Resources

Microcontroller and Embedded Systems:

Chapter 6 PROGRAMMING THE TIMERS

2. Write an 8051 program to generate a square wave of 25 khz at pin P2.3 using XTAL = 12 MHz. Solution:

Lesson-3: Counters and Timers

8051 Timers and Serial Port

CoE3DJ4 Digital Systems Design. Chapter 5: Serial Port Operation

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

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

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

Interrupt Programming: Interrupts vs. Polling Method:

Chapter 3. Bit Addressable Area. By DeccanRobots

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

INTERRUPTS PROGRAMMING

e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interrupt Programming in Embedded C Module No: CS/ES/20 Quadrant 1 e-text

FACULTY OF ENGINEERING LAB SHEET

CPEG300 Embedded System Design. Lecture 6 Interrupt System

80C51 Block Diagram. CSE Overview 1

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

CHAPTER 11 INTERRUPTS PROGRAMMING

8051 Interrupt Organization

8051 I/O and 8051 Interrupts

8051 Serial Communication

Introduction To MCS-51

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

How to use the PSoC based 16C450 Replacement

SANKALCHAND PATEL COLLEGE OF ENGINEERING, VISNAGAR. ELECTRONICS & COMMUNICATION DEPARTMENT Question Bank- 1

Lecture 9. Timer Operations and Programming

8051 Microcontroller

EE6502- MICROPROCESSOR AND MICROCONTROLLER

UNIT THE 8051 INSTRUCTION SET AND PROGRAMMING

INSTITUTE OF AERONAUTICAL ENGINEERING Dundigal, Hyderabad ELECTRONICS AND COMMUNICATION ENGINEERING QUESTION BANK

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

By the end of Class. Outline. Homework 5. C8051F020 Block Diagram (pg 18) Pseudo-code for Lab 1-2 due as part of prelab

UNIT 2 THE 8051 INSTRUCTION SET AND PROGRAMMING

8051 Core Specification

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

Timer programming

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

CS 320. Computer Architecture Core Architecture

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

MAHALAKSHMI ENGINEERING COLLEGE TIRUCHIRAPALLI UNIT- IV

Interrupts, timers and counters

~: Simple Programs in 8051 assembly language :~

2. (2 pts) If an external clock is used, which pin of the 8051 should it be connected to?

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

MICROPROCESSORS AND MICROCONTROLLERS MATERIAL. Features of 8051:

Department of Electronics and Instrumentation Engineering Question Bank

ELEG3923 Microprocessor Ch.4 I/O Ports

AN427 Timer I in non-i 2 C applications of the 83/87C751/752 microcontrollers

Embedded Controller Programming

Table of Contents. PREFACE... vii CONVENTIONS... vii HOW TO USE THIS MANUAL... vii Further Information...viii

Memory organization Programming model - Program status word - register banks - Addressing modes - instruction set Programming examples.

8051 Microcontroller Logical Operations. Prepared by : A. B. Modi Target Audience : 5 th Semester Students

8051 Microcontroller memory Organization and its Applications

C H A P T E R 1 INTRODUCTION

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

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

Three criteria in Choosing a Microcontroller

8051 Microcontroller. Ali Ziya Alkar 1

1. Pin diagram of 8051 and ports

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

Fig 1. Block diagram of a microcomputer

MCS -51 Programmer s Guide and Instruction Set

ELEG3923 Microprocessor Ch.10 Serial Port Programming

MLR INSTITUTE OF TECHNOLOGY DUNDIGAL , HYDERABAD

MODULE-1. Short Answer Questions

Firmware Description:

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

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


C51 Family. Architectural Overview of the C51 Family. Summary

Program Modeling Concepts:

Module 1: Introduction to Microcontroller

AT Bit Spread- Spectrum Microcontroller. Preliminary. Features. Description. Pin Configuration

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

1. Attempt any three of the following: 15

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

Measuring Duty Cycles with an Intel MCS-51 Microcontroller

VRS570 32K Flash, 1kB RAM, 25~40MHz, 8-Bit MCU VRS580 64K Flash, 1kB RAM, 25~40MHz, 8-Bit MCU

BHARATHIDASAN ENGINEERING COLLEGE. III Year / V Semester / EEE MICROPROCESSORS AND MICROCONTROLLERS (R-2013)

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

PART - B (Answer all five units, 5 X 10 = 50 Marks)

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

Transcription:

Chapter 09 Programming in Assembly

Lesson 05 Programming Examples for Timers

Programming TMOD Register 3

Write instructions to run T0 in Mode 0, external count inputs, internal start/stop control ANL TMOD, # F4 ; Using AND operation upper 4 bits will not change in ; TMOD. Lower 4-bits will change = 0100. GATET0 = 0, ;C/T0 = 1, M1T0; = 0 and M0 T0 = 0 ;When defining a mode do not change the mode of T1 4

Write instructions to run T0 in Mode 1 internal clock inputs and internal start/stop control ANL TMOD, # F1 ; Using AND operation upper 4 bits will not change in ; TMOD. Lower 4-bits will change = 0001. GATET0 = 0, ;C/TT0 = 0, M1T0; = 0 and M0 T0 = 1. ;When defining a mode do not change the mode of T1 5

Write instructions to run T0 in mode 2 internal clock inputs ANL TMOD, # F4; Using AND operation upper 4 bits will not change in ; TMOD. Lower 4-bits will change = 0010. GATET0 = 0, ;C/TT0 = 0, M1T0; = 1 and M0 T0 = 0 ;When defining a mode do not change the mode of T1 6

Write instructions to run TH0 and TL0 independent timer in mode 3 internal clock inputs ANL TMOD, # F3 ; Using AND operation upper and lower 4 bits will change in ; TMOD. Lower 4-bits will change = 0011. GATET0 = 0, ;C/TT0 = 0, M1T0; = 1 and M0 T0 = 1 ; When defining a mode do not change the mode of T1 7

Programming Time Interval for the Overflow and Timer Interrupt using TH0, TL0, TH1 andtl1 8

Internal clock input intervals and frequency of internal clock to the 12 MHz timers in 8051 Each internal clock interval to the timer will be equal to 1 µs 9

Internal clock input intervals and frequency of internal clock to the timers in 8051 Xtal frequency 24 MHz Internal clock input intervals 0.5 µs 10

Internal clock input intervals and frequency of internal clock to the timers in 8051 XTAL frequency = 11.0592 MHz then Internal clock input intervals = 1.085 µs. 11

Maximum interval for the overflow the timer T0 12 MHz Xtal used Mode 0: 2 13 1 µs. Mode 1: 2 16 1 µs. Mode 2: 2 8 1 µs. Mode 3 TL0: 2 8 1 µs. Mode 3 TH0: 2 8 1 µs. 12

Timer higher byte TH0 with 80H in mode 2 MOV TH0, #80H; TH0 = 128; MOV TL0, #80H; TL0 = 128; SETB TR0; Timer T0 runs (28 80H) 1 ; µs= 128 µs. TL0 overflows in 128 µs ;and TH0 reloads into TL0 after every 128 µs [12 MHz XTAL] 13

Timer with 40H and 80H in mode 3 TH0 and TL0 MOV TH0, #40H; MOV TL0, #80H; SETB TR0; ;TH0 overflows after (2 8 40H) 1 µs ;= 192 µs. TL0 overflows after ;(2 8 80H) 1 µs= 128 µs [12 MHz XTAL] 14

Timer with 8000H in mode 1 MOV TH0, #80H; MOV TL0, #00H; SETB TR0 ;TH0 overflows after (2 16 32768) 1 µs= ;32.768 ms [12 MHz XTAL] 15

Programming TCON 16

Using TCON bit for the starting timer T0 Starting timer T0: SETB TCON.4 or SETB TR0 or SETB 8CH 17

Using TCON bits for the starting timer T1? Starting timer T1: SETB TCON.6 or SETB TR1 or SETB 8EH 18

Using TCON flag for the overflow of timer T0 Resetting timer T0: CLR TCON.5; or CLR TF0; or CLR8DH ;Some time a program waits for TF0 to set ;and then an instruction clears it after the ;necessary action. ISR for T0 is not used in ;this case. Resetting the flag enables ;response to next T0 interrupt and next ;overflow. 19

Using TCON bits for the starting timer T0 Resetting timer T1: CLR TCON.7; or CLR TF1; or CLR8FH ;Some time a program waits for TF1 to set ;and then an instruction clears it after the ;necessary action, ISR for T1 is not used in ;this case. ;Resetting the flag enables response to next ;T1 interrupt and next overflow 20

Programming for program for overflow and interrupt after 4.096 ms and setting output at P2.6 pin after the overflow and interrupt after 4.096 ms 21

Solution When Xtal frequency = 12 MHz, the internal clock intervals = 1 µs Overflow required after 4.096 ms It means after 4.096 ms/ 1µs = 4096 internal clock input = 1000H = 128 32 = 2 7 2 5 = 2 12 clock inputs. Use timer T0 mode 0 ISR for timer T0 will stop the Timer 0 after the overflows and interrupt and set port bit P2.6 22

Program (Main Program) (i) ANL TMOD, #0F0 ; Define T0 mode 0, internal clock inputs and internal start/stop (ii) MOV TH0, #80H ; TH0 overflows after the 128 clock inputs (iii) MOV TL0, #00H ; TL0 overflows after 32 clock inputs 23

Program (Main Program) (iv) SETB EA ; Enable interrupts (v) SETB ET0 ; Enable T0 interrupts (vi) SETB TR0 ; Run timer T0 (vii) SJMP 2 ; Wait for ever 24

Interrupt Service Routine for T0 (i) CLR TR0 ; Stop T0 (ii) CLR ET0 ; Disable T0 interrupts. en (iii) SETB P2^6 ; Set bit 0AEH can be used in place of P2^6. 0AEH is bit address of P2.6 pin (iv) RETI ; Return from Interrupt 25

Program for a timer in mode 2 for the successive interrupts after every 250 µs and setting and resetting (toggling) of the P2.6 pin output on overflow [Square Pulses] 26

Program (Main Program) (i) ANL TMOD, #F2 ; Define T0 mode 2, internal clock inputs and internal start/stop (ii) MOV TL0, #06H ; TL0 overflows after 150 clock inputs (iii) MOV TH0, #06H ; TH0 loads in TL0 after 150 clock inputs 27

Program (Main Program) (iv) SETB EA ; Enable interrupts (v) SETB ET0 ; Enable T0 interrupts (vi) SETB TR0 ; Run timer T0 (vii) SJMP 2 ; Wait for ever 28

Interrupt Service Routine for T0 (i) CPL P2^6 ; CPL at 0AEH can be used in place of P2^6. 0AEH is bit address of P2.6 pin (ii) RETI ; Return from Interrupts 29

Summary

We learnt Programming the TMOD register Programming the T0 and T1 registers Programming the TCON register Programs for mode 0 and mode 2 31

End of Lesson 05 on Programming Examples for Timers