Seminar Topics & Project Ideas On Computer Science Electronics Electrical Mechanical Engineering Civil MBA Medicine Nursing Science Physics Mathematics Chemistry ppt pdf doc presentation downloads and Abstract

Full Version: 8051 timer/counter ppt
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
8051 timer/counter

[attachment=56143]

Timers /Counters Programming

The 8051 has 2 timers/counters:
timer/counter 0
timer/counter 1
They can be used as
The timer is used as a time delay generator.
The clock source is the internal crystal frequency of the 8051.
An event counter.
External input from input pin to count the number of events on registers.
These clock pulses cold represent the number of people passing through an entrance, or the number of wheel rotations, or any other event that can be converted to pulses.

Timer

Set the initial value of registers
Start the timer and then the 8051 counts up.
Input from internal system clock (machine cycle)
When the registers equal to 0 and the 8051 sets a bit to denote time out

Counter

Count the number of events
Show the number of events on registers
External input from T0 input pin (P3.4) for Counter 0
External input from T1 input pin (P3.5) for Counter 1
External input from Tx input pin.
We use Tx to denote T0 or T1.

TMOD Register

Timer mode register: TMOD
MOV TMOD,#21H
An 8-bit register
Set the usage mode for two timers
Set lower 4 bits for Timer 0 (Set to 0000 if not used)
Set upper 4 bits for Timer 1 (Set to 0000 if not used)
Not bit-addressable

Timer Mode 1

In following, we all use timer 0 as an example.
16-bit timer (TH0 and TL0)
TH0-TL0 is incremented continuously when TR0 is set to 1. And the 8051 stops to increment TH0-TL0 when TR0 is cleared.
The timer works with the internal system clock. In other words, the timer counts up each machine cycle.
When the timer (TH0-TL0) reaches its maximum of FFH, it rolls over to 0000, and TF0 is raised.
Programmer should check TF0 and stop the timer 0.

Steps in executing an interrupt

Finish current instruction and saves the PC on stack.
Jumps to a fixed location in memory depend on type of interrupt
Starts to execute the interrupt service routine until RETI (return from interrupt)
Upon executing the RETI the microcontroller returns to the place where it was interrupted. Get pop PC from stack