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

Similar documents
Chapter 09. Programming in Assembly

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

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

ELEG3923 Microprocessor Ch.9 Timer Programming

80C51 Block Diagram. CSE Overview 1

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

Timers and interrupts

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

CPEG300 Embedded System Design. Lecture 8 Timer

Introduction To MCS-51


CHAPTER TIMER PROGRAMMING

Lesson-3: Counters and Timers

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

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

INTERRUPTS PROGRAMMING

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

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

Embedded Controller Programming

FACULTY OF ENGINEERING LAB SHEET

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

CoE3DJ4 Digital Systems Design. Chapter 6: Interrupts

Microcontroller and Embedded Systems:

Lecture 9. Timer Operations and Programming

Chapter 09. Programming in Assembly

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

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

EE6502- MICROPROCESSOR AND MICROCONTROLLER

8051 Core Specification

Chapter 6 PROGRAMMING THE TIMERS

1. Attempt any three of the following: 15

CPEG300 Embedded System Design. Lecture 6 Interrupt System

8051 Interrupt Organization

Three criteria in Choosing a Microcontroller

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

Embedded Controller Programming II. I/O Device Programming in C Part 1: Input and Interrupts

8051 Microcontroller. Ali Ziya Alkar 1

MASSEY UNIVERSITY PALMERSTON NORTH CAMPUS

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

8051 Microcontroller

8051 Microcontroller memory Organization and its Applications

8051 Timers and Serial Port

ELEG3923 Microprocessor Ch.10 Serial Port Programming

EE 354 September 16, 2016 C Sample Programs

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

CS 320. Computer Architecture Core Architecture

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

8051 I/O and 8051 Interrupts

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

MICROPROCESSORS AND MICROCONTROLLERS MATERIAL. Features of 8051:

8051 Microcontroller

Microcontroller and Applications

Interrupt Programming: Interrupts vs. Polling Method:

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

UNIT 2 THE 8051 INSTRUCTION SET AND PROGRAMMING

C Language Programming

Interrupts, timers and counters

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

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

Microprocessors & Interfacing

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


MAHALAKSHMI ENGINEERING COLLEGE TIRUCHIRAPALLI UNIT- IV

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

SUMMER 13 EXAMINATION

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

WINTER 14 EXAMINATION

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

UBC104 Embedded Systems. Review: Introduction to Microcontrollers

User-defined Download Application Note

8051 Single Board Monitor Programming. Minmon - Yeralan & Ahluwalia. PaulMon1 & PaulMon2 - Paul Stoffregen

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

8051 Microcontroller Interrupts

UNIT THE 8051 INSTRUCTION SET AND PROGRAMMING

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

MODULE-1. Short Answer Questions

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

CHAPTER 11 INTERRUPTS PROGRAMMING

Description of the Simulator

Flash Microcontrollers. Application Note. Migrating from AT89C2051/C4051 to AT89LP2052/LP4052

Vidyalankar T.E. Sem. V [EXTC] Microprocessors and Microcontrollers I Prelim Question Paper Solution V SS (GND)

Non-Portable C-Language for Microcontroller Applications

Rev. No. History Issue Date Remark


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

TUTORIAL. Donal Heffernan University of Limerick May Tutorial D.Heffernan 2000,

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).

Chapter 2. Overview of Architecture and Microcontroller-Resources

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

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

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

8XC51RA RB RC Hardware Description

CoE3DJ4 Digital Systems Design. Chapter 5: Serial Port Operation

MODEL ANSWER WINTER 17 EXAMINATION Subject Title: Microcontroller and applications

Lab-Report Microprocessors

MCS -51 Programmer s Guide and Instruction Set

MicroConverter Technical Note uc001 MicroConverter I 2 C Compatible Interface

~: Simple Programs in 8051 assembly language :~

WZMICRO>COM

Unit-I. 1. INTRODUCTION TO MICROCONTROLLERS. Micro controller, types, selection of a microcontroller and applications

Transcription:

Equation (16 bits counter, Mode 1, 16MHz): THxTLx = 65536 - (Tt * 16.777216 e6) where: Tt: Target time x: Timer/Counter (0, 1 and 2) THx: Timer high byte TLx: Timer low byte Used Interrupts: 1 (Address, 0x0B): Timer 0 3 (Address, 0x1B): Timer 1 5 (Address, 0x2B): Timer 2 Interval of Interrupt Time (PLL = 16 MHz): Min:.06e-6 seg Max: 3.9e-3 seg Timer Counter and Interrupt Output of Pin P0.3

Software interface for Timer/Counter: Interrupt, 2 ms

Copy the program: #include <ADUC842.H> /*############################################################# // Interval for Clock 16MHz, ADuC842: // 1.- THxTLx = 0x0000 == 3.9mseg (max) // 2.- THxTLx = 0xFFFF ==.06e-6 seg (min) // Time constants are computing using: // THxTLx = 65536 - (Tt*16.777216 e6) ; Where, Tt: Target time // Principal function: // Init_Timers(Timer, Interrupt Time); // Where: Timer == {0, 1, 2 // // Microconverterkits, LLC. 2017 //############################################################# */ // Bit variables sbit TEST_TC = P0^3; // P0.3 // Variables unsigned char data TL0varp; unsigned char data TH0varp; unsigned char data TL1varp; unsigned char data TH1varp; unsigned char data TL2varp; unsigned char data TH2varp;

unsigned char data *tconst; //############################################# Timer Interrupts //################### Timer 0 Interrupt void timer0_isr() interrupt 1{ TH0 = TH0varp; TL0 = TL0varp; TEST_TC = ~TEST_TC; TR0 = 1; //################### Timer 1 Interrupt void timer1_isr() interrupt 3 { TH1 = TH1varp; TL1 = TL1varp; TEST_TC = ~TEST_TC; TR1 = 1; //################### Timer 2 Interrupt void timer2_isr() interrupt 5 { //TR2 = 0; TH2 = TH2varp; TL2 = TL2varp; TEST_TC = ~TEST_TC; TF2 = 0; TR2 = 1; //******************************************************************************* Compute Time Constants // Equation: // THxTLx = 65536 - (Tt*16777216) ; Where, Tt: Target time // Interval: // Interval for Clock: 16MHz, ADuC842 // 1.- THxTLx = 0x0000 == 3.9mseg (max) // 2.- THxTLx = 0xFFFF ==.06e-6 seg (min) unsigned char data *TimeConst(float delay_float) { unsigned int data THxTLx; static unsigned char data TLTH[2]; THxTLx = 65536 - (delay_float * 16777216) ; TLTH[0] = (THxTLx & 0x00ff); TLTH[1] = ((THxTLx >> 8) & 0x00ff); return TLTH; //******************************************************************************* // Timers initialization // Init_Timers(Timer, Interrupt Time); void Init_Timers (unsigned char TC_chan, float Def_time_seg) { tconst=timeconst(def_time_seg); switch(tc_chan){ case 0 : //------------------------------------------------------Timer/Counter 0,1 Setup TMOD = 0x01; /*Channel 0: Timer, 16 divider // Compute Time Constants (Timer 0) TL0varp=*tconst; // TL0 Controlled by Software (TR0) */

TH0varp=*(tconst+1); // TH0 TH0 = TH0varp; TL0 = TL0varp; EA = 1; // Enable interrupt ET0 = 1; //Run Timer counter: TC0 TR0 = 1; // Start timer 0 break; case 1 : TMOD = 0x10; /* Channel 1: Timer, 16 divider Controlled by Software (TR1) */ // Time Constants (Timer 1) TL1varp=*tconst; // TL1 TH1varp=*(tconst+1); // TH1 TH1 = TH1varp; TL1 = TL1varp; EA = 1; // Enable interrupt ET1 = 1; //Run Timer counter: TC1 TR1 = 1; // Start timer 1 break; case 2 : // ----------------------------------------------------- Timer/Counter 2 Setup T2CON = 0x00; /* No Hardware Control or, Serial Port Mode Timer Mode ; Autoreload */ TL2varp=*tconst; // TL2 TH2varp=*(tconst+1); // TH2 TH2 = TH2varp; TL2 = TL2varp; EA = 1; // Enable interrupt ET2 = 1; //Run Timer counter: TC2 TR2 = 1; // Start timer 2 break; //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ // Main function void main (void) { // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% XTAL CLK // Clock, 16 MHz PLLCON = 0x50; // 16MHz, ADuC842 // Principal function: // Init_Timers(Timer, Interrupt Time); Timer == {0, 1, 2; Interval of Interrupt Time: {.06e-6 to 3.9e-3, PLL = 16 MHz //Examples: Init_Timers(0, 2e-3); // Timer 0, 2 mseg (P0^3) while (1) { // Disable interrupts and Timers Run //ET0 = 0; //TR0 = 0; // Disable timer 0

Software interface for Timer/Counter: Assembler Version

NAME TC_TEST ; Program description ; Purpose: Test of Interrupt using Timer Counter ;------------------------------------------------------------------- ; Interrupt, Timer 0, Equation: ; THxTLx = 65536 - (Tt*16.777216e6) ; Where, Tt: Target time ; Note: 1 Machine Cycle, No prescaler ;------------------------------------------------------------------ ; Data Memory: ; Delay variable (TIME_1MSEG): (21H) ; Delay Constant (COUNT_1MSEG): (22H) ; ----------------------------------------------------- Clock frequency PLLCON DATA 0D7H ; -----------------------------------------------------HARDW TEST_TERMINAL EQU P0.3 ; For Timer Counter Test Copy the program: CSEG AT 00H RESET: JMP BEGIN_PROG ; It jumps interrupts segment ; -------------------- Interrupts -------------------------------- ;--------------------------------------------------------------------- ;--------------------------------------------Timer 0: 1mseg Interval, 16 MHz ;--------------------------------------------------------------------- CSEG AT 0BH MOV TL0,#077H ; TC Reload MOV TH0,#0BEH; INC TIME_1MSEG RETI ;------------------------------------------------------------------------ ;------------------------------------------------------CODE_INIT ;------------------------------------------------------------------------ CSEG AT 100H BEGIN_PROG: ;------------------------------------------------------ Stack Pointer MOV SP,#0E0H ; Stack Pointer to upper space ;---------------------------------------------------- Timer/Counter 0 Setup MOV TMOD,#01H ;Channel 0: Timer, 16 divider MOV TL0,#077H ;Time constant (1 mseg) MOV TH0,#0BEH MOV TIME_1MSEG,#00H ;RESET 1 mseg interrupts counter ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% XTAL CLK ; Clock, 16 MHz MOV PLLCON,050H; // 16MHz, ADuC842 ;------------------------------------------------------Interrupt enable MOV IE, #82H SETB TEST_TERMINAL ;Initial Conditions

AGAIN_LOOP: MOV COUNT_1MSEG,#5 CALL DEL_mseg CPL TEST_TERMINAL; JMP AGAIN_LOOP ;5 mseg ;******************************************************************** END ; ;------------------------------------------------------- COUNT_1MSEG Delay DEL_mseg: MOV TIME_1MSEG, #00H ;mseg counter to 0 SETB TR0 ;Start counter AGAIN_5: ;Wait MOV A, TIME_1MSEG; CJNE A,COUNT_1MSEG,AGAIN_5 CLR TR0 ;Stop counter MOV TIME_1MSEG,#00H ; RESET 1mseg counter, TC0 MOV TL0,#077H ; TC0 reload (1 mseg) MOV TH0,#0BEH RET ; The below is defined in data memory ;------------------------------------------------------- 1mseg Count ; Interrupt counter (1 mseg, Timer 0) DSEG AT 21H TIME_1MSEG: DS 1 ; Number of 1 mseg interrupts DSEG AT 22H COUNT_1MSEG: DS 1 END