Microcontroller pic 16f877 architecture and basics
1,610 views
71 slides
Jul 01, 2021
Slide 1 of 71
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
About This Presentation
What is Microcontroller, Microcontroller vs Microprocessor, Development/Classi�cation of microcontrollers, Harvard vs. Princeton Architecture, RISC AND CISC CONTROLLERS
Features of RISC, Microcontroller for Embedded Systems
10 x86 PC Embedded Applications, Choosing a Microcontroller
Criteria for...
What is Microcontroller, Microcontroller vs Microprocessor, Development/Classi�cation of microcontrollers, Harvard vs. Princeton Architecture, RISC AND CISC CONTROLLERS
Features of RISC, Microcontroller for Embedded Systems
10 x86 PC Embedded Applications, Choosing a Microcontroller
Criteria for Choosing a Microcontroller, Mechatronics, and Microcontrollers, A brief history of the PIC microcontroller, PIC Microcontrollers, Feature: PIC16F877, Simpli�ed Features.
Size: 704.88 KB
Language: en
Added: Jul 01, 2021
Slides: 71 pages
Slide Content
Microcontroller (PIC)
Basics of Microcontroller (PIC)
Nilesh Bhaskarrao Bahadure
Ph.D, ME, BE [email protected]
https://www.sites.google.com/site/nileshbbahadure/home
July 1, 2021
1 / 71
Overview
1
Syllabus
2
Course Objectives & Outcomes
3
Objectives
4
What is Microcontroller
5
Microcontroller vs Microprocessor
6
Development/Classication of microcontrollers
7
Harvard vs. Princeton Architecture
8
RISC AND CISC CONTROLLERS
Features of RISC
9
Microcontroller for Embedded Systems
10
x86 PC Embedded Applications
11
Choosing a Microcontroller
Criteria for Choosing a Microcontroller
12
Mechatronics and Microcontrollers
13
A brief history of the PIC microcontroller
14
PIC Microcontrollers
15
Feature: PIC16F877
Simplied Features
16
Pin Diagram of PIC16F877
17
CPU Architecture
18
PIC Memory Organization
19
University Questions
20
Thank You
2 / 71
Syllabus
Unit Heading No. of Lectures
Unit 1: PIC MicrocontrollersNo of lectures - 3
The PIC Microcontrollers: History, Overview and Features.
3 / 71
Course Objectives
1
To expose the students to the fundamentals of PIC Microcontroller
16F877 architecture and its Peripherals.
2
To introduce the advanced features in PIC Microcontroller 16F877.
3
To make student develop and practice assembly language and C
language programming techniques
4
To enable student demonstrate and perform hardware interfacing and
design.
4 / 71
Course Outcomes
At the end of the course, the student shall be able to,
1
Describe how PIC microcontroller and its peripherals function.
2
Interpret advanced features in PIC Microcontroller 16F877.
3
Program an embedded system in assembly and C.
4
Design, implement and test a single-processor embedded systems for
real-time applications
5 / 71
Objectives
Upon completion of this chapter, you will be able to:
1
Compare and contrast microprocessors and microcontrollers [1, 2]
2
Describe the advantages of microcontrollers for some applications
3
Explain the concept of embedded systems
4
Discuss the criteria for considering Microcontroller
5
Explain the variations of speed, packaging, memory and cost per unit
and how these aect choosing a Microcontroller
6
Compare and contrast the various members of the PIC family
7
Compare the PIC with microcontrollers oered by other manufactures.
6 / 71
What is Microcontroller
A Microcontroller is a programmable digital processor with necessary
peripherals. Both microcontrollers and microprocessors are complex
sequential digital circuits meant to carry out job according to the program
/ instructions. Sometimes analog input/output interface makes a part of
microcontroller circuit of mixed mode(both analog and digital nature).
7 / 71
Microcontroller vs Microprocessor
Figure :
8 / 71
Microcontroller vs Microprocessor...
A system designer using a general purpose microprocessor such as the
Pentium or the PowerPC must add RAM, ROM, IO ports, and timers
externally to make then functional. Although the addition of external
RAM, ROM, and IO ports makes these systems bulkier and much more
expensive, they have the advantage of versatility, enabling the designer to
decide on the amount of RAM, ROM, and IO ports needed to t the task
at hand. This is not the case with microcontrollers. A Microcontroller has
a CPU (a Microprocessor) in addition to a xed amount of RAM, ROM,
IO ports, and a timer all on a single chip.
The xed amount of ON - chip ROM, RAM, and number of IO ports in
microcontrollers makes them ideal for many applications in which cost and
space are critical. In many applications, for example a TV remote control,
there is no need for the consuming power of a 486 or even an 8086
microprocessor. In many applications, the space used, the power
consumed, and the price per unit are much critical considerations than the
computing power.
9 / 71
Microcontroller vs Microprocessor...
1
A microprocessor requires an external memory for program/data
storage. Instruction execution requires movement of data from the
external memory to the microprocessor or vice versa. Usually,
microprocessors have good computing power and they have higher
clock speed to facilitate faster computation.
2
A microcontroller has required on-chip memory with associated
peripherals. A microcontroller can be thought of a microprocessor
with inbuilt peripherals.
3
A microcontroller does not require much additional interfacing ICs for
operation and it functions as a stand alone system. The operation of
a microcontroller is multipurpose, just like a Swiss knife.
4
Microcontrollers are also called embedded controllers. A
microcontroller clock speed is limited only to a few tens of MHz.
Microcontrollers are numerous and many of them are application
specic.
10 / 71
Development/Classication of microcontrollers
Microcontrollers have gone through a silent evolution (invisible). The
evolution can be rightly termed as silent as the impact or application of a
microcontroller is not well known to a common user, although
microcontroller technology has undergone signicant change since early
1970's. Development of some popular microcontrollers is given as follows.
11 / 71
Development/Classication of microcontrollers...
Processor No. of Bits Year
Intel 4004 4 bit (2300 PMOS trans, 108 kHz) 1971
Intel 8048 8 bit 1976
Intel 8031 8 bit (ROM-less) {
Intel 8051 8 bit (Mask ROM) 1980
Microchip PIC16C64 8 bit 1985
Motorola 68HC11 8 bit (on chip ADC) {
Intel 80C196 16 bit 1982
Atmel AT89C51 8 bit (Flash memory) {
Microchip PIC 16F877 8 bit (Flash memory + ADC) {
12 / 71
Harvard vs. Princeton Architecture
Harvard vs. Princeton Many years ago, in the late 1940's, the US Government asked Harvard and
Princeton universities to come up with a computer architecture to be used
in computing distances of Naval artillery shell for defense applications.
Princeton suggested computer architecture with a single memory interface.
It is also known as Von Neumann architecture after the name of the chief
scientist of the project in Princeton University John Von Neumann (1903 -
1957 Born in Budapest, Hungary).
Harvard suggested a computer with two dierent memory interfaces, one
for the data / variables and the other for program / instructions. Although
Princeton architecture was accepted for simplicity and ease of
implementation, Harvard architecture became popular later, due to the
parallelism of instruction execution.
13 / 71
Harvard Architecture (Separate Program and Data
Memory interfaces)
Figure :
15 / 71
RISC AND CISC CONTROLLERS
There are some dierences that an Electronics Engineer must know
regarding the design aspect of microcontrollers. RISC stands for reduced
instruction set computing and CISC stands for complex instruction set
computing. As the name implies RISC perform the same operation as CISC
can perform, but on the reduced instruction. In other words, we can say
that with only few or less number of instruction compared to CISC, RISC
can perform all the operations initiated by CISC computing approach.
16 / 71
RISC AND CISC CONTROLLERS...
The CISC Approach The primary goal of CISC architecture is to complete a task in as few
lines of assembly as possible. This is achieved by building processor
hardware that is capable of understanding and executing a series of
operations.
For this particular task, a CISC processor would come prepared with a
specic instruction (we'll call it "MULT"). When executed, this
instruction loads the two values into separate registers, multiplies the
operands in the execution unit, and then stores the product in the
appropriate register. Thus, the entire task of multiplying two numbers
can be completed with one instruction.
17 / 71
RISC AND CISC CONTROLLERS...
The RISC Approach RISC processors only use simple instructions that can be executed
within one clock cycle.
Thus, the "MULT" command described above could be divided into
three separate commands: "LOAD," which moves data from the
memory bank to a register, "PROD," which nds the product of two
operands located within the registers, and "STORE," which moves
data from a register to the memory banks. In order to perform the
exact series of steps described in the CISC approach, a programmer
would need to code four lines of assembly:
LOAD A, 2:3
LOAD B, 5:2
PROD A, B
STORE 2:3, A
18 / 71
RISC AND CISC CONTROLLERS...
The RISC Approach At rst, this may seem like a much less ecient way of completing
the operation. Because there are more lines of code, more RAM is
needed to store the assembly level instructions.
The compiler must also perform more work to convert a high-level
language statement into code of this form.
19 / 71
Features of RISC
Feature 1 RISC processors have a xed instruction size. In a CISC microcontroller
such as the 8051, instructions can be 1, 2, or even 3 bytes. For example,
look at the following instructions in the 8051:
CLR C ; Clear carry ag ; 1- byte instructionADD A, #20h ; 2-byte instructionLJMP 2000 ; 3-byte instructionThis variable instruction size makes the task of the instruction decoder
very dicult because the size of the incoming instruction is never known.
In RISC architecture, the size of all instructions is xed. Therefore, the
CPU can decode the instructions quickly.
20 / 71
Features of RISC
Feature 2 One of the major characteristics of RISC architecture is a large number of
registers. ALL RISC architectures have at least 32 registers. Of these 32
registers only a few are assigned to a dedicated function.
Feature 3 RISC processors have a small instruction set. RISC processors have only
the basic instructions such as ADD, SUB, MUL, LOAD, STORE, AND,
OR, EXOR, CALL, JUMP, and so on. The limited number of instructions
is one of the criticism leveled at the RISC processor because it makes the
job of assembly language programmer much more tedious and dicult
compared to CISC programmer. This is one reason RISC processor mostly
used in high language environment such as C.
21 / 71
Features of RISC
Feature 4 The most important characteristics of the RISC processor is that more
than 95% of instructions are executed with only one clock cycle, in
contrast to CISC instructions.
Feature 5 RISC processors have separate buses for data and code. In all the x86
processors, like all other CISC computers, there is one set of buses for all
the address and another set of buses for data carrying opcodes and
operand in and out of the CPU. In RISC processors, there are four sets of
buses:
1. A set of data buses for carrying data (operand)
2. A set of address bus
for accessing the data
3. A set of buses to carry the opcodes4. A set of
address buses to access the opcodes The use use of separate buses for code and data operands is commonly
referred to as Harvard architecture.
22 / 71
Features of RISC
Feature 6 In case of RISC, however, due to the small set of instructions, they are
implemented using the hardwire method. Hardwiring of RISC insructions
takes no more than 10% of the transistors, the same will take 40 - 60% of
transistors in many CISC processors.
Feature 7 RISC uses load/store architecture. In CISC microprocessors, data can be
manipulated while it is still in memory.
23 / 71
Microcontroller for Embedded Systems
Microprocessors and microcontrollers are widely used in embedded system
products. An embedded product is controlled by its own internal
microprocessor or Microcontroller as opposed to an external controller.
Typically, in an embedded system, the microcontrollers ROM are burned
with a purpose for specic functions needed for the system. A printer is an
example of an embedded system because the processor inside it performs
one task only; namely, getting the data and printing it. Contrast this with
a Pentium based PC, which can be used for any number of applications
such as word processor, print server, bank teller terminal, video game
player, network server or internal terminal.
24 / 71
Microcontroller for Embedded Systems...
A PC can also load and run software for a variety of applications. Of
course, the reason a PC can perform myriad tasks is that it has RAM
memory and an operating system that loads the application software into
RAM and lets the CPU run it. In an embedded system, typically only one
application software is burned into ROM. An x86 PC contains or is
connected to various embedded products such as the keyboard, printer,
modem, disk controller, sound card, CD - ROM driver, mouse, and so on.
Each of these peripherals has a Microcontroller inside it that performs only
one task. For example, inside every mouse a Microcontroller performs the
task of nding the mouse's position and sending it to the PC.
25 / 71
Microcontroller for Embedded Systems...
Home Oce Auto
AppliancesTelephones Trip computerIntercomComputers Engine controlTelephoneSecurity systems Air bagSecurity systemsFax Machines ABSGarage door openersMicrowave InstrumentationAnswering machinesCopier Security systemFax machinesLaser printer Transmission controlHome computersColor Printer EntertainmentTVsPaging Climate controlCable TV tuner Keyless entryVCRCamcordersRemote controlsVideo games,cellular phonesMusical instrumentsSewing machinesLighting controlPaging Camera
Table :
26 / 71
x86 PC Embedded Applications
Although microcontrollers are the preferred choice for many embedded
systems, sometimes a Microcontroller is inadequate for the task. For this
reason, in recent years many manufactures of general purpose
microprocessors such as Intel, Freescale Semiconductors (Formerly
Motorola), and AMD (Advanced Micro Devices, Inc.) have targeted their
microprocessor for the high end of the embedded market. Intel and AMD
push their x86 processors for both the embedded and desktop PC markets.
In the early 1990s, apple computer began using the PowerPC
microprocessors (604, 603, 620 etc) in place of the 680x0 for the
Macintosh. The PowerPC microprocessor is a joint venture between IBM
and Motorola, and is targeted for the high end of the embedded market as
well as the PC market. It must be noted that when a company targets a
general purpose microprocessor for the embedded market it optimizes the
processor used for embedded systems. For this reason these processors are
often called high end embedded processors. Another chip widely used in
the high end of the embedded system design is the ARM microprocessor.
Very often the terms embedded processor and Microcontroller are used
interchangeably.
27 / 71
x86 PC Embedded Applications...
One of the most critical needs of an embedded system is to decrease
power consumption and space. This can be achieved by integrating more
functions into the CPU chip. All the embedded processors based on the
x86 and PowerPC 6xx have low power consumption in addition to some
forms of I/O, COM port, and ROM, all on a single chip. In high
performance embedded processors, the trend is to integrate more and
more functions on the CPU chip and let the designer decides which
features to use. This trend is invading PC system design as well. Normally
in designing the PC motherboard we need a CPU plus a chipset containing
I/O a cache controller, a ash ROM containing BIOS, and nally a
secondary cache memory.
28 / 71
x86 PC Embedded Applications...
Currently, because of Linux, MS- DOS, and Windows standardization,
many embedded systems use x86 PCs. In many cases, using x86 PCs for
the high end embedded applications not only saves money but also
shortens development times because a vast library of software already
exists for the Linus, DOS and Windows plate form.
29 / 71
Choosing a Microcontroller
There are ve major 8 - bit microcontrollers. They are: Freescale
Semiconductor's (Motorola) 68HC08/68HC11, Intel's 8051, Atmel's AVR,
Zilog's Z8 and PIC from Microchip technology. Each of the above
microcontrollers has a unique instruction set and register set; therefore
they are not compatible with each other. Programs written for one will not
run on the others. There are also 16 and 32 bit microcontrollers made by
various chip makers. With all these dierent microcontrollers, what criteria
for designers consider in choosing one? Three criteria in choosing
microcontrollers are as follows:
30 / 71
Choosing a Microcontroller
Choosing a Microcontroller
1
Meeting the computing needs of the task at hand eciently and cost
eectively
2
Availability of software and hardware development tools such as
compilers, assemblers, debuggers, and emulators and
3
Wide availability and reliable source of microcontrollers.
31 / 71
Criteria for Choosing a Microcontroller
1
The rst and foremost criterion in choosing a Microcontroller is that
it must meet the task at hand eciently and cost eectively. In
analyzing the needs of a Microcontroller - based project, we must rst
see whether an 8 - bit, 16 bit or 32 bit Microcontroller can best
handle the computing needs of the task most eectively. Among
other considerations in this category are:
Speed: What is the highest speed that the Microcontroller supports?
Packaging: Does it come in a40-pin DIP (dual in line package) or a
QFP (quad at package), or some other packaging format? This is
important in terms of space, assembling, and prototyping the end
product.
Power consumption:This is especially critical for battery-powered
products.
The amount of RAM and ROM on the chip.
The number of I/O pins and the timer on the chip.
Ease of upgrade to higher-performance or lower-power-consumption
versions.
32 / 71
Criteria for Choosing a Microcontroller
Cost per unit:This is important in terms of the nal cost of the product
in which a Microcontroller is used. For example, some microcontrollers
cost 50 cents per unit when purchased 1000,000 units at a time.
2
The second criterion in choosing a Microcontroller is how easy it is to
develop products around it. Key considerations include the availability
of an assembler, debugger, a code-ecient C language compiler,
emulator, technical sup-port, and both in-house and outside expertise.
In many cases, third-party vendor (i.e., a supplier other than the chip
manufacturer) support for the chip is as good as, if not better than,
support from the chip manufacturer.
33 / 71
Criteria for Choosing a Microcontroller
3
The third criterion in choosing a microcontroller is its ready
availability in needed quantities both now and in the future. For some
designers this is even more important than the rst two criteria.
Currently, of the leading 8-bit micro-controllers, the 8051 family has
the largest number of diversied (multiple source) suppliers. (Supplier
means a producer besides the originator of the microcontroller.) In
the case of the 8051, which was originated by Intel, several companies
also currently produce (or have produced in the past) the 8051.
34 / 71
Mechatronics and Microcontrollers
The microcontroller is playing a major role in an emerging eld called Mecha-
tronics. Here is an excellent summary of what the eld of Mechatronics is
all about, "Many technical processes and products in the area of mechan-
ical and electrical engineering show an increasing integration of mechanics
with electronics and information processing. This integration is between the
components (hardware) and the information-driven functions (software), re-
sulting in integrated systems called Mechatronics systems. The development
of Mechatronics systems involves nding an optimal balance between the
basic mechanical structure, sensor and actuator implementation, automatic
digital information processing and overall control, and this synergy results in
innovative solutions. The practice of Mechatronics requires multidisciplinary
expertise across a range of disciplines, such as: mechanical engineering, elec-
tronics, information technology, and decision making theories."
35 / 71
A brief history of the PIC microcontroller
In 1989, Microchip Technology Corporation introduced an 8-bit micro-controller called
the PIC, which stands for Peripheral Interface Controller. This microcontroller had small
amounts of data RAM, a few hundred bytes of on-chip ROM for the program, one timer,
and a few pins for I/O ports, all on a single chip with only 8 pins.The simplied view of
PIC microcontroller is shown in Figure 4. It is amazing that a company that began with
such a humble product became one of the leading suppliers of 8-bit microcontrollers in
less than a decade. At the time of this writing, Microchip is the number-one supplier of
8-bit microcontrollers in the world. Since the introduction of the PIC16xxx, they have
introduced an array of 8-bit microcontrollers too numerous to list here. They include
the PIC families of 10xxx, 12xxx, 14xxx, 16xxx, 17xxx, and 18xxx. They are all 8-bit
processors, meaning that the CPU can work on only 8 bits of data at a time. Data
larger than 8 bits has to be broken into 8-bit pieces to be processed by the CPU. One of
the problems with the PIC family is that they are not all 100% upwardly compatible in
terms of software when going from one family to another family. For example, while the
12xxx/16xxx have 12-bit and 14-bit wide instructions, the PIC18xxx instruction is 16 bits
wide with many new instructions.
36 / 71
A brief history of the PIC microcontroller
Figure :
37 / 71
PIC Microcontrollers
PIC stands for Peripheral Interface Controller given by Microchip
Technology to identify its single-chip microcontrollers. These devices have
been very successful in 8-bit microcontrollers. The main reason is that
Microchip Technology has continuously upgraded the device architecture
and added needed peripherals to the microcontroller to suit customers'
requirements. The development tools such as assembler and simulator are
freely available on the internet at www.microchip.com.
The architectures of various PIC microcontrollers can be divided as follows.
38 / 71
PIC Microcontrollers
Low - end PIC Architectures:
Microchip PIC microcontrollers are available in various types. When PIC
microcontroller MCU was rst available from General Instruments in early
1980's, the microcontroller consisted of a simple processor executing
12-bit wide instructions with basic I/O functions. These devices are known
as low-end architectures. They have limited program memory and are
meant for applications requiring simple interface functions and small
program data memories. Some of the low-end device numbers are
1
12C5XX
2
16C5X
3
16C505
39 / 71
PIC Microcontrollers
Mid range PIC Architectures
Mid range PIC architectures are built by upgrading low-end architectures
with more number of peripherals, more number of registers and more
data/program memory. Some of the mid-range devices are
1
16C6X
2
16C7X
3
16F87X
Program memory type is indicated by an alphabet.
1
C = EPROM
2
F = Flash
3
RC = Mask ROM
Popularity of the PIC microcontrollers is due to the following
factors.
40 / 71
PIC Microcontrollers
1
Speed: Harvard Architecture, RISC architecture, 1 instruction cycle =
4 clock cycles.
2
Instruction set simplicity: The instruction set consists of just 35
instructions (as opposed to 111 instructions for 8051).
3
Power-on-reset and brown-out reset. Brown-out-reset means when
the power supply goes below a specied voltage (say 4V), it causes
PIC to reset; hence malfunction is avoided.
4
A watch dog timer (user programmable) resets the processor if the
software/program ever malfunctions and deviates from its normal
operation.
5
PIC microcontroller has four optional clock sources.
Low power crystal
Mid range crystal
High range crystal
RC oscillator (low cost).
41 / 71
PIC Microcontrollers
6
Programmable timers and on-chip ADC.
7
Up to 12 independent interrupt sources.
8
Powerful output pin control (25 mA (max.) current sourcing
capability per pin.)
9
EPROM/OTP/ROM/Flash memory option.
10
I/O port expansion capability.
11
Free assembler and simulator support from Microchip at
www.microchip.com
42 / 71
Feature: PIC16F877
1
High performance RISC CPU
2
Only 35 single word instructions to learn
3
All single cycle instructions except for program branches which are
two cycle
4
Operating speed: DC - 20 MHz clock input DC - 200 ns instruction
cycle
5
Up to 8K x 14 words of FLASH Program Memory,
Up to 368 x 8 bytes of Data Memory (RAM)
Up to 256 x 8 bytes of EEPROM Data Memory
6
Pinout compatible to the PIC16C73B/74B/76/77
7
Interrupt capability (up to 14 sources)
8
Eight level deep hardware stack
9
Direct, indirect and relative addressing modes
43 / 71
Feature: PIC16F877
10
Power-on Reset (POR)
11
Power-up Timer (PWRT) and
Oscillator Start-up Timer (OST)
12
Watchdog Timer (WDT) with its own on-chip RC oscillator for
reliable operation
13
Programmable code protection
14
Power saving SLEEP mode
15
Selectable oscillator options
16
Low power, high speed CMOS FLASH/EEPROM technology
17
Fully static design
18
In-Circuit Serial Programming (ICSP)via two pins
19
Single 5V In-Circuit Serial Programming capability
20
In-Circuit Debugging via two pins
21
Processor read/write access to program memory
44 / 71
Feature: PIC16F877
22
Wide operating voltage range: 2.0V to 5.5V
23
High Sink/Source Current: 25 mA
24
Commercial, Industrial and Extended temperature ranges
25
Low-power consumption:
<0.6 mA typical @ 3V, 4 MHz
20A typical @ 3V, 32 kHz
<1A typical standby current
26
Peripheral Features:
27
Timer0: 8-bit timer/counter with 8-bit prescaler
28
Timer1: 16-bit timer/counter with prescaler, can be incremented
during SLEEP via external crystal/clock
29
Timer2: 8-bit timer/counter with 8-bit period register, prescaler and
postscaler
30
Two Capture, Compare, PWM modules
Capture is 16-bit, max. resolution is 12.5 ns
45 / 71
Feature: PIC16F877
Compare is 16-bit, max. resolution is 200 ns
PWM max. resolution is 10-bit
31
10-bit multi-channel Analog-to-Digital converter
32
Synchronous Serial Port (SSP) with SPI (Master mode) and
I
2
C(Master/Slave)
33
Universal Synchronous Asynchronous Receiver Transmitter
(USART/SCI) with 9-bit address detection
34
Parallel Slave Port (PSP) 8-bits wide, with external RD, WR and CS
controls (40/44-pin only)
35
Brown-out detection circuitry for Brown-out Reset (BOR)
46 / 71
Simplied Features
: Simplied features
Features Description
CPU 8-bit PIC
Number of Pins40
Operating Voltage
(V)
2 to 5.5 V
Number of I/O
pins
33
ADC Module 8ch, 10-bit
Timer Module 8-bit(2), 16-bit(1)
Comparators 2
DAC Module Nil
47 / 71
Simplied Features
Communication
Peripherals
UART(1),
SPI(1), I2C(1),
MSSP(SPI/I2C)
External OscillatorUp to 20Mhz
Internal OscillatorNil
Program Memory
Type
Flash
Program Memory
(KB)
14KB
CPU Speed
(MIPS)
5 MIPS
RAM Bytes 368
Data EEPROM 256 bytes
48 / 71
Simplied Features
49 / 71
Pin Diagram of PIC16F877
50 / 71
Pin Diagram of PIC16F877...
51 / 71
Pin Diagram of PIC16F877...
1
The rst pin is the master clear pin of this IC. It resets the
microcontroller and is active low, meaning that it should constantly
be given a voltage of 5V and if 0 V are given then the controller is
reset. Resetting the controller will bring it back to the rst line of the
program that has been burned into the IC.
52 / 71
Pin Diagram of PIC16F877...
A push button and a resistor is connected to the pin. The pin is
already being supplied by constant 5V. When we want to reset the IC
we just have to push the button which will bring the MCLR pin to 0
potential thereby resetting the controller.
2
PIN 2: RA0/AN0 PORTA consists of 6 pins, from pin 2 to pin 7, all
of these are bidirectional input/output pins. Pin 2 is the rst pin of
this port. This pin can also be used as an analog pin AN0. It is built
in analog to digital converter.
3
PIN 3: RA1/AN1
This can be the analog input 1.
4
PIN 4: RA2/AN2/Vref-
It can also act as the analog input2. Or negative analog reference
voltage can be given to it.
53 / 71
Pin Diagram of PIC16F877...
5
PIN 5: RA3/AN3/Vref+
It can act as the analog input 3. Or can act as the analog positive
reference voltage.
6
PIN 6: RA0/T0CKI
To timer0 this pin can act as the clock input pin, the type of output
is open drain.
7
PIN 7: RA5/SS/AN4
This can be the analog input 4. There is synchronous serial port in
the controller also and this pin can be used as the slave select for that
port.
8
PIN 8: RE0/RD/AN5
PORTE starts from pin 8 to pin 10 and this is also a bidirectional
input output port. It can be the analog input 5 or for parallel slave
port it can act as a read control pin which will be active low.
54 / 71
Pin Diagram of PIC16F877...
9
PIN 9: RE1/WR/AN6
It can be the analog input 6. And for the parallel slave port it can act
as the write control which will be active low.
10
PIN 10: RE2/CS/A7
It can be the analog input 7, or for the parallel slave port it can act as
the control select which will also be active low just like read and write
control pins.
11
PIN 11 and 32: VDD
These two pins are the positive supply for the input/output and logic
pins. Both of them should be connected to 5V.
12
PIN 12 and 31: VSS
These pins are the ground reference for input/output and logic pins.
They should be connected to 0 potential.
13
PIN 13: OSC1/CLKIN
This is the oscillator input or the external clock input pin.
55 / 71
Pin Diagram of PIC16F877...
14
PIN 14: OSC2/CLKOUT
This is the oscillator output pin. A crystal resonator is connected
between pin 13 and 14 to provide external clock to the
microcontroller.
1
4
of the frequency of OSC1 is outputted by OSC2 in
case of RC mode. This indicates the instruction cycle rate.
56 / 71
Pin Diagram of PIC16F877...
15
PIN 15: RC0/T1OCO/T1CKI
PORTC consists of 8 pins. It is also a bidirectional input output port.
Of them, pin 15 is the rst. It can be the clock input of timer 1 or
the oscillator output of timer 2.
16
PIN 16: RC1/T1OSI/CCP2
It can be the oscillator input of timer 1 or the capture 2
input/compare 2 output/ PWM 2 output.
17
PIN 17: RC2/CCP1
It can be the capture 1 input/ compare 1 output/ PWM 1 output.
18
PIN 18: RC3/SCK/SCL
It can be the output for SPI or I2C modes and can be the
input/output for synchronous serial clock.
19
PIN 23: RC4/SDI/SDA
It can be the SPI data in pin. Or in I2C mode it can be data
input/output pin.
57 / 71
Pin Diagram of PIC16F877...
20
PIN 24: RC5/SDO
It can be the data out of SPI in the SPI mode.
21
PIN 25: RC6/TX/CK
It can be the synchronous clock or USART Asynchronous transmit
pin.
22
PIN 26: RC7/RX/DT
It can be the synchronous data pin or the USART receive pin.
23
PIN 19,20,21,22,27,28,29,30:
All of these pins belong to PORTD which is again a bidirectional
input and output port. When the microprocessor bus is to be
interfaced, it can act as the parallel slave port.
24
PIN 33-40: PORT B
All these pins belong to PORTB. Out of which RB0 can be used as
the external interrupt pin and RB6 and RB7 can be used as in-circuit
debugger pins.
58 / 71
Pin Diagram of PIC16F877...
59 / 71
Pin Diagram of PIC16F877...
60 / 71
CPU Architecture:
The CPU uses Harvard architecture with separate Program and Variable
(data) memory interface. This facilitates instruction fetch and the
operation on data/accessing of variables simultaneously.
Figure :
61 / 71
PIC Memory Organization:
PIC microcontroller has 13 bits of program memory address. Hence it can
address up to 8k of program memory. The program counter is 13-bit. PIC
16C6X or 16C7X program memory is 2k or 4k. While addressing 2k of
program memory, only 11-bits are required. Hence two most signicant
bits of the program counter are ignored. Similarly, while addressing 4k of
memory, 12 bits are required. Hence the MSB of the program counter is
ignored.
62 / 71
PIC Memory Organization:
Figure :
63 / 71
PIC Memory Organization:
The program memory map of PIC16C74A is shown in Fig 6. On reset, the
program counter is cleared and the program starts at 00H. Here a 'goto'
instruction is required that takes the processor to the mainline program.
When a peripheral interrupt, that is enabled, is received, the processor
goes to 004H. A suitable branching to the interrupt service routine (ISR) is
written at 004H.
Data memory (Register Files):
Data Memory is also known as Register File. Register File consists of two
components.
1
General purpose register le (same as RAM).
2
Special purpose register le (similar to SFR in 8051).
64 / 71
PIC Memory Organization:
Figure :
65 / 71
PIC Memory Organization:
The special purpose register le consists of input/output ports and control
registers. Addressing from 00H to FFH requires 8 bits of address.
However, the instructions that use direct addressing modes in PIC to
address these register les use 7 bits of instruction only. Therefore the
register bank select (RP0) bit in the STATUS register is used to select one
of the register banks.
In indirect addressing FSR register is used as a pointer to anywhere from
00H to FFH in the data memory.
66 / 71
PIC Memory Organization:
67 / 71
Que - 1
2018 (SLR - TJ-221) - Marks 1
PIC 16F877 devices: : : : : :bit program counter capable of addressing
: : : : : :program memory.
(a)
(b)
(c)
(d)
Answer (c) 13, 8K x 14
68 / 71
Que - 2
2018 (SLR - TJ-221) - Marks 1
PIC16F877 is a: : : : : :bit microcontroller
(a)
(b)
(c)
(d)
Answer (a) 8
69 / 71
References
Muhammad Ali Mazidi, Rolin D. McKinlay, and Danny Causey.
PIC Microcontroller and Embedded Systems - Using Assembly and C
for PIC18.
Pearson International Edition, Upper Saddle River, NJ, 2008.
Martin P. Bates.
Programming 8 - bit PIC Microcontrollers in C with Interactive
Hardware Simulation.
Newnes Press Private Limited, United Kingdom, 2008.
70 / 71
Thank you
Please send your feedback at [email protected]
For download and more information[Click Here]
71 / 71