Upload
sumit-madaan
View
233
Download
0
Embed Size (px)
Citation preview
8/2/2019 Micro Controller Final
1/45
A
TRAINING REPORT
ON
MICRO CONTROLER
SUBMITTED IN THE PARTIAL FULFILLMENT
FOR THE AWARD OF THE
DEGREE OF BACHELOR OF TECHNOLOGY
IN
ELECTRONICS & COMMUNICATION
Submitted by:
Payal Mittal(1808220)
Submitted to:
Electronics & Communication Department
(BATCH 2008-2010)
Haryana Engineering College,
Jagadhri
(Kurukshetra University, Kurukshetra)
8/2/2019 Micro Controller Final
2/45
CERTIFICATE
8/2/2019 Micro Controller Final
3/45
ACKNOWLEDGEMENT
Perseverance, inspiration and motivation have always played a key role in any venture. It
is not just the brain that matters most, but that which guides them: The character, the heart,
generous qualities and progressive forces. What was conceived just as an idea materialized
slowly into concrete facts? The metamorphosis took endless hours of toil, had its moments
of frustration, but in the end everything seemed to have sense.
At this level of understanding it is often difficult to understand the wide spectrum of
knowledge without proper guidance & advice. Hence, I take this opportunity to express my
heartfelt gratitude to respected Er. Anurag Goyal who had faith in me and allowed me to
work on the PIC controller. And for his kind co-operation throughout the period of work
undertaken, which has been instrumented in the success of my project and for providing me
the technical knowledge and moral support to complete the work.
I would also like to pay my sincere gratitude to respected Er. Parveen, Head of the
department of Electronics, Haryana Engineering college, Jagadhri for providing me
opportunity to move with such a big corporation.
Last but not the least; I extend my gratitude to the Microsoft. It is only when you make a
presentation, realize the importance of Microsoft Power Point and only when you put
matter in order know the importance of Microsoft Word.
NIKUNJ JAIN
1808247
8/2/2019 Micro Controller Final
4/45
INDEX
Chapter 1 : Introduction to Microcontroller
Embedded System
Microcontroller Microcontroller v/s Microprocessor
Chapter 2 : Introduction to 16F877A
PIC Microcontroller
Chapter 3 : Architecture of 16F877A
Special function registers
Option registers
Intcon
Chapter 4 : Memory
Memory organization
Data Memory organization Data EEPROM and Flash Memory
Chapter 5 : Circuit Implementation
Counters
Interrupts
Power Supply
MCLR
Chapter 6 : Timers
Timer 0 Module
Timer 2 ModuleChapter 7 : Light Emitting Diode
Introducing the LED
Resistor
Seven segment display
Conclusion
Bibliography
8/2/2019 Micro Controller Final
5/45
LIST OF FIGURES
FIG. NO. DESCRIPTION
1. Pin diagram2. Memory organization3. Timer 0 module4. Timer 2 module5. LED6. Resistor 7. Seven Segment Display
8/2/2019 Micro Controller Final
6/45
CHAPTER 1
INTRODUCTION
8/2/2019 Micro Controller Final
7/45
1.1 EMBEDDED SYSTEM
An Embedded System is a combination of computer hardware and software, and perhaps
additional mechanical or other parts, designed to perform a specific function. A good
example is the microwave oven. Almost every household has one, and tens of millions ofthem are used every day, but very few people realize that a processor and software are
involved in the preparation of their lunch or dinner.
This is in direct contrast to the personal computer in the family room. It too is comprised
of computer hardware and software and mechanical components (disk drives, for
example). However, a personal computer is not designed to perform a specific function.
Rather, it is able to do many different things. Many people use the term general-purpose
computer to make this distinction clear. As shipped, a general-purpose computer is a
blank slate; the manufacturer does not know what the customer will do with it. One
customer may use it for a network file server, another may use it exclusively for playing
games, and a third may use it to write the next great American novel.
Frequently, an embedded system is a component within some larger system. For example,
modern cars and trucks contain many embedded systems. One embedded system controls
the anti-lock brakes, another monitors and controls the vehicle's emissions, and a third
displays information on the dashboard. In some cases, these embedded systems are
connected by some sort of a communications network, but that is certainly not a
requirement.
At the possible risk of confusing you, it is important to point out that a general-purpose
computer is itself made up of numerous embedded systems. For example, my computer
consists of a keyboard, mouse, video card, modem, hard drive, floppy drive, and sound
cardeach of which is an embedded system. Each of these devices contains a processor
and software and is designed to perform a specific function. For example, the modem is
designed to send and receive digital data over an analog telephone line. That's it. And all
of the other devices can be summarized in a single sentence as well.
If an embedded system is designed well, the existence of the processor and software
could be completely unnoticed by a user of the device. Such is the case for a microwave
oven, VCR, or alarm clock. In some cases, it would even be possible to build an
equivalent device that does not contain the processor and software. This could be done by
8/2/2019 Micro Controller Final
8/45
replacing the combination with a custom integrated circuit that performs the same
functions in hardware. However, a lot of flexibility is lost when a design is hard-coded in
this way. It is much easier, and cheaper, to change a few lines of software than to redesign
a piece of custom hardware.
1.1.2 EXAMPLES OF EMBEDDED SYSTEM
DIGITAL WATCH
At the end of the evolutionary path that began with sundials, water clocks, and
hourglasses is the digital watch. Among its many features are the presentation of the date
and time (usually to the nearest second), the measurement of the length of an event to the
nearest hundredth of a second, and the generation of an annoying little sound at the
beginning of each hour. As it turns out, these are very simple tasks that do not require
very much processing power or memory. In fact, the only reason to employ a processor at
all is to support a range of models and features from a single hardware design.The typical
digital watch contains a simple, inexpensive 8-bit processor. Because such small
processors cannot address very much memory, this type of processor usually contains its
own on-chip ROM. And, if there are sufficient registers available, this application may
not require any RAM at all. In fact, all of the electronicsprocessor, memory, countersand real-time clocksare likely to be stored in a single chip. The only other hardware
elements of the watch are the inputs (buttons) and outputs (LCD and speaker). The watch
designer's goal is to create a reasonably reliable product that has an extraordinarily low
production cost. If, after production, some watches are found to keep more reliable time
than most, they can be sold under a brand name with a higher markup. Otherwise, a profit
can still be made by selling the watch through a discount sales channel. For lower-cost
versions, the stopwatch buttons or speaker could be eliminated. This would limit the
functionality of the watch but might not even require any software changes. And, of
course, the cost of all this development effort may be fairly high, since it will be
amortized over hundreds of thousands or even millions of watch sales
8/2/2019 Micro Controller Final
9/45
VIDEO GAME PLAYER
When you pull the Nintendo-64 or Sony Playstation out from your entertainment center,
you are preparing to use an embedded system. In some cases, these machines are more
powerful than the comparable generation of personal computers. Yet video game players
for the home market are relatively inexpensive compared to personal computers. It is the
competing requirements of high processing power and low production cost that keep
video game designers awake at night (and their children well-fed).
The companies that produce video game players don't usually care how much it costs to
develop the system, so long as the production costs of the resulting product are low
typically around a hundred dollars.
1.2 MICROCONTROLLER
A microcontroller (or MCU) is a computer-on-a-chip used to control electronic devices.
It is a type of microprocessor emphasizing self-sufficiency and cost-effectiveness, in
contrast to a general-purpose microprocessor (the kind used in a PC). A typical
microcontroller contains all the memory and nterfaces needed for a simple application,
whereas a general purpose microprocessor requires additional chips to provide these
functions.
1.2.1 INTRODUCTION
Circumstances that we find ourselves in today in the field of microcontrollers had their
beginnings in the development of technology of integrated circuits. This development has
made it possible to store hundreds of thousands of transistors into one chip. That was a
prerequisite for production of microprocessors , and the first computers were made by
adding external peripherals such as memory, input-output lines, timers and other. Further
increasing of the volume of the package resulted in creation of integrated circuits. These
integrated circuits contained both processor and peripherals. That is how the first chip
8/2/2019 Micro Controller Final
10/45
containing a microcomputer , or what would later be known as a microcontroller came
about.
1.2.2 HISTORY
it was year 1969, and a team of japanese engineers from the busicom company arrived to
united states with a request that a few integrated circuits for calculators be made using
their projects. the proposition was set to intel, and marcian hoff was responsible for the
project. since he was the one who has had experience in working with a computer (pc)
pdp8, it occured to him to suggest a fundamentally different solution instead of the
suggested construction. this solution presumed that the function of the integrated circuit is
determined by a program stored in it. that meant that configuration would be more simple,
but that it would require far more memory than the project that was proposed by japanese
engineers would require. after a while, though japanese engineers tried finding an easier
solution, marcian's idea won, and the first microprocessor was born. in transforming an
idea into a ready made product , frederico faggin was a major help to intel. he transferred
to intel, and in only 9 months had succeeded in making a product from its first
conception. intel obtained the rights to sell this integral block in 1971.
First, they bought the license from the busicom company who had no idea what treasure
they had. During that year, there appeared on the market a microprocessor called 4004.
That was the first 4-bit microprocessor with the speed of 6 000 operations per second. Not
long after that, American company CTC requested from INTEL and Texas Instruments to
make an 8-bit microprocessor for use in terminals. Even though CTC gave up this idea in
the end, Intel and Texas Instruments kept working on the microprocessor and in April of
1972, first 8-bit microprocessor appeard on the market under a name 8008. It was able to
address 16Kb of memory, and it had 45 instructions and the speed of 300 000 operations
per second. That microprocessor was the predecessor of all today's microprocessors. Intel
kept their developments up in April of 1974, and they put on the market the 8-bit
processor under a name 8080 which was able to address 64Kb of memory, and which had
75 instructions, and the price began at $360 microprocessors.
8/2/2019 Micro Controller Final
11/45
At the WESCON exhibit in United States in 1975, a critical event took place in the
history of microprocessors. The MOS Technology announced it was marketing
microprocessors 6501 and 6502 at $25 each, which buyers could purchase immediately.
This was so sensational that many thought it was some kind of a scam, considering that
competitors were selling 8080 and 6800 at $179 each. As an answer to its competitor,
both Intel and Motorola lowered their prices on the first day of the exhibit down to $69.95
per microprocessor. Motorola quickly brought suit against MOS Technology and Chuck
Peddle for copying the protected 6800. MOS Technology stopped making 6501, but kept
producing 6502. The 6502 was a 8-bit microprocessor with 56 instructions and a
capability of directly addressing 64Kb of memory. Due to low cost , 6502 becomes very
popular, so it was installed into computers such as: KIM-1, Apple I, Apple II, Atari,
Comodore, Acorn, Oric, Galeb, Orao, Ultra, and many others. Soon appeared several
makers of 6502 (Rockwell, Sznertek, GTE, NCR, Ricoh, and Comodore takes over MOS
Technology) which was at the time of its prosperity sold at a rate of 15 million processors
a year!Others were not giving up though. Frederico Faggin leaves Intel, and starts his own
Zilog Inc.In 1976 Zilog announced the Z80.
During the making of this microprocessor, Faggin made a pivotal decision. Knowing that
a great deal of programs have been already developed for 8080, Faggin realized that many
would stay faithful to that microprocessor because of great expenditure which redoing of
all of the programs would result in. Thus he decided that a new processor had to be
compatible with 8080, or that it had to be capable of performing all of the programs
which had already been written for 8080. Beside these characteristics, many new ones
have been added, so that Z80 was a very powerful microprocessor in its time. It was able
to address directly 64 Kb of memory, it had 176 instructions, a large number of registers,
a built in option for refreshing the dynamic RAM memory, single-supply, greater speed
of work etc. Z80 was a great success and everybody converted from 8080 to Z80. It could
be said that Z80 was without a doubt commercially most successful 8-bit microprocessor
of that time. Besides Zilog, other new manufacturers like Mostek, NEC, SHARP, and
SGS also appeared. Z80 was the heart of many computers like Spectrum, Partner,
TRS703, Z-3 .
8/2/2019 Micro Controller Final
12/45
In 1976, Intel came up with an improved version of 8-bit microprocessor named 8085.
However, Z80 was so much better that Intel soon lost the battle. Altough a few more
processors appeared on the market (6809, 2650, SC/MP etc.), everything was actually
already decided. There weren't any more great improvements to make manufacturers
convert to something new, so 6502 and Z80 along with 6800 remained as main
representatives of the 8-bit microprocessors of that time.
1.3 Microcontrollers Versus Microprocessors
Microcontroller differs from a microprocessor in many ways. First and the most
important is its functionality. In order for a microprocessor to be used, other components
such as memory, or components for receiving and sending data must be added to it. Inshort that means that microprocessor is the very heart of the computer. On the other hand,
microcontroller is designed to be all of that in one. No other external components are
needed for its application because all necessary peripherals are already built into it. Thus,
we save the time and space needed to construct devices.
A microprocessor contains a control unit, ALU, and Registers
Limited to no I/O
A microcontroller contain a control unit, ALU, Registers, memory, I/O and other
peripherals inside the chip.
Both come in 8, 16, and 32 bit models
Difference is the number of bits that the processor can operate on in one
instruction
8/2/2019 Micro Controller Final
13/45
CHAPTER 2
INTRODUCTION TO
16F877A
8/2/2019 Micro Controller Final
14/45
2.1 THE PIC MICROCONTROLLER
Although microcontrollers were being developed since early 1970' s real boom
came in mid 1990' s. A company named Microchip made its first simple microcontroller,which they called PIC. Originally this was developed as a supporting device for POP
computers to control its peripheral devices, and therefore' named as PIC, Peripheral
Interface Controller. Thus all the chips developed by Microchip have been named as a
class by themselves and called PIC. Microchip itself does not use this term anymore to
describe their microcontrollers, however use PIC as part of product name. they call their
products MCU's.
A large number of microcontroller designs are available from microchip.
Depending upon the architecture, memory layout and processing power. They have been
classified as low range, mid range, high range and now digital signal processing
microcontrollers.
The beauty of these devices is their easy availability, low cost and easy
programming and handling. This has made PIC microcontrollers as the apple of hobbyists
and students eyes. We shall be talking about mid-range PIC microcontrollers, and use
PIC16F877A rototype in this manual to explore them. Knowledge gained by learning and
exploring one microcontroller is almost 90% applicable on other microcontrollers of the
same family The only difference is in availability of resources on different chips. General
organization of PIC Microcontrollers. Although we shall talk in detail on various aspect of
these chips in relevant sections, here I would like to give a brief introduction on the overall
business involved.
Fig shows the pin out details of a very popular 40 pin In PIC microcontroller,
PIC16F877, as you can see that each pin has been assigned a number of functions.
Sometimes two and sometimes three. This situation is very common in microcontroller, as
there is always more which your microcontroller
8/2/2019 Micro Controller Final
15/45
Can offer, yet the number of pins on a given package is limited. In a given
circuit/application a pin is usually tied to a specific job, and all functionality q a pin is
usually not required, however you make opt to use the specific pin your own way.
The specific function of a pin is selected by configuring various bits of internal
registers. The number and names of these special function registers (SFRs) vary from
device to device as some devices have limited functionality while others have more.
Nevertheless if we are talking about a function which is present in both devices, its SFR
will be same. The selection and settings of these SFR's is the key to successful
programming. It is therefore mandatory to go through the data sheets of the device before
starting a project.
Second important thing to know is that the devices with same number of R
microchip), are all pin-compatible. Which means if you design a project four Pin PIC
microcontrol1er, and later want to replace the chip with another 40 pin PIC microcontroller
are all compatible. It is also good to know that a pin labeled as lets say RBO is plotted, on
pin 33 of PIC l6F877, but the same pin is available on pin 6 in 18 pin PIC1F628 the pins
are functionally same, as long as their names are same. So if you develop all a project
while experimenting on. 18F452 using pin RBO, after successful testing you want to
8/2/2019 Micro Controller Final
16/45
transport the project to an 18 pm device, which also has RBO on It, apart form pin number
on package, and recompiling the program, you don have to bother much about anything
else.
8/2/2019 Micro Controller Final
17/45
CHAPTER 3
ARCHITECTURE OF
16F877A
8/2/2019 Micro Controller Final
18/45
3.1 SPECIAL FUNCTION REGISTERSThe Special Function Registers are registers used by the CPU and peripheral
modules for controlling the desired operation of the device. These registers areimplemented as static RAM. A list of these registers is given in Table 2-1. The Special
Function Registers can be classified into two sets: core (CPU) and peripheral. Thoseregisters associated with the core functions are described in detail in this section. Thoserelated to the operation of the peripheral features are described in detail in the peripheralfeatures section.
8/2/2019 Micro Controller Final
19/45
3.2 OPTION_REG REGISTER
The OPTION_REG Register is a readable and writable register, which contains various
control bits to configure the TMR0 prescaler/WDT postscaler (single assignable register
known also as the prescaler), the external INT interrupt, TMR0 and the weak pull-ups on.
PORTB.
8/2/2019 Micro Controller Final
20/45
3.3 INTCON REGISTER
The INTCON register is a readable and writable register,which contains various enable and
flag bits for the TMR0 register overflow, RB port change and external RB0/INT pininterrupts.
8/2/2019 Micro Controller Final
21/45
8/2/2019 Micro Controller Final
22/45
CHAPTER 4
MEMORY
8/2/2019 Micro Controller Final
23/45
4.1 MEMORY ORGANIZATION
There are three memory blocks in each of the PIC16F87XA devices. The program memory
and data memory have separate buses so that concurrent access can occur
and is detailed in this section. Data Eeprom And Flash Program Memory.
Fig.-
Memory organization
8/2/2019 Micro Controller Final
24/45
The PIC16F87XA devices have a 13-bit program counter capable of addressing an 8K
word x 14 bit program memory space. The PIC16F876A/877A devices have 8K words x
14 bits of Flash program memory, while PIC16F873A/874A devices have 4K words x 14
bits. Accessing a location above the physically implemented address will cause a
wraparound.
The Reset vector is at 0000h and the interrupt vector is at 0004h.
8/2/2019 Micro Controller Final
25/45
4.2 DATA MEMORY ORGANIZATION
The data memory is partitioned into multiple banks which contain the General
Purpose Registers and the pecial Function Registers. Bits RP1 (Status) and RP0
(Status) are the bank select bits. Each bank extends up to 7Fh (128 bytes).
The lower locations of each bank are reserved for the Special Function Registers.
Above the Special Function Registers are General Purpose Registers, implemented as static
RAM. All implemented banks contain Special Function Registers. Some frequently used
Special Function Registers from one bank may be mirrored in another bank for code
reduction and quicker access.
8/2/2019 Micro Controller Final
26/45
4.3 DATA EEPROM AND FLASH PROGRAM MEMORY
Although there are many models of microcontrollers in the PIC family, they all
share some common features, such as program memory, data memory, I/O ports, andtimers..The data EEPROM and Flash program memory is readable and writable during
normal operation (over the full VDD range). This memory is not directly mapped in the
register file space. Instead, it is indirectly addressed through the Special Function
Registers. There are six SFRs used to read and write this memory:
EECON1
EECON2
EEDATA
EEDATH
EEADR
EEADRH
When interfacing to the data memory block, EEDATA holds the 8-bit data for
read/write and EEADR holds the address of the EEPROM location being accessed.
These devices have 128 or 256 bytes of data EEPROM (depending on the device),
with an address range from 00h to FFh. On devices with 128 bytes, addresses from 80h to
FFh are unimplemented and will wraparound to the beginning of data EEPROM memory.
When writing to unimplemented locations, the on-chip charge pump will be turned off.
When interfacing the program memory block, the EEDATA and EEDATH
registers form a two-byte word that holds the 14-bit data for read/write and the EEADR
and EEADRH registers form a two-byte word that holds the 13-bit address of the program
memory location being accessed. These devices have 4 or 8K words of program Flash,
with an address range from 0000h to 0FFFh for the PIC16F873A/874A and 0000h to
1FFFh for the PIC16F876A/877A. Addresses above the range of the respective device will
wraparound to the beginning of program memory.
The write/erase voltages are generated by an on-chip charge pump, rated to operate
over the voltage rangeof the device for byte or word operations.
8/2/2019 Micro Controller Final
27/45
4.3.1 REGISTERS LINKING TO MEMORY OPERATION
8/2/2019 Micro Controller Final
28/45
CHAPTER 5
CIRCUIT
IMPLEMENTATION
8/2/2019 Micro Controller Final
29/45
5.1 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 thiscase pulses to be counted come through the ports and their duration (width) is mostly not
defined. That is why they cannot be used for time measurement, but can be used to measure
anything else: products on an assembly line, number of axis rotation, passengers etc.
(depending on sensor in use).
Watchdog Timer
As name itself indicates a lot about its purpose. Watchdog Timer is a timer
connected to a completely separate RC oscillator within the microcontroller.
If the watchdog timer is enabled, every time it counts up to end, the microcontroller
reset occurs and program execution starts from the first instruction. The point is to prevent
this from happening by using a specific command. The whole idea is based on the fact that
every program is executed in several longer or shorter loops.
If instructions which reset the watchdog timer are set on the appropriate program
locations, besides commands being regularly executed, then the operation of watchdog
timer will not affect program execution. If for any reason (usually electrical noises in
industry), the program counter "gets stuck" on some memory location from which there is
no return, the watchdog will .not be cleared and there registers value being constantly
incremented will reach the maximum! Reset occurs .
8/2/2019 Micro Controller Final
30/45
5.2 INTERRUPTS
The subject of interrupts is probably' be the longest and most difficult to go
through. There is no easy way of explaining interrupts, but hopefully by the end of thissection you will be able to implement interrul1t into your own programs. We have split the
section into two parts. This is to help break the subjects up, and to give you, a break. So
what is an interrupt? Well, as the name suggest an interrupt is a process or a signal that
stops a microprocessor/microcontroller. What it is doing so that something else can happen.
Let me give you an every day example. at home, chatting to someone. Suddenly the
telephone rings. You stop chatting and pick up the telephone to speak to the caller. When
you have finished your telephone conversation, you go back to chatting to the person
before telephone rang. You can think of the main routine as you chatting to person before
the telephone ringing causes you to interrupt your chatting, and the interrupt routine is the
process of talking on the telephone. When the telephone conversation has ended, you then
back to your main routine of chatting. This example is exactly how an interrupt ca~
processor to act. The main program is running, performing some function in a circuit, but
when an interrupt occurs the main program halts while another routine is carried out. When
this routine finishes, the processor goes back to the main routine again. The PIC has 4
sources of interrupt. They can be split into two groups. Two are sources of interrupts that
can be applied externally to the PIC, while the other two are internal processes. We are
going to explain the two external ones here. The other two will be explained in timers and
storing data.
If you look at the pin-out of the PIC, you will see that pin 33 shows it is RBO/INT.
Now, RBO is obviously Port B bit O. The INT symbolizes that it can also be configures as
an external interrupt pin. Also, Port B bits 4 to 7 can also be used for interrupts. Before we
can use the INT or other Port B pins, we need to do two things. First we need to tell the
PIC that we are going to use interrupts. Secondly, we need to specify which port B pin we
will be using as an interrupt and not as an I/O pin.
8/2/2019 Micro Controller Final
31/45
Inside the PIC there is a register called iNTCON, and is at address 0Bh. Within this register
there are 8 bits that can be enabled or disabled. Bit 7 of INTCON is called GIE. This is the
Global Interrupt Enable. Setting this to I tells the PIC that we are going to use an interrupt.
Bit 4 of INTCON is called INTE, which means interrupt Enable. Setting this bit to I tells
the PIC that RBO will be an interrupt pin. Setting bit 3, called RBIE, tells the PIC that we
will be using Port B bits 4 to 7. Now the PIC knows when this pin goes high or low, it will
need to stop what it's doing and get on with an interrupt routine. Now, we need to tell . IC
whether the interrupt is going to be on the rising edge (OV to +5V) or the falling edge
(+5Vto 0V) transition of the signal. In other words, do we want the PIC to interrupt when
the signal goes from low to high, or from high to low. By default, this is set up to be on the
rising edge. The edge 'triggering' is set up in another register called the OPTION register, at
address 81 h. The bit we are interested in is bit 6, which is called INTEDG. Setting this to 1
will cause the PIC to interrupt on the rising edge (default state) and setting it because the
PIC to interrupt on the falling edge. If you' want the PIC to trigger o~ the edge, then you
don't need to do anything to this bit.
Ok, so now we have told the PIC which pin is going to be the interrupt, and on
which edge to trigger, what happens in the program and the PIC when interrupt occurs?
Two things happen. First, a 'flag' is set. This tells the internal processor of the PIC that an
interrupt has occurred. Secondly, the program counter which points to a particular address
within the PIC. Let's quickly look at each of these separately.
Interrupt Flag
In our INTCON register, bit 1 is the interrupt flag, called INTF. Now when any
interrupt occurs, this flag will be set to 1 while there isn't an interrupt, the flag is set to O.
And that is all it does. Now you are probably thinking 'what is the point? Well, while this
flag is set to the PIC cannot, and. will ~, pond to any other interrupt. So, let say that we use
an interrupt. The flag will be 1, and the PIC will go to our routine for processing the
interrupt. If this flag was not set to 1, and the PIC was allowed to keep responding to the
interrupt, then continually pulsing the pin will keep the PIC going back to the start of our
interruption routine will never finishing it. Going back to my example of telephone, it's like
8/2/2019 Micro Controller Final
32/45
picking up the telephone, and Just as soon as you start to speak It starts ringing again
because someone else want to talk to you. It is far better to finish one conversation, then
pick up the phone again to talk to the second person.
There is a slight drawback to this flag. Although the PIC automatically sets this flag to 1; it
doesn't set it back to 0! That ,task has to be done by the programmer - i.e. you. This is
easily done, as We are sure you can guess, and has to be done after the PIC has executed
the interrupt routine.
5.3 POWER SUPPLY
PIC Microcontroller use TTL Logic, and therefore expect a well regulated 5V
power supply. The supply may however range from 3.5 V to 5.5 V. These icrocontrollers
require very small amount of current. Indeed these devices have been labeled as nano-watt
technology devices. The logical levels are also same, a signal from 0 to about 2 V is
considered as logical 0 and a signal from 3.5 V to 4.5 V is considered as logical 1. In
order to communicate with devices using higher logical voltages, consider level
conversion.
5.4 MCLR, MASTER CLEAR
8/2/2019 Micro Controller Final
33/45
On every PIC microcontroller you will find a pin labeled as MCLR. This pin has
two basic functions. It is used to reset the microcontroller, like soft boot. As well as to put
the microcontroller into programming mode.
The MCLR pin when connected to ground, will reset the microcontroller, and keep
it in reset the microcontroller state, till the ground connection is released. After that the
microcontroller will have all its RAM reset, and program execution will begin, just like the
system has been just powered on. A 1OK pull up resistor is usually connected with the pin
to keep it high when reset switch is released.
The same pin will also work as program mode pin. When a new software is to be
downloaded into the microchip by your programming device. This can be done right in
your circuit, or by taking the IC out of circuit and putting it into the IC socket on your
programmer. We shall talk more about this in section on programming.
8/2/2019 Micro Controller Final
34/45
CHAPTER 6
TIMERS
8/2/2019 Micro Controller Final
35/45
6.1 TIMER0 MODULE
The Timer0 module timer/counter has the following features:
8-bit timer/counter
Readable and writable
8-bit software programmable prescaler
Internal or external clock select
Interrupt on overflow from FFh to 00h
Edge select for external clock
The Timer0 module and the prescaler shared with the WDT. Additional information
on the Timer0 module is available in the PICmicro Mid-Range MCU Family Reference
Manual (DS33023). Timer mode is selected by clearing bit T0CS (OPTION_REG). In
Timer mode, the Timer0 module will increment every instruction cycle (without prescaler).
If the TMR0 register is written, the increment is inhibited for the following two instruction
cycles.
The user can work around this by writing an adjusted value to the TMR0 register.
Counter mode is selected by setting bit T0CS (OPTION_REG). In Counter mode,Timer0 will increment either on every rising or falling edge of pin RA4/T0CKI. The
incrementing edge is determined by the Timer0 Source Edge Select bit, T0SE
(OPTION_REG). Clearing bit T0SE selects the rising edge. Restrictions on the
external clock input are discussed in detail in Section Using Timer0 with an External
Clock.
The prescaler is mutually exclusively shared between the Timer0 module and the
Watchdog Timer. The prescaler is not readable or writable. Section Prescaler details the
operation of the prescaler. Timer0 Interrupt The TMR0 interrupt is generated when the
TMR0 register overflows from FFh to 00h. This overflow sets bit TMR0IF (INTCON).
The interrupt can be masked by clearing bit TMR0IE (INTCON). Bit TMR0IF must be
8/2/2019 Micro Controller Final
36/45
cleared in software by the Timer0 module Interrupt Service Routine before re-enabling this
interrupt. The TMR0 interrupt cannot awaken the
processor from Sleep since the timer is shut-off during Sleep.
6.2 TIMER2 MODULE
Timer2 is an 8-bit timer with a prescaler and a postscaler. It can be used as the
PWM time base for the PWM mode of the CCP module(s). The TMR2 register is readable
and writable and is cleared on any device Reset. The input clock (FOSC/4) has a prescale
option of 1:1, 1:4 or 1:16, selected by control bits T2CKPS1:T2CKPS0 (T2CON).
The Timer2 module has an 8-bit period register, PR2. Timer2 increments from 00h until it
matches PR2 and then resets to 00h on the next increment cycle. PR2 is a readable and
writable register. The PR2 register is initialized to FFh upon Reset. The match output of
TMR2 goes through a 4-bit postscaler (which gives a 1:1 to 1:16 scaling inclusive) to
generate a TMR2 interrupt (latched in flag bit, TMR2IF (PIR1)). Timer2 can be shut-
8/2/2019 Micro Controller Final
37/45
off by clearing control bit, TMR2ON (T2CON), to minimize power consumption.
Register 7-1 shows the Timer2 Control register. Additional information on timer modules
is available in the PICmicro Mid-Range MCU Family Reference Manual (DS33023).
6.2.1 Timer2 Prescaler and Postscaler
8/2/2019 Micro Controller Final
38/45
The prescaler and postscaler counters are cleared when any of the following occurs:
a write to the TMR2 register
a write to the T2CON register
any device Reset (POR, MCLR Reset, WDT
Reset or BOR TMR2 is not cleared when T2CON is written. 7.2 Output of TMR2
The output of TMR2 (before the postscaler) is fed to the SSP module, which optionally
uses it to generate the shift clock.
8/2/2019 Micro Controller Final
39/45
CHAPTER 7
LIGHT EMITTING
DIODE (LED)
8/2/2019 Micro Controller Final
40/45
7.1 INTRODUCING THE LED
A diode is a one-way current valve, and a light emitting diode (LED) emits light
when current passes through it. Unlike the color codes on a resistor, the color of the LEDusually just tells you what color it will glow when current passes through it. The important
markings on an LED are contained in its shape. Since an LED is a one-way current valve,
you have to make sure to connect it the right way, or it wont work as intended.
Fig. shows an LEDs schematic symbol and part drawing. An LED has two
terminals. One is called the anode, and the other is called the cathode. In this activity, you
will have to build the LED into a circuit, paying attention to make sure the leads connected
to the anode and cathode are connected to the circuit properly. On the part drawing, the
anode lead is labeled with the plus-sign (+). On the schematic symbol, the anode is the
wide part of the triangle. In the part drawing, the cathode lead is the unlabeled pin, and on
the schematic symbol, the cathode is the line across the point of the triangle.
7.2 LED BUILDING AND TESTING THE LED CIRCUIT
Its important to test components individually before building them into a larger
system. This activity focuses on building and testing two different LED circuits. The first
circuit is the one that makes the LED emit light. The second circuit is the one that makes it
not emit light. In the activity that comes after this one, you will build the LED circuit into a
larger system by connecting it to the BASIC Stamp. You will then write programs that
make the BASIC Stamp cause the LED to emit light, then not emit light. By first testing
8/2/2019 Micro Controller Final
41/45
each LED circuit to make sure it works, you can be more confident that it will work when
you connect it to a BASIC Stamp.
7.3 INTRODUCING THE RESISTORA resistor is a component that resists the flow of electricity. This flow of
electricity is called current. Each resistor has a value that tells how strongly it resists
current flow. This resistance value is called the ohm, and the sign for the ohm is the Greek
letter omega: The resistor you will be working with in this activity is the 470 resistor
shown in Figure
. The resistor has two wires (called leads and pronounced leeds), one coming out of each
end. There is a ceramic case between the two leads, and its the part that resists current
flow. Most circuit diagrams that show resistors use the jagged line symbol on the left to tell
the person building the circuit that he or she must use a 470 resistor. This is called a
schematic symbol. The drawing on the right is a part drawing used in some beginner level
Stamps in Class texts to help you identify the resistor in your kit.
Resistors like the ones we are using in this activity have colored stripes that tell you
what their resistance values are. There is a different color combination for each resistance
value. For example, the color code for the 470 resistor is yellow-violet-brown. There
may be a fourth stripe that indicates the resistors tolerance. Tolerance is measured in
percent, and it tells how far off the parts true resistance might be from the labeled
resistance. The fourth stripe could be gold (5%), silver (10%) or no stripe (20%). For the
activities in this book, a resistors tolerance does not matter, but its value does. Each color
8/2/2019 Micro Controller Final
42/45
bar that tells you the resistors value corresponds to a digit, and these colors/digits are listed
in Table Figure shows how to use each color bar with the
table to determine the value of a resistor.
Here is an example that shows how Table and Figure can be used to figure out a
resistor value by proving that yellow-violet-brown is really 470 :
7.4 WHATS A 7-SEGMENT DISPLAY?
A 7-segment display is rectangular block of 7 lines of equal length that can be lit
selectively to display digits and some letters. A very common form is the 7-segment LED
display, a package with a rectangular block of 7 LEDs. Figure shows a part drawing of the
7-segment LED display you will use in this chapters activities. It has one additional LED,
a dot that can be used as a decimal point. Each of the segments (A through G) and the dot
contains a separate LED, which can be controlled individually.
Most of the pins have a number along with a label that corresponds with one of the
LED segments. Pin 5 is labeled DP, which stands for decimal point. Pins 3 and 8 are
labeled common cathode, and they will be explained when the schematic for this part is
introduced.
8/2/2019 Micro Controller Final
43/45
Figure shows a schematic of the LEDs inside the 7-segment LED display. Each
LED anode is connected to an individual pin. All the cathodes are connected together by
wire inside the part. Because all the cathodes share a common connection, the 7-segment
LED display can be called a common cathode display. By connecting either pin 3 or pin
8 of the part to Vss, you will connect all the LED cathodes to Vss.
8/2/2019 Micro Controller Final
44/45
CONCLUSION
I Would Like To Say That I Was Given A Great Chance To Study, Understand And
Learn About The Embedded Systems. and got a great opportunity to learn about a
industrial controller (PIC ) ,which is massively used all over the world on an average of
about 69 %.so , would like to thank my college to include this training as a part of studies,
Apart from the great chance to develop it also act as a great source of inspiration
and Motivation for all of us inside and out
8/2/2019 Micro Controller Final
45/45
REFERENCES
Websites :
www.microchip.com
www.enwikipedia.org
www.ccsinfo.com
http://www.microchip.com/http://www.enwikipedia.org/http://www.ccsinfo.com/http://www.microchip.com/http://www.enwikipedia.org/http://www.ccsinfo.com/