Electronic Circuits - Electronic Tutorials - Electronic Hobby Projects - A Complete Electronic Resource Centre

MICROCONTROLLER TUTORIALS - 8051

Videos

Products

Sitemap

Circuits

Tutorials

8051

Introduction

Chapter 1
Types of Memory

Chapter 2
Special Function Registers

Chapter 3
Basic Registers

Chapter 4
Addressing Modes

Chapter 5
Program Flow

Chapter 6
Low Level Information

Chapter 7
Timers

Chapter 8
Serial Port Operations

Chapter 9
Interrupts

Additional Features in 8052

8052 Instruction Set

8051 Microcontroller
Timers as Event Counters

Author : Craig Steiner

Source : 8052.com

Book : The 8051/8052 Microcontroller:
       
 Architecture, Assembly Language, And Hardware Interfacing (Paperback)

USING TIMERS AS EVENT COUNTERS

We've discussed how a timer can be used for the obvious purpose of keeping track of time. However, the 8051 also allows us to use the timers to count events.

How can this be useful? Let's say you had a sensor placed across a road that would send a pulse every time a car passed over it. This could be used to determine the volume of traffic on the road. We could attach this sensor to one of the 8051's I/O lines and constantly monitor it, detecting when it pulsed high and then incrementing our counter when it went back to a low state. This is not terribly difficult, but requires some code. Let's say we hooked the sensor to P1.0; the code to count cars passing would look something like this:

JNB P1.0,$

;If a car hasn't raised the signal, keep waiting

JB P1.0,$

;The line is high which means the car is on the sensor right now

INC COUNTER

;The car has passed completely, so we count it

>>> Enter here for detail on Timers as Event Counters  <<<


<<< Click here to come back on (8051 - Timers)

<<<<  Back to 8051 / 52  Microcontroller Tutorial