100% found this document useful (1 vote)
45 views13 pages

Unit 3

The PIC16F877A is a 40-pin Peripheral Interface Microcontroller developed in 1993, widely used in embedded applications such as smartphones and medical devices. It features five I/O ports, multiple timers, and supports various communication protocols like USART and I2C. The microcontroller's architecture includes a CPU, memory organization with RAM and ROM, and capabilities for analog-to-digital conversion, timers, and serial communication.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
45 views13 pages

Unit 3

The PIC16F877A is a 40-pin Peripheral Interface Microcontroller developed in 1993, widely used in embedded applications such as smartphones and medical devices. It features five I/O ports, multiple timers, and supports various communication protocols like USART and I2C. The microcontroller's architecture includes a CPU, memory organization with RAM and ROM, and capabilities for analog-to-digital conversion, timers, and serial communication.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

UNIT 3 PIC 16F877A

3.1 Introduction PIC Microcontroller:

PIC is a Peripheral Interface Microcontroller which was developed in


the year 1993 by the General Instruments Microcontrollers. It is controlled by
software and programmed in such a way that it performs different tasks and
controls a generation line. PIC microcontrollers are used in different new
applications such as smart phones, audio accessories and advanced medical
devices.

Fig 3.1 IC Chip’s

PIC16F877a is a 40-pin PIC Microcontroller and is used mostly in Embedded


Projects and Applications.

Few of its features are as follows:

It has five Ports on it starting from Port A to Port E.


It has three Timers in it, two of which are 8 bit Timers while 1 is 16 Bit.
It supports many communication protocols like:
 Serial Protocol.
 Parallel Protocol.
 I2C Protocol.

3.2 PIC16F877a Pin Diagram:

PIC16F877 chip is available in different types of packages. According to the


type of applications and usage, these packages are differentiated. The pin
diagram of a PIC16F877 chip in different packages is shown in the figure
below.
Fig 3.2 Pin Diagrams

Input/output ports:

PIC16F877 has 5 basic input/output ports. They are usually denoted by


PORT A (R A), PORT B (RB), PORT C (RC), PORT D (RD), and PORT E
(RE). These ports are used for input/ output interfacing. In this controller,
“PORT A” is only 6 bits wide (RA-0 to RA-7), ”PORT B” , “PORT
C”,”PORT D” are only 8 bits wide (RB-0 to RB-7,RC-0 to RC-7,RD-0 to
RD-7), ”PORT E” has only 3 bit wide (RE-0 to RE-7).

PORT-A RA-0 to RA-5 6 bit wide

PORT-B RB-0 to RB-7 8 bit wide

PORT-C RC-0 to RC-7 8 bit wide

PORT-D RD-0 to RD-7 8 bit wide

PORT-E RE-0 to RE-2 3 bit wide


All these ports are bi-directional. The direction of the port is controlled by
using TRIS(X) registers (TRIS A used to set the direction of PORT-A, TRIS
B used to set the direction for PORT-B, etc.). Setting a TRIS(X) bit ‘1’ will
set the corresponding PORT(X) bit as input. Clearing a TRIS(X) bit ‘0’ will
set the corresponding PORT(X) bit as output.

Analog input port (AN0 TO AN7) : these ports are used for interfacing
analog inputs.
TX and RX: These are the USART transmission and reception ports.
SCK: these pins are used for giving synchronous serial clock input.
SCL: these pins act as an output for both SPI and I2C modes.
DT: these are synchronous data terminals.
CK: synchronous clock input.
SD0: SPI data output (SPI Mode).
SD1: SPI Data input (SPI mode).
SDA: data input/output in I2C Mode.
CCP1 and CCP2: these are capture/compare/PWM modules.
OSC1: oscillator input/external clock.
OSC2: oscillator output/clock out.
MCLR: master clear pin (Active low reset).
Vpp: programming voltage input.
THV: High voltage test mode controlling.
Vref (+/-): reference voltage.
SS: Slave select for the synchronous serial port.
T0CK1: clock input to TIMER 0.
T1OSO: Timer 1 oscillator output.
T1OS1: Timer 1 oscillator input.
T1CK1: clock input to Timer 1.
PGD: Serial programming data.
PGC: serial programming clock.
PGM: Low Voltage Programming input.
INT: external interrupt.
RD: Read control for parallel slave port.
CS: Select control for parallel slave.
PSP0 to PSP7: Parallel slave port.
VDD: positive supply for logic and input pins.
VSS: Ground reference for logic and input/output pins.
3.3 Architecture of PIC Microcontroller:

The PIC microcontroller architecture comprises of CPU, I/O ports, memory


organization, A/D converter, timers/counters, interrupts, serial
communication, oscillator and CCP module which are discussed in detailed
below.

Fig 3.3 Architecture of PIC Microcontroller

CPU (Central Processing Unit):

It is not different from other microcontrollers CPU and the


PIC microcontroller CPU consists of the ALU, CU, MU and accumulator,
etc. Arithmetic logic unit is mainly used for arithmetic operations and to take
logical decisions. Memory is used for storing the instructions after
processing. To control the internal and external peripherals, control unit is
used which are connected to the CPU and the accumulator is used for storing
the results and further process.
 Memory Organization
 The memory module in the PIC microcontroller architecture
consists of RAM (Random Access Memory), ROM (Read Only
Memory) and STACK.
3.4 Memory Organization:

3.4.1 Random Access Memory (RAM):

RAM is an unstable memory which is used to store the data temporarily in


its registers. The RAM memory is classified into two banks, and each bank
consists of so many registers.
The RAM registers are classified into two types:
1. Special Function Registers (SFR) and
2. General Purpose Registers (GPR).

General Purpose Registers (GPR):


These registers are used for general purpose only as the name implies. For
example, if we want to multiply two numbers by using the PIC microcontroller.
Generally, we use registers for multiplying and storing the numbers in other
registers. So these registers don’t have any special function,- CPU can easily
access the data in the registers.

Special Function Registers:


These registers are used for special purposes only as the name SFR implies.
These registers will perform according to the functions assigned to them , and
they cannot be used as normal registers. For example, if you cannot use the
STATUS register for storing the data, these registers are used for showing the
operation or status of the program. So, user cannot change the function of the
SFR; the function is given by the retailer at the time of manufacturing.

Fig 3.4 Memory Organization


3.4.2 Read Only Memory (ROM):

Read only memory is a stable memory which is used to store the data
permanently. In PIC microcontroller architecture, the architecture ROM
stores the instructions or program, according to the program the
microcontroller acts. The ROM is also called as program memory, wherein
the user will write the program for microcontroller and saves it permanently,
and finally the program is executed by the CPU. The microcontrollers
performance depends on the instruction, which is executed by the CPU.
Electrically Erasable Programmable Read Only Memory (EEPROM)
In the normal ROM, we can write the program for only once we cannot use
again the microcontroller for multiple times. But, in the EEPROM, we can
program the ROM multiple times.

3.4.3 Flash Memory:

Flash memory is also programmable read only memory (PROM) in which we


can read, write and erase the program thousands of times. Generally, the PIC
microcontroller uses this type of ROM.
Stack

When an interrupt occurs, first the PIC microcontroller has to execute the
interrupt and the existing process address. Then that is being executed is
stored in the stack. After completing the execution of the interrupt, the
microcontroller calls the process with the help of address, which is stored in
the stack and get executes the process.

3.5 I/O Ports:

The series of PIC16 consists of five ports such as Port A, Port B, Port C, Port
D & Port E.
Port A is an 16-bit port that can be used as input or output port based on the
status of the TRISA (Tradoc Intelligence Support Activity) register.
Port B is an 8- bit port that can be used as both input and output port.
Port C is an 8-bit and the input of output operation is decided by the status of
the TRISC register.
Port D is an 8-bit port acts as a slave port for connection to the
microprocessor BUS.
Port E is a 3-bit port which serves the additional function of the control
signals to the analog to digital converter.

3.5.1 BUS:

BUS is used to transfer and receive the data from one peripheral to
another. It is classified into two types such as data bus and address.

Data Bus: It is used for only transfer or receives the data.

Address Bus: Address bus is used to transmit the memory address from the
peripherals to the CPU. I/O pins are used to interface the external peripherals;
UART and USART both are serial communication protocols which are used
for interfacing serial devices like GSM, GPS, Bluetooth, IR , etc.

Fig 3.5 BUS

3.6 A/D converters:

The main intention of this analog to digital converter is to convert analog


voltage values to digital voltage values. A/D module of PIC microcontroller
consists of 5 inputs for 28 pin devices and 8 inputs for 40 pin devices. The
operation of the analog to digital converter is controlled by ADCON0 and
ADCON1 special registers. The upper bits of the converter are stored in
register ADRESH and lower bits of the converter are stored in register
ADRESL. For this operation, it requires 5V of an analog reference voltage.
Fig 3.6 A/D CONVERTER

3.7 Timers/ Counters:

PIC microcontroller has four timer/counters wherein the one 8-bit timer
and the remaining timers have the choice to select 8 or 16-bit mode. Timers
are used for generating accuracy actions, for example, creating specific time
delays between two operations.
Interrupts
PIC microcontroller consists of 20 internal interrupts and three external
interrupt sources which are associated with different peripherals like ADC,
USART, Timers, and so on.
Serial Communication
Serial communication is the method of transferring data one bit at a time
sequentially over a communication channel.

USART: The name USART stands for Universal synchronous and


Asynchronous Receiver and Transmitter which is a serial communication for
two protocols. It is used for transmitting and receiving the data bit by bit over
a single wire with respect to clock pulses. The PIC microcontroller has two
pins TXD and RXD. These pins are used for transmitting and receiving the
data serially.

SPI Protocol: The term SPI stands for Serial Peripheral Interface. This
protocol is used to send data between PIC microcontroller and other
peripherals such as SD cards, sensors and shift registers. PIC microcontroller
support three wire SPI communications between two devices on a common
clock source. The data rate of SPI protocol is more than that of the USART.
I2C Protocol: The term I2C stands for Inter Integrated Circuit , and it is a
serial protocol which is used to connect low speed devices such as
EEPROMS, microcontrollers, A/D converters, etc. PIC microcontroller
support two wire Interface or I2C communication between two devices which
can work as both Master and Slave device.

Fig 3.7 Serial Communication


Oscillators:
Oscillators are used for timing generation. Pic microcontroller consist of
external oscillators like RC oscillators or crystal oscillators. Where the
crystal oscillator is connected between the two oscillator pins. The value of
the capacitor is connected to every pin that decides the mode of the operation
of the oscillator. The modes are crystal mode, high-speed mode and the low-
power mode. In case of RC oscillators, the value of the resistor & capacitor
determine the clock frequency and the range of clock frequency is 30KHz to
4MHz.

CCP module:
The name CCP module stands for capture/compare/PWM where it works
in three modes such as capture mode, compare mode and PWM mode.
Capture Mode: Capture mode captures the time of arrival of a signal, or in
other words, when the CCP pin goes high, it captures the value of the
Timer1.
Compare Mode: Compare mode acts as an analog comparator. When the
timer1 value reaches a certain reference value, then it generates an output.
PWM Mode: PWM mode provides pulse width modulated output with a 10-
bit resolution and programmable duty cycle.
3.8 Features of PIC16F877:

The PIC16FXX series has more advanced and developed features when
compared to its previous series. The important features of PIC16F877 series
is given below.
General Features:
 High performance RISC CPU.
 ONLY 35 simple word instructions.
 All single cycle instructions except for program branches which are
two cycles.
 Operating speed: clock input (200MHz), instruction cycle (200nS).
 Up to 368×8bit of RAM (data memory), 256×8 of EEPROM (data
memory), 8k×14 of flash memory.
 Pin out compatible to PIC 16C74B, PIC 16C76, PIC 16C77.
 Eight level deep hardware stack.
 Interrupt capability (up to 14 sources).
 Different types of addressing modes (direct, Indirect, relative
addressing modes).
 Power on Reset (POR).
 Power-Up Timer (PWRT) and oscillator start-up timer.
 Low power- high speed CMOS flash/EEPROM.
 Fully static design.
 Wide operating voltage range (2.0 – 5.56)volts.
 High sink/source current (25mA).
 Commercial, industrial and extended temperature ranges.
 Low power consumption (<0.6mA typical @3v-4MHz, 20µA typical
@3v-32MHz and <1 A typical standby).
 Peripheral Features
 Timer 0: 8 bit timer/counter with pre-scalar.
 Timer 1:16 bit timer/counter with pre-scalar.
 Timer 2: 8 bit timer/counter with 8 bit period registers with pre-scalar
and post-scalar.
 Two Capture (16bit/12.5nS), Compare (16 bit/200nS), Pulse Width
Modules (10bit).
 10bit multi-channel A/D converter
 Synchronous Serial Port (SSP) with SPI (master code) and I2C
(master/slave).
 Universal Synchronous Asynchronous Receiver Transmitter (USART)
with 9 bit address detection.
 Parallel Slave Port (PSP) 8 bit wide with external RD, WR and CS
controls (40/46pin).
 Brown Out circuitry for Brown-Out Reset (BOR).

Key Features:

 Maximum operating frequency is 20MHz.


 Flash program memory (14 bit words), 8KB.
 Data memory (bytes) is 368.
 EEPROM data memory (bytes) is 256.
 5 input/output ports.
 3 timers.
 2 CCP modules.
 2 serial communication ports (MSSP, USART).
 PSP parallel communication port
 10bit A/D module (8 channels)
 Analog Features
 10bit, up to 8 channel A/D converter.
 Brown Out Reset function.
 Analog comparator module.

Special Features:

 100000 times erase/write cycle enhanced memory.


 1000000 times erase/write cycle data EEPROM memory.
 Self programmable under software control.
 In-circuit serial programming and in-circuit debugging capability.
 Single 5V,DC supply for circuit serial programming
 WDT with its own RC oscillator for reliable operation.
 Programmable code protection.
 Power saving sleep modes.
 Selectable oscillator options.

3.9 PIC Microcontroller Applications:


The PIC microcontroller projects can be used in different applications, such
as peripherals, audio accessories, video games, etc. For better understanding
of this PIC microcontroller, the following project demonstrates PIC
microcontroller’s operations.

Street Light that Glows on Detecting Vehicle Movement:

The main intention of this project is to detect the movement of vehicles on


highways to switch on a block of street lights ahead of it, and also switch off
the trailing lights to conserve energy. In this project, a PIC microcontroller is
done by using assembly language or embedded C.

Fig 3.8 Street Light that Glows on Detecting Vehicle Movement

The power supply gives the power to the total circuit by stepping down,
rectifying, filtering and regulating AC mains supply. When there are no
vehicles on highway, then all lights will turn OFF so that the power can be
conserved. The IR sensors are placed on the road to sense the vehicle
movement. When there are vehicles on highway, then the IR sensor senses
the vehicle movement immediately, it sends the commands to the PIC
microcontroller to switch ON/OFF the LEDs. A bunch of LEDS will be
turned on when a vehicle come near to the sensor and once the vehicle passes
away from the sensor the intensity will become lower than the LEDs will turn
OFF
3.10 Advantages of PIC Microcontroller:
PIC microcontrollers are consistent and faulty of PIC percentage is very
less. The performance of the PIC microcontroller is very fast because of
using RISC architecture.
 When comparing to other microcontrollers, power consumption is very
less and programming is also very easy.
 Interfacing of an analog device is easy without any extra circuitry

Disadvantages of PIC Microcontroller:

The length of the program is high due to using RISC architecture (35
instructions)
One single accumulator is present and program memory is not accessible

You might also like