You are on page 1of 6

INTRODUCTION

World of Microcontrollers

MICROCONTROLLER

VERSUS

MICROPROCESSOR

A microcontroller differs from a microprocessor in many ways. The first and most important difference is its functionality. In order the microprocessor may be used, other components such as memory or components for data transfer must be added to it. Even though the microprocessor is considered to be a powerful computer machine, the weak point is that it is not adjusted to communication to peripheral environment. Simply, in order to communicate with peripheral environment, the microprocessor must use specialized circuits added as external chips. It means in short that microprocessors are the pure heart of the computers. That is how it was when they appeared and the same is now.

On the other hand, the microcontroller is designed to be all of that in one. No other specialized external components are needed for its application because all necessary circuits which otherwise belong to peripherals are already built into it. It in any case saves the time and space needed to design a device.

PIC MICROCONTROLLERS

17

INTRODUCTION World of Microcontrollers

Interrupt in Timer Operating If the timer register consists of 8 bits, the largest number that can be written to it is 255 (for 16-bit registers it is the number 65.535). If this number is exceeded, the timer will be automatically reset and counting will start from zero. This event is called overflow. If enabled from within the program, the overflow can cause an interrupt, which gives completely new possibilities. For example, the state of registers used for counting seconds, minutes or days can be changed in an interrupt routine. The whole this process (except interrupt routine) is automatically performed behind the scenes, which enables main circuits of the microcontroller to perform regular operations normally.

The picture above illustrates the use of interrupt in timer operating. Delays of arbitrary duration with minimal interference in the main program execution can be easily obtained by assigning a prescaler to the timer. Counters If a timer is supplied with pulses over the microcontroller input pin, then it turns into a counter. Clearly, it is about the same electronic circuit. The only difference is that in this case pulses to be counted come over the microcontroller input pin and their duration (width) is mostly undefined. That is why they cannot be used for time measurement, but can be used for counting: products on an assembly line, number of axis rotation, passengers etc. (depending on sensor in use).

42

PIC MICROCONTROLLERS

INTRODUCTION World of Microcontrollers

A/D CONVERTER
External signals are usually fundamentally different from those the microcontroller understands (zero and one), so that they have to be converted in order the microcontroller can understand them. An analog-to digital converter is an electronic circuit which converts continuous signals to discrete digital numbers. In other words, this circuit converts an analog value into a binary number and forwards it to the CPU for further processing. This module is therefore used for input pin voltage measurement (analog value). The result of measurement is a number (digital value) used and processed later in the program.

Analog Input 0-Vref.

Vref.

44

PIC MICROCONTROLLERS

CHAPTER 1
Device Overview

1.2

CENTRAL PROCESSOR UNIT (CPU)

Any attempt to explain in detail the operation of CPU would take us too far. Who is anyway interested in that?! It is important to say that CPU is made in RISC technology because this fact can affect you to buy exactly this microcontroller. RISC stands for Reduced Instruction Set Computer, which gives the PIC16F877 two great advantages: Its CPU can recognize and execute only 35 simple instructions. Just to mention that in order to program other microcontrollers it is necessary to know more than 200 instructions by heart. Execution time is the same for all of them and lasts 4 clock cycles (oscillator whose frequency is stabilized by quartz crystal). The only exceptions are jump and branch instructions whose execution time is twice as long. It means that if the microcontrollers operating speed is 20MHz, execution time of each instruc tion is 200nS, i.e. the program will be executed at the speed of 5 million instruc tions per second!

60

PIC MICROCONTROLLERS

CHAPTER 1
Device Overview

RAM MEMORY
This is the third and the most complex memory unit. In this very case, it consists of two types of registers: general-purpose registers and special-function registers (SFR). Both of them are divided in for memory banks, which will be explained later in the chapter. Even though these registers are cleared when power goes off and even though they are manufactured in the same way and act similarly, their functions do not have many things in common.

62

PIC MICROCONTROLLERS

APPENDIX B
Examples

EXAMPLE 14
Sound Generating, Using Macros The common task of the microcontroller is to generate sound. Basically, it all comes to generating pulse sequence on one output pin. While doing so, the proportion of logic zero (0) to logic one (1) duration determines the tone pitch and by changing different tones, different melodies arise. Obviously, it all still remains in the field the microcontroller is specialized in. In this example, any press on push-buttons T1 and T2 generates sound. The appropriate instructions are stored in macro beep containing two arguments.
Frequency: the greater number, the higher tone BEEP MACRO freq, duration Duration: the greater number is, the longer it lasts

PIC MICROCONTROLLERS

369

You might also like