PIC Microcontroller
PIC Microcontroller
PICs are popular with both industrial developers and hobbyists alike due to their low
cost, wide availability, large user base, extensive collection of application notes, availability of
low cost or free development tools, and serial programming (and re-programming with flash
memory) capability.
Peripheral Features:
5 I/O ports (Port A, Port B, Port C, Port D and Port E).
33 I/O Pins
15 Interrupt Sources
2 CCP modules
3 Timers (two 8 bit and one 16 bit timers. Timer0 and Timer1 are 8 bit, Timer2 is 16 bit)
Timer0: 8-bit timer/counter with 8-bit prescaler
Timer1: 16-bit timer/counter with prescaler (Can be incremented during Sleep via
external crystal/clock)
Timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler
Two Capture, Compare, PWM modules (16-bit Capture input; max resolution 12.5 ns,
16-bit Compare; max resolution 200 ns, 10-bit PWM)
Synchronous Serial Port (SSP) with two modes (1. SPI (Master), 2. I2C (Master and
Slave))
USART/SCI with 9-bit address detection
Parallel Slave Port (PSP) 8 bit wide with external RD, WR and CS controls
Brown-out detection circuitry for Brown-Out Reset
Analog Features:
10 Bit, 8 channel inbuilt ADC.
Brown-Out Reset
2 Analog Comparators
Programmable on-chip voltage reference module
Programmable input multiplexing from device inputs and internal VREF
Comparator outputs are externally accessible
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).
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.
(If we want to set PORT A as an input, just set TRIS(A) bit to logical 1 and want to set PORT B
as an output, just set the PORT B bits to logical 0.)
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.
The pins RB0-RB7, RC0-RC7, and RD0-RD7 are digital I/O pins. The pins CCP1 and
CCP2, which share locations with RC1 and RC2, can be used for a PWM signal. The pins
AN0-AN7 are for analog I/O. TX and RX are for debugging I/O. The remaining pins deal with
power/ground, the clock signal, and programmer I/O.
A PIC is made of several ports. Each port is designated with a letter, RB0-RB7 are a
port. RC0-RC7 and RD0-RD7 are a port as well. RA0-RA5 and RE0-RE2 are also ports, but
with fewer pins. Some of these pins have special purposes, but most can be used as basic
input/output pins.
For example, you can set pin RB0 to be either an input pin, or an output pin. As an input
pin, the digital voltage on the pin can be read in. For example, if RB0 is connected to ground
(0v), then you would read a digital 0. If RB0 was connected to power (5v), then you would read
a digital 1.
On the other hand, if you wanted to set RBO as an output pin, you could choose to
make RB0 either be 5v, or 0v. This can be used, for example, to turn off or on a LED, or to turn
off or on a motor.