Lecture 3
Learning:
➢ Specification of PIC16F877A
➢ Structure of the microcontroller with all
PIC16F877A I/O pins.
Microcontroller ➢ Architecture of the PIC16F877A
1
PIC (Programmable Interface Controller)
•The PIC16F877A is an 8-bit microcontroller from the PIC16 family of microcontrollers
developed by Microchip Technology. It is a versatile microcontroller suitable for a wide
range of applications, including industrial automation, consumer electronics,
automotive, and medical devices.
•It is programmed using a range of programming languages and tools, including
Microchip's MPLAB Integrated Development Environment (IDE), C compilers, and
assembly language.
2
PIC16F877A Pin Diagram
3
PIC16F877A Pin Diagram
➢ 8-bit (mid range) microcontroller with a 20 MHz clock speed
➢ 14 KB of flash memory for program storage, 368 bytes of data EEPROM, and 368 bytes of SRAM
(static random-access memory) for data storage.
➢ It has a total number of 40 pins. Total 5 I/O ports have 33 I/O pins, of which 28 are dedicated I/O
pins and 5 are multiplexed with other functions.
➢ 3 (two 8 bit and one 16 bit) timers/counters, 2 CCP (capture/compare/PWM) modules.
➢ An A/D converter (AN0-AN7) with 10-bit resolution and up to 8 channels (RA0-RA4 & RE0-RE2)
➢ An USART (Universal Synchronous/Asynchronous Receiver Transmitter), a synchronous serial
port, and an SPI interface
➢ Operating voltage range of 2.0V to 5.5V.
4
I/O Ports and Pins
•The PIC16F877A microcontroller has a total of 33 input/output (I/O) pins. Of these, 5
pins are multiplexed with other functions, which means they can be used for either I/O
or other functions depending on how they are configured. Therefore, there are 28
dedicated I/O pins that are always available for general-purpose use.
Here is a breakdown of the I/O pins on the PIC16F877A:
✓ PORTA (6 pins): RA0, RA1, RA2, RA3, RA4/T0CKI, RA5
✓ PORTB (8 pins): RB0, RB1, RB2, RB3, RB4, RB5, RB6, RB7
✓ PORTC (8 pins): RC0, RC1, RC2, RC3, RC4, RC5, RC6, RC7
✓ PORTD (8 pins): RD0, RD1, RD2, RD3, RD4, RD5, RD6, RD7
✓ PORTE (3 pins): RE0, RE1, RE2
5
I/O Ports and Pins
❑ 5 pins on the PIC16F877A microcontroller are multiplexed with other functions:
✓ RA4/T0CKI: This pin is multiplexed with Timer0 clock input (T0CKI). It can be used as a
digital I/O pin or as a clock input for Timer0.
✓ RB0/INT: This pin is multiplexed with an external interrupt input (INT). It can be used as a
digital I/O pin or as an interrupt input.
✓ RB1/PGM: This pin is multiplexed with programming voltage input (PGM). It can be used as a
digital I/O pin or as a programming voltage input during device programming.
✓ RB2/SDI: This pin is multiplexed with SPI data input (SDI) for the Serial Peripheral Interface
(SPI). It can be used as a digital I/O pin or as an input for the SPI data.
✓ RB3/SDO: This pin is multiplexed with SPI data output (SDO) for the Serial Peripheral Interface
(SPI). It can be used as a digital I/O pin or as an output for the SPI data.
6
I/O Ports and Pins In Details
PGD: Programming Data pin, used to program the microcontroller using In-Circuit Serial
Programming (ICSP).
PIN 1: MCLR: The first 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 first line of the program
that has been burned into the IC
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.
PIN 12 and 31: VSS: These pins are the ground reference for input/output and logic pins. They
should be connected to 0 potential.
7
I/O Ports and Pins In Details
PIN 13: OSC1/CLKIN: This is the oscillator input or the external clock input pin.
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. ¼ of the frequency
of OSC1 is outputted by OSC2 in case of RC mode. This indicates the instruction cycle rate.
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.
PIN 17: RC2/CCP1: It can be the capture 1 input/ compare 1 output/ PWM 1 output.
PIN 25: RC6/TX/CK: It can be the synchronous clock or USART Asynchronous transmit pin.
PIN 26: RC7/RX/DT: it can be the synchronous data pin or the USART receive pin.
8
Block Diagram of PIC16F877A
9
Timers of PIC16F877A
• The PIC16F877A microcontroller has three built-in timers, each with its own set of
registers and control bits.
• These timers are versatile peripherals that can be used for a wide range of tasks, from
basic timekeeping to advanced control and synchronization of external devices.
✓ Timer0 is an 8-bit timer.Timer0 has its own interrupt flag (TMR0IF) that can be
used to trigger an interrupt when the timer overflows.
✓ Timer1 and Timer2 are 16-bit timers that can be used for more advanced timing
and control functions.
10
Flash Program Memory
❑ The PIC16F877A has 14KB of flash program memory, which is non-volatile and can
retain its contents even when power is turned off.
❑ The memory is divided into 8K x 14 bits, meaning there are 8,192 memory locations,
and each location can hold either 14 or 16 bits of data.
❑ The flash memory can be reprogrammed up to 10,000 times, and the programming
process involves erasing the existing contents of the memory and then writing new
data to it.
❑ The flash memory is used to store the program instructions that the microcontroller
executes. These instructions are fetched from the flash memory and executed by the
microcontroller's CPU.
11
Data Memory (RAM)
❑ The PIC16F877A has 368 bytes of data memory (RAM), which is volatile and loses its
contents when power is turned off.
❑ The data memory is divided into three banks, each containing 128 bytes of memory,
and an additional 32 bytes of memory are available for special function registers
(SFRs).
❑ The data memory is used to store temporary variables and data during the
execution of the program.
12
Data Memory (EEPROM)
❑ 256 bytes of data memory in the form of Electrically Erasable Programmable Read-
Only Memory (EEPROM), which is non-volatile and can retain its contents even
when power is turned off.
❑ The EEPROM memory is typically used to store program configuration data or other
data that needs to be retained when power is lost, such as calibration values, user
preferences, or device settings.
13
USART (Universal Synchronous Asynchronous Receiver Transmitter)
❑ The USART is a communication module that provides serial communication
capabilities to the microcontroller, allowing it to send and receive data over a
communication channel.
❑ Two pins for transmission (TX) and reception (RX) of data, which can be connected
to external devices such as sensors, displays, or other microcontrollers.
❑ Supports baud rates between 300 and 115200 bits per second.
14