0% found this document useful (0 votes)
53 views

Microcontrollers and Systems Lesson7

The PIC microcontroller PIC16f877a is one of the most renowned microcontrollers in the industry. This microcontroller is very convenient to use, the coding or programming of this controller is also easier. One of the main advantages is that it can be write-erase as many times as possible because it uses FLASH memory technology. It has a total number of 40 pins and there are 33 pins for input and output. PIC16F877A is used in many pic microcontroller projects. PIC16F877A also has much application
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Microcontrollers and Systems Lesson7

The PIC microcontroller PIC16f877a is one of the most renowned microcontrollers in the industry. This microcontroller is very convenient to use, the coding or programming of this controller is also easier. One of the main advantages is that it can be write-erase as many times as possible because it uses FLASH memory technology. It has a total number of 40 pins and there are 33 pins for input and output. PIC16F877A is used in many pic microcontroller projects. PIC16F877A also has much application
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Lesson 7:

PIC16F877A Microcontroller

7.1- Introduction and Features

The PIC microcontroller PIC16f877a is one of the most renowned microcontrollers in the
industry. This microcontroller is very convenient to use, the coding or programming of this
controller is also easier. One of the main advantages is that it can be write-erase as many times
as possible because it uses FLASH memory technology. It has a total number of 40 pins and
there are 33 pins for input and output. PIC16F877A is used in many pic microcontroller
projects. PIC16F877A also have much application in digital electronics circuits.

PIC16f877a finds its applications in a huge number of devices. It is used in remote sensors,
security and safety devices, home automation and many industrial instruments.
An EEPROM is also featured in it which makes it possible to store some of the information
permanently like transmitter codes and receiver frequencies and some other related data. The
cost of this controller is low and its handling is also easy. It is flexible and can be used in areas
where microcontrollers have never been used before as in microprocessor applications and
timer functions etc.
• It has a smaller 35 instructions set.
• It can operate up to 20MHz frequency with 200ns instruction cycle.
• The operating voltage is between 4.2 volts to 5.5 volts. If you provide it
voltage more than 5.5 volts, it may get damaged permanently.

By Jean de Dieu NGUIMFACK NDONGMO, PhD –EAA 1


• 8K x 14-bit words of flash program memory, 368 bytes of data memory
(RAM), 256 bytes of EEPROM data memory.
• It does not have an internal oscillator like other PIC18F46K22, PIC18F4550.
• The maximum current each PORT can sink or source is around 100mA.
Therefore, the current limit for each GPIO pin of PIC16F877A is 10 mili
ampere.
• It is available in four IC packaging such as 40-pin PDIP, 44-pin PLCC, 44-
pin TQFP, 44-pin QFN

7.2- PIN configuration and description of PIC16F877A


microcontroller

As it has been mentioned before, there are 40 pins of this microcontroller IC. It consists of two
8 bit and one 16 bit timer. Capture and compare modules, serial ports, parallel ports and five
input/output ports are also present in it. This picture shows the pinout diagram of
PIC16F877A.

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

By Jean de Dieu NGUIMFACK NDONGMO, PhD –EAA 2


program that has been burned into the IC. 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.
PORT A, 6-bit port
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 first pin of this port. This pin can also be used as an analog pin
AN0. It is built in analog to digital converter.
PIN 3: RA1/AN1: This can be the analog input 1.
PIN 4: RA2/AN2/Vref-: It can also act as the analog input2. Or negative analog reference
voltage can be given to it.
PIN 5: RA3/AN3/Vref+: It can act as the analog input 3. Or can act as the analog positive
reference voltage.
PIN 6: RA0/T0CKI:To timer0 this pin can act as the clock input pin, the type of output is
open drain.
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.
PORT E, 3-bit port
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 “read control” for parallel slave port (see port D) which will be active
low/ it can be the analog input 5
PIN 9: RE1/WR/AN6: this is also a bidirectional input output port /It can be “write-control”
for parallel slave port (see port D) which will be active low/It can be the analog input 6.
PIN 10: RE2/CS/AN7: this is also a bidirectional input output port /It can be “control select”
for parallel slave port (see port D) which will be active low/It can be the analog input 7.
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.
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.

By Jean de Dieu NGUIMFACK NDONGMO, PhD –EAA 3


PORT C, 8-bit port

PIN 15: RC0/T1OSO/T1CKI: has three functions. It is a bidirectional digital input output
port / Timer1 oscillator output / Timer1external clock input
PIN 16: RC1/T1OSI/CCP2: has three functions. It is a bidirectional digital input output port /
Timer1 oscillator input / the capture 2 input - compare 2 output - PWM 2 output.
PIN 17: RC2/CCP1: has two functions. It is a bidirectional digital input output port/ It can
be the capture 1 input/ compare 1 output/ PWM 1 output.
PIN 18: RC3/SCK/SCL: has three functions. It is a bidirectional digital input-output port/ It
can be the input-output for synchronous serial clock for SPI modes /input-output for
synchronous serial clock for I2C mode.
PIN 23: RC4/SDI/SDA: has three functions. It is a bidirectional digital input-output port / It
can be the SPI data in pin/ data input-output pin in I2C mode.
PIN 24: RC5/SDO: has two functions. It is a bidirectional digital input-output port/ It can be
the SPI data out in the SPI mode.
PIN 25: RC6/TX/CK: has three functions. It is a bidirectional digital input-output port/ It can
be the asynchronous transmit (output) data pin for USART/ synchronous clock pin.
PIN 26: RC7/RX/DT: has three functions. It is a bidirectional digital input-output port/ It
can be the USART asynchronous receive (input) data pin /synchronous data pin.

PORT D, 8-bit port

PIN 19, 20, 21, 22, 27, 28, 29, and 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 data.

PORT B, 8-bit port

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.

PIN 33: RB0/INT: has two functions. It can be a bidirectional digital input output port / can
be used as external interrupt (input) pin
PIN 34: RB1: It is a bidirectional digital input output port
PIN 35: RB2: It is a bidirectional digital input output port

By Jean de Dieu NGUIMFACK NDONGMO, PhD –EAA 4


PIN 36: RB3/PGM: has two functions. It can be a bidirectional digital input-output port / low
voltage ICSP programming enable (input) pin

PIN 37: RB4: It is a bidirectional digital input output port

PIN 38: RB5: It is a bidirectional digital input output port

PIN 39: RB6/PGC: has two functions. It can be a bidirectional digital input-output port/ It
can be used as in circuit debugger and ICSP programing clock.

PIN 40: RB7/PGD: has two functions. It can be a bidirectional digital input-output port/ It
can be used as in circuit debugger and ICSP programing data.

Note: All pins have multiple functionalities. Like PORTC pins can be used as digital input pins,
digital output pins, for UART communication, I2C communication. But, we can use one
function of each port at a time or you have to program it smartly so that you can switch between
different functionalities. Like once you need one pin to read analog signal, define it for analog
purpose and then switch to other functions like digital output etc. For beginners, we suggest
to use one pin for single functionality and you can use multi-function mode, once you
become an expert in programming.
7.3- How to program the input and output ports

• As we have studied 5 input and output ports namely PORTA, PORTB, PORTC,
PORTD and PORTE which can be digital as well as analog.
• We will configure them according to our requirements. But in case of analog
mode, the pins or the ports can only act as inputs. There is a built in A to D
converter which is used in such cases. Multiplexer circuits are also used.
• But in digital mode, there is no restriction. We can configure the ports as output
or as input. This is done through programming. For PIC the preferable
compiler is mikro C pro which can be downloaded from their website.
• There is a control register named as ‘TRIS’ which controls the direction of
ports. For different ports there are different registers such as TRISA, TRISB
TRISC, TRISD, and TRISE.
• If we set a bit of the TRIS register to 0, the corresponding port bit will act as
the digital output.
• If we set a bit of the TRIS register to 1, the corresponding port bit will act as
the digital input.

By Jean de Dieu NGUIMFACK NDONGMO, PhD –EAA 5


• For example to set the whole PORTB to output we can write the program
statement as:
TRISB=0;
• Now the port will act as the output port and we can send any value on the output
such as
PORTB=0XFF;
• FF represents all 1’s in binary i.e. FF=11111111, now all the pins of port b are
high. If we connect LEDs at all the pins then they will all start glowing in this
condition.
• If we want to negate the values of the port b we can use the statement:
PORTB=~PORTB;
• Now all the pins of the PORTB will be low.

7.4- Compiler for PIC16F877A microcontroller

Four popular compiler which are used to program pic microcontrollers are MPLAB
XC8, Mikro C for pic, PIC CCS compiler and Hi-Tech compiler.
The official compiler is MPLAB XC8 compiler which is developed by manufactures of
PIC16F877A.
We generally recommend Mikro C for pic compiler for beginners and MPLAB XC8 compiler
for those who want to learn pic microcontrollers programming from register level bare metal
concepts.

7.5- Main features of PIC16F877A microcontroller

Like all other microcontroller, PIC16F877A also provide built-in useful features as mentioned
in this list:

- Analog to digital converter module : It has 8 bit ADC module which consists of 8 channels
(AN0,…,AN7) . We can use 8 analog sensors with this microcontroller.
-TIMERS: It provides three timers: timer0, timer1 and timer2. All these timers can be used
either in timer mode or in counter mode (timer/counter). These timers are used to generate
delays, pulse width modulation (PWM), counting external events and timer interrupts.

By Jean de Dieu NGUIMFACK NDONGMO, PhD –EAA 6


Timer0 is a 8-bit timer and it can operate with internal or external clock frequency. When we
use Timer0 in timer mode, we usually operate it with internal frequency and in counter mode,
we trigger it with external clock source.
Similarly, Timer1 is a 16-bit timer and it can also operate in both modes.
Timer2 is also of 8-bit. It is used with PWM as a time base for CCP module.
EEPROM : It also has built-in Electrically erasable read only memory 256 x 8 bytes which
can used to store data permanently even if the microcontroller is switched off, data will remain
there. It is usually used with electronics lock related projects.
PWM modules: It also provide 2 CCP modules. CCP stands for capture compare PWM
modules. We can easily generate two PWM signals with this microcontroller. The maximum
resolution it supports is 10 bits (read PWM using PIC16F877A microcontroller tutorial for
more information and programming).
Serial or UART communication pins: It support one UART channel. UART pins are used
for serial communication between digital devices. RC7 pin is a transmitter or RX pin which is
pin number 26. RC6 is a receiver or TX pin which is pin number 25 (read serial
communication using pic16f877a microcontroller).
I2C Communication: PIC16F877A also support I2C communication and its has one module
for I2C communication. Pin#18/RC3 and 23/RC4 are SCL and SDA pins respectively. SCL
is a serial clock line and SDA is serial data line (read I2C communication tutorial).
Interrupts: Interrupts have wonderful applications in embedded systems field. Each one
should know about interrupts and get complete understanding about them. If not, one cannot
get command on embedded systems without programming them. PIC16F877A microcontroller
provides 8 types of interrupts namley; External interrupts, timer interrupts, PORT state
change interrupts, UART interrupt, I2C, PWM interrupts (read pic microcontroller
interrupts).
Comparator module: It has a comparator module which composed of two comparators. They
are used for comparison of analog signal similar to comparators in electronics circuits. Input
pins for these comparators are RA0, RA1, RA2 and RA3 and the output can be measured
through RA4 and RA5.
Capture/Compare/PWM Modules: Each CCP module contains a 16-bit register which can
operate as a: 16-bit capture register; 16-bit compare register; 16-bit PWM register;

By Jean de Dieu NGUIMFACK NDONGMO, PhD –EAA 7


- Capture mode: In capture mode, CCPR1H:CCPR1L captures the 16-bit value
of the timer1 register when an event occurs on pin RC2/CCP1. An event is
defined as one of the following: every falling edge, every rising edge, every 4th
rising edge, every 16th rising edge.
- Compare mode: In compare mode, the 16-bit CCPR1 register is constantly
compared against the timer1 register pair value. When a match occurs, the
RC2/CCP1 pin is: driven high, driven low, remains unchanged.
- PWM mode: In Pulse Width Modulation mode, the CCPx pin produces up to a
10 bit resolution PWM output.
Watchdog timer : WDT is a on chip separate oscillator which runs freely. It is a separate
oscillator from OSC1/CLKI. WDT will also work even if the device is in sleep mode. It is
used to wake up device from sleep mode and also used to generate watchdog timer reset.
Sleep mode: PIC16F877A also provide sleep mode operation. In this mode, device operates at
very low power. All peripherals draws minimum amount of current. Wake up from sleep mode
from interrupts resources like timer1 interrupt, uart interrupt, EEPROM write completion
operation and many others.
Brown out detection: It also has a brown out detection circuit which detects the significant
drop in power supply voltage. If supply voltage drop from a certain limit, it will generate a
interrupt signal. This configuration bit (BODEN) is used to disable or enable this circuitry.
Brown out reset : This option reset the device upon detection of brown out interrupt signal
from BODEN signal if supply voltage goes below threshold for more than 100 micro seconds,
Programmable code protection, Brown out reset will occur and device will remain reset until
the voltage raise to its nominal value. Device checks for voltage after every 72ms.
Some other momentous features are listed below:

• Power on Reset
• Multiple oscillator group
• In-Circuit Debugger
• In-Circuit Serial programming
• Low voltage ICSP programming

By Jean de Dieu NGUIMFACK NDONGMO, PhD –EAA 8

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy