PIC Microcontrollers: Know It All

Chapter 13: Program Examples

13.1 Counting Events

Counting is a useful feature for any control circuit. We may wish to count the number of times a door has opened or closed, or count a number of pulses from a rotating disc. If we count cars into a car park we would increment a file count every time a car entered, using the instruction INCF COUNT. If we needed to know how many cars were in the car park, we would of course have to reduce the count by one every time a car left. We would do this by DECF COUNT. To clear the user file COUNT to start, we would CLRF COUNT. In this way the file count would store the number of cars in the car park.

Let's look at an application.

Design a circuit that will count 10 presses of a switch and then turn an LED on and reset when the next ten presses are started. The hardware is that of Fig. 11.1 with AO as the switch input and BO as the output to the LED.

There are two ways to count, UP and DOWN. We usually count up and know automatically when we have reached 10. A computer, however, knows when it reaches a count of 10 by subtracting the count from 10. If the answer is zero, then bingo. A simpler way, however, is to start at 10 and count down to zero after 10 events we will have reached zero without doing a subtraction. Zero for the...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Digital Counters
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.