Académique Documents
Professionnel Documents
Culture Documents
Rongmei
, Instrumentation & Control Engg.
Electrical Engg. Department
NITTTR ,Chandigarh
Our world is full of integrated circuits.
We can find several of them in computers. For
example, microprocessor.
The microprocessor is an integrated circuit that
processes all functions in the computer.
But a microprocessor can not work alone .
It requires some external peripherals such as
memory(RAM & ROM), Input/Output ports ,
Timers, etc.
But the addition of external RAM,ROM, Timers
and I/O ports makes these systems bulkier and
much more expansive.
Which forced to engineers to devolve a special
type of chip having CPU (microprocessor) with a
fixed amount of memory, I/O ports and Timers.
So we do not need to add any external memory,
I/O port and timer to it.
Which reduces system cost and weight.
So we can say that microcontroller
is a CPU on a small chip with some
amount of fixed memory(RAM and
ROM), I/O ports and Timers.
Some microcontroller manufacturers
have gone far as integrating an ADC
and other peripherals.
The types of micro controller can be
classified based on internal bus width,
instruction set, memory architecture ,family
etc. some of them are given below:-
Intel 8051 (8-bit)
PIC (8-bit PIC16, PIC18, 16-bit dsPIC33 / PIC24)
FreeScale 68HC11(8-bit)
Atmel AVR(8-bit), AVR32 (32-bit)
Toshiba TLCS-870
Hitachi H8, Hitachi SuperH (32-bit), etc.
In 1989, Microchip Corporation
introduced an 8-bit microcontroller called
PIC microcontroller. (PIC16xxx)
PIC16xxx had :-
Small amount of DATA RAM and PROM.
One Timer
Few Pins for I/O ports
One ADC
After the introduction of PIC16xxx, they
have introduced an array of 8-bit
microcontrollers.
They includes the PIC families of :-
PIC10xxx
PIC12xxx
PIC14xxx
PIC16xxx
PIC18xxx
All of above are 8-bit microcontrollers.
Right now PIC18xxx and PIC16xxx
families has the highest performance of
all the families of 8-bit PIC
microcontrollers.
Right now no 8 pinPIC18xxx exists, and
this is the main reason to choose other
family members(PIC10xxx to PIC16xxx),
if our design call for small package.
STACK
EEPRO
PROM RAM
M
PC
CPU
Interru Other
pt I/O
Timers periphe
Control Ports ral
Logic OSC
PIC18 Program ROM
The maximum size of PROM is 2M
The PROM size can vary from 4k to 128k bytes.
PIC18 PROM is available in different memory
types, such as :-
UV-EPROM
Flash PROM
OTP PROM ( All of have different part numbers)
Masked PROM
UV-EPROM
Data EEPROM
We also have a small amount of EEPROM
to store Critical data, that does not need
to be changed very often.
Not all PIC18 comes with Data
EEPROM ,because it is optional.
PIC microcontroller can have from 16 to 72
pins dedicated for I/O.
The number of pins for the PIC18 package
goes from 18 to 80 at this time.
Other Peripherals
ADC (10 bit)
Timers(4)
USART(universal synchronous asynchronous
receiver/transmitter)-for serial data transfer.
Part Num PROM DATA I/O Pins ADC Timers Pin no &
RAM Package
I/O Pins 32 33 to 36
Serial Ports 1 1
12F508/509
2 7
GP5/OSC1/CLKIN GP2/ICSPDAT
3 6
GP4/OSC2 GP1/ICSPCLK
PIC
4 5
GP3/MCLR/VPP GPO/ICSPT0CKI
20
Sl. Pin. Descriptions
01 VDD Power Supply
02 OSC1, Oscillator Pin
OSC2
03 VPP Programming Voltage Input
04 GP0 to GP5 General Purpose input/
output pins (Bidirectional
except GP3)
21
Sl. Pin. Descriptions
05 CSPDAT In-circuit Serial Programming
Data pin
06 CSPCLK In-circuit Serial Programming
clock pin
07 VSS Ground
08 MCLR Master clear
09 CLKIN External Clock input
22
23
Pin Pin Buffer Descriptions
No Name Type
01 RA2 TTL Bidirectional i/o port
02 RA3 TTL Bidirectional i/o port
03 RA4/ TTL Can also be selected to be
TOCK1 the clock input to the TMRO
Timer / Counter. Output is
open drain type.
24
Pin Pin Buffer Descriptions
No Name Type
04 MCLR ST Master Clear (Reset) input/
Programming Voltage input.
This pin is an activelow
RESET to the device.
27
Pin Pin Buffer Descriptions
No Name Type
12 RB6 TTL/ST Interrupt-on-change pin
Serial Programming clock
13 RB7 TTL/ST Interrupt-on-change pin
Serial Programming data
14 VDD ------- Positive supply for logic
and Input / Output pins
28
Pin Pin Buffer Descriptions
No Name Type
15 OSC2/ -------- Oscillator Crystal output ,
CLKOUT connect to Crystal or
Resonator in crystal
oscillator mode. In RC
mode, OSC2 pin outputs
CLKOUT, which has ¼ the
frequency of OSC1
29
Pin Pin Buffer Descriptions
TTL = TTL Input; ST =
No Name Type
16 Schmitt TriggerOscillator
OSC1/ ST/ Input; Crystal input /
CLKIN CMOS External clock source input
31
To define the type of an I/O pin, you use the
TRIS register.
There are two TRIS registers, the TRISA and
the TRISB
When one bit of this register is set to '1', the
corresponding port pin shall become an
input.
When it is set to '0', then this port pin shall
become an output.
32
PIC16F84 can work with four different
configurations of an oscillator.
Microcontroller type with a crystal
oscillator (XT), and
A microcontroller with resistor-capacitor
pair (RC).
This is important because we need to
mention the type of oscillator when buying
a microcontroller.
33
C2=30p
F
XTAL
C2=30p
F
34
35
“R” should be between 3K to 100K.
Below 2.2K of “R” Oscillator become
unstable.
At 1M and above of “R” Oscillator
becomes very sensitive to noise and
humidity.
“C” should be select as per the
requirement of the clock.
The clock frequency must be divided by 4.
36
37
The main oscillator signal is divided by 4 to
produce the instruction cycle time.
38
The overall speed of the
microcontroller operation is entirely
dependent on this clock frequency.
Higher frequency -> Higher
Performance and higher power
consumption.
39
VDD
40
The microcontroller pins have multiple
functions
41
42
Peripheral Interface Controller is a
family of Micro controller by Microchip
Technology.
It Uses Harvard Architecture.
Here we have separate Data and
Program memories.
Harvard von-Neumann
Program
Data Program and
CPU CPU
Memory Memory Data
Memory
8 kB of FLASH Program Memory.
256 bytes of EEPROM Data Memory.
33 input or output pins.
20 MHz operating speed(200 ns instruction cycle)
High performance RISC CPU.
PIC 16F877 44
Only 35 simple word instructions.
Power on Reset (POR).
Power-Up Timer (PWRT) and oscillator
start-up timer.
Wide operating voltage range (2.0 –
5.56)volts.
Low power consumption .
PIC 16F877 46
A PIC CPU consists of several sub units
such as instruction decoder, ALU,
control unit, etc.
It normally supports Reduced
Instruction Set Computer (RISC)
architecture. RISC Architecture has only
35 instructions. The execution time is
very less 5 MIPS(Million Instructions per
second)
As like normal microcontrollers, the PIC
chip also has certain amount of RAM,
ROM, EEPROM, other flash memory,
etc.
8 KB of FLASH Program Memory.
256 bytes of EEPROM Data Memory.
ALU normally performs all the
arithmetic operations. One of the
operand is normally in W-Register and
second operand can be in any other
register.
Address Bus- 13 Bit
Data Bus- 8 Bit
When the power supply drops below a
certain voltage(4 v in case of PIC),it
causes PIC to reset.
TheReset function will set the Program
counter to the starting address.
A special timer that delay the start of
program execution after the PIC has
been reset on power. This time delay
allows VDD to rise to the required level.
A watch dog timer is a simple timer circuit
that performs a specific operation after a
certain period of time if something goes
wrong.
Suppose we have written a program which
is compiled successfully and when we
simulate it every time seems to work fine.
Then we program the PIC.
However after a long period of time the
program gets stuck somewhere .
What needs it this case is some kind of
reset if the program is gets stuck.
54
This is a purpose of a watchdog timer circuit.
When the WDT is enable, a counter starts at 00 and
increment by 1 unit until it reaches FF.
When it goes from FF to 00 the PIC will be reset,
irrespective of what it is doing.
The only way we can stop the WDT, from resetting the
WDT back to 00 throughout the program which is
done by the processor.
Which indicates that the processor functioning is
going on.
Watchdog timer is thus increases the system
reliability.
PIC 16F877 55
It is similar to Accumulator in 8051.
It is an 8 bit register.
It is only used for ALU operation.
Carry bit(C)
When two 8-bit operands are added ,a 9 bits
result occurs,Because the result of addition
may exceeds 256(FFH).
The 9th bit is copied in the Carry bit.
PIC 16F877
57
Bit 0 (C): Carry/borrow bit (ADDWF, ADDLW,
SUBLW, SUBWF instructions)
1 = A carry-out from the Most Significant
bit of the result occurred
0 = No carry-out from the Most
Significant bit of the result occurred.
Digit Carry
This bit indicates a Carry from the lower 4
bits.During 8 bit addition.
If set,it means there is a carry from the 3rd
bit to 4th bit position.
(1 = A carry-out from the 4th low order bit
of the result occurred
0 = No carry-out from the 4th low order bit
PIC 16F877 58
Many arithmetic and logic instructions affect
the zero flag.
if result is zero, Zbit is set, otherwise cleared.
Bit 2, (Z): Zero bit
1 = the result of an arithmetic or logic
operation is zero
0 = the result of an arithmetic or logic
operation is not zero.)
PIC 16F877 59
Used along with the SLEEP mode of PIC.
During the sleep mode the microcontroller
save lots of power.
After coming out of this mode, the CPU can
check these two status bits to determine which
kind of event is responsible to bring it out of the
SLEEP mode
Bit 4, (TO): this is a time-out bit used for timing
and counting, sleep and reset functions.
1 = after power-up, CLRWDT instruction
0 = A WDT time-out occurred
Bit 3, (PD): Power-down bit
1 = after power-up or by the CLRWDT
There are four memory banks ,each of
128 bytes in size.
For bank selection 2 bits are needed,
making the effective address 9-bit
wide.
Microchip has provided only direct
addressing mode for the register file with
7-bits address plus remaining 8th and 9th
bits frozen in the STATUS REGISTER bits
RP1:RP0.
11 = Bank 3 (180h-1FFh)
10 = Bank 2 (100h-17Fh)
01 = Bank 1 (80h-FFh)
00 = Bank 0 (00h-7Fh)
PIC 16F877 62
PIC 16F877 63
IRP bit is used for indirect addressing.
The IRP bit allows selecting either
1= Bank 2 & bank 3
0= Bank 0 & bank 1
The IPR bit and FSR decide the
effective 9 bit address.
PIC 16F877
64
65
PIC 16F877
FSR is the pointer used for indirect memory
addressing in the whole register file.
In PIC every instruction that can be used for
direct addressing may also be used in a
different way for indirect addressing.
The only difference in indirect addressing
mode is that one has to write the address
byte in FSR .
PIC 16F877 66
Different from the program counter.
Any write to PCL will cause the contents
of PCLATH to be transferred to the 13
bit PC higher locations.
PIC 16F877 67
PIC 16F877 series normally has five
input/output ports.
They are used for the input/output
interfacing with other devices/circuits.
Most of these port pins are multiplexed
for handling alternate function for
peripheral features on the devices.
The PIC 16F877 chip basically has 5
input/output ports.
PORT A
PORT B
PORT C
PORT D
PORT E
68
A PIC microcontroller is an amazingly powerful fully
featured processor with internal RAM, EEPROM FLASH
memory and peripherals.
We can use it to control our projects (or build projects
around it). So it saves us from building a circuit that
has separate external RAM, ROM and peripheral chips.
In fact PIC has an amazing number of internal peripherals.
These are divided in several categories:
Communication peripherals:
• RS232/RS485
• SPI
• USB
• Radio Frequency
• TCP/IP
• Ethernet
• CAN( Controller Area Network)
• LIN( Local Interconnect Network)
Control and Timing Peripherals:
Capture/Compare
Pulse Width Modulators
Counters/Timers
Watchdog Timers
Display Peripherals:
LED drivers
LCD drivers
Analog Peripherals:
Up to 12 bit A-D converters
Comparators and Op-Amps
Brown-Out Detectors
Low voltage Detectors
Temperature sensors
Oscillators
Voltage references
D-A Converters
Voltage Regulators
Mainly 3 Interrupt Sources :
External Interrupt–Due to external source.
Edge Sensitive RB0/INT causes this interrupt.
This interrupt wakes up processor from SLEEP.
This must be set before going into SLEEP mode.
Timer 0–Timer 0 overflow. FF to 00 overflow.
Port B Change Interrupt–A change from high to low or low
to high on port B pins RB4 to RB7 causes this interrupt.
This interrupt can wake device from SLEEP.
TIMER 0
8 Bit wide with an 8 bit prescaler.
Clocked internally by system clock which is
Fosc/4 or by external clock on RA4/TOCKI.
It generates an interrupt on overflow when
the count goes from 255 to zero.
Timer 0 always synchronizes the input clock
(when using external clock).
We can read and write timer 0 but can not
read the prescaler.
The prescaler changes its effect depending on
whether it is a timer prescaler or a watch dog
prescaler - so the same prescaler setting may
prescale by 2 or by 1 depending on its use.
TIMER 1
This is a 16 bit timer that generates an
overflow interrupt when it goes from 65535
to zero.
It has an 8 bit programmable prescaler and
you can drive it from the internal clock
(Fosc/4) or an external pin.
This timer can be used in sleep mode and
will generate a wakeup interrupt on
overflow.
Timer 1 is also read by the CCP module to
capture an event time.
Using this timer in sleep mode will use more
current.
TIMER 2
This is an 8 bit timer with an 8 bit
prescaler and an 8 bit postscaler.
It takes its input only from the internal
oscillator (Fosc/4).
This timer is used for the timebase of a
PWM when PWM is active.
It also has a period register that allows
easy control of the period
When timer 2 reaches the PR2 register
value then it resets.
This saves having to check the timer
value in software and then reset the
timer and since it is done in hardware
the operation is much faster.
In Circuit Serial Programming:
It allows microcontroller to be programmed
after being placed on a circuit board, offering
tremendous flexibility, reduced development
time, increasing manufacturing efficiency and
reducing cost.
Self Programming:
Self programming enables remote upgrades to
the Flash memory. It allows for easy code
revisions in the end user applications.
One Time Programming:
These are manufactured in high volumes
without specific software and provided
immediately for custom programming.
12, 14 and 16 bit wide instructions are
upward compatible and provided to
maximize efficiency and boost the
performance.
Instruction and Data are transferred on
separate buses avoiding, processing
bottlenecks and increasing overall system
performance.
Two stage pipelining enables one
instruction to be executed while the next
instruction is fetched.
Single wide word instructions increase
software code efficiency and reduce
required programming memory
With only 33 – 79 instructions, Programming and
Debugging tasks are easy to learn and perform.
Devices with self write options have the ability
to remotely program and upgrade the MCU
application in the field ( Flexible Flash
program Memory).
Low power capability.
Extremely Rich Peripheral set.
Optimal Cost to performance Ratio.
Data EEPROM is also available for those
applications which require secure, non volatile
memory for data that changes frequently.
PIC microcontroller is very popular. It is
used in variety of applications at each
level.
Consumer level
Motion detectors
Remote controls
Rice cookers
Battery management
Smoke detectors
Toys
In Communication
Telephone handset
Microphone control
UART Replacements
Industrial applications
Utility metering
Portable instruments
Data acquisition
Motor control: Stepper, Fan,
Brushless DC, AC inductance,
Automotive applications
Light Dimmers
Intelligent sensors
Proximity detectors
Keyless entry
Tire pressure monitors
Dash Controllers
Seat Controllers
In Appliances
Refrigerator control units
Smart relay
Delay Timers
Temperature Sensors
THANKS