Sei sulla pagina 1di 57

Chapter 1

Introduction to the PIC


Microcontroller
COURSE INTRODUCTION
Chapter Outline
Microcontrollers and Embedded Processors
Introduction to Microcontroller
Microcontroller vs Microprocessor

Overview of Microcontroller Family


PIC Microcontroller Family

Microcontroller Architecture
General architecture and pin descriptions
Clock Generator
Reset
Ports
Memory Organization
Timer
Introduction to Microcontroller

What is Microcontroller?

Integrated chip that contains CPU, RAM,


some form of ROM, I/O ports, and timers
Designed for a
very specific task
to control a
particular system
reduce production
cost
Microcontroller vs Microprocessor

1.2 C vs General-Purpose P

Microcontroller Microprocessor
Devices Microchips PICs Intels x86 family (8086,
series, Atmels AVR 80286, 80386, 80486 &
series the Pentium) or
(Motorolas PowerPC
family)
Components Internal CPU, RAM, External RAM, ROM, and
ROM, I/O ports and I/O ports
timers
Application Perform specific Perform more tasks that
function: A small set of related to general
signal processing requirements: calculations
functions for digital of software, personal
signal processor computer
Microcontroller vs Microprocessor

C vs General-Purpose P (Cont..)

CPU / P
C
CPU / P DATA BUS

Register ALU Register ALU


Serial
RAM ROM I/O Timer
COM

Control Unit

Control Unit ADDRESS BUS

CONTROL BUS
Microcontroller vs Microprocessor

C vs General-Purpose P (Cont..)

Microprocessor-based System Microcontroller-based System

ROM EEPROM

RAM
Microprocessor

Serial I/O

A/D Input Input Parallel I/O


and and
Analog output output
I/O ports ports Timer
D/A
PWM
C vs General-Purpose P (Cont..)
PIC Microcontroller Family

Microchip Mid-Range PIC


PIC Microcontroller Family

8-bit PIC MCU Architectures


PIC Microcontroller Family

Baseline
PIC Microcontroller Family

Mid Range
PIC Microcontroller Family

Enhanced Mid Range


PIC Microcontroller Family

18F Architecture
PIC Microcontroller Family

A Brief History of PIC C

In 1989, Microchip Technology Corporation


introduced an 8-bit C called PIC (Peripheral
Interface Controller).
This 8 pins chip contains a small amounts of
data RAM, a few hundred bytes of on-chip
ROM for program, one timer, and a few pins
for I/O ports.
The family of 8-bit C: 10xxx, 12xxx, 14xxx,
16xxx, 17xxx, and 18xxx
PIC Microcontroller Family

A Brief History of PIC C (Cont..)

http://www.microchip.com
PIC Microcontroller Family

A Brief History of PIC C (Cont..)

They are all 8-bit processors that the CPU can


work on only 8 bits of data a time.
Problem: not all 100% upwardly compatible in
terms of software when going from one family
to another family.
Ex.: 12xxx - 12-bit wide instructions
16xxx- 14-bit wide instructions
PIC18xxx - 16-bit wide with many
new instructions
PIC Microcontroller Family

A Brief History of PIC C (Cont..)

Advantages of PIC:
30 to 100 times faster than other Cs
(program memory is integrated to the chip)
Smaller size (on-board memory)
Easy to program, reusable and inexpensive
PIC Microcontroller Family

A Brief History of PIC C (Cont..)

Architecture:

Program &
CPU Data Memory
Von Neumann architecture

Data Program
Memory CPU Memory
Harvard architecture
Review

1. A C normally has which of the following devices on-


chip?
(a) RAM (b) ROM (c) I/O (d) all of the above

2. A general-purpose microprocessor normally needs


which of the following devices to be attached to it?
(a) RAM (b) ROM (c) I/O (d) all of the above

3. The PIC16 is a(n) ___-bit P.


Microcontroller Architecture

PIC16F877 Architecture
Microcontroller Architecture

PIC16F877 Architecture (Cont)


Microcontroller Architecture

PIC16F877 Architecture Pin descriptions

Pin Name Description


OSC1/CLKIN Oscillator crystal input/external clock source input.
OSC2/CLKOUT Oscillator crystal output. Connects to crystal or resonator
in crystal oscillator mode. In RC mode, OSC2 pin outputs
CLKOUT which has 1/4 the frequency of OSC1, and
denotes the instruction cycle rate.
MCLR/VPP Master Clear (Reset) input or programming voltage input.
This pin is an active low RESET to the device.
VSS Ground reference for logic and I/O pins.
VDD Positive supply for logic and I/O pins.
NC These pins are not internally connected. These pins
should be left unconnected.
Microcontroller Architecture

PIC16F877 Architecture Pin descriptions


PORTA is a bi-directional I/O port.

Pin Name Description


RA0/AN0 RA0 can also be analog input0.
RA1/AN1 RA1 can also be analog input1.
RA2/AN2/VREF- RA2 can also be analog input2 or negative
analog reference voltage.
RA3/AN3/VREF+ RA3 can also be analog input3 or positive
analog reference voltage.
RA4/T0CKI RA4 can also be the clock input to the Timer0 timer/
counter. Output is open drain type.
RA5/SS/AN4 RA5 can also be analog input4 or the slave select for
the synchronous serial port.
Microcontroller Architecture

PIC16F877 Architecture Pin descriptions


PORTB is a bi-directional I/O port. PORTB can be software
programmed for internal weak pull-up on all inputs.

Pin Name Description


RB0/INT RB0 can also be the external interrupt pin.
RB1
RB2
RB3/PGM RB3 can also be the low voltage programming input.
RB4 Interrupt-on-change pin.
RB5 Interrupt-on-change pin.
RB6/PGC Interrupt-on-change pin or In-Circuit Debugger pin.
Serial programming clock.
RB7/PGD Interrupt-on-change pin or In-Circuit Debugger pin.
Serial programming data.
Microcontroller Architecture

PIC16F877 Architecture Pin descriptions


PORTC is a bi-directional I/O port.

Pin Name Description


RC0/T1OSO/T1CKI RC0 can also be the Timer1 oscillator output or a
Timer1 clock input.
RC1/T1OSI/CCP2 RC1 can also be the Timer1 oscillator input or
Capture2 input/Compare2 output/PWM2 output.
RC3/SCK/SCL RC3 can also be the synchronous serial clock input/
output for both SPI and I2C modes.
RC4/SDI/SDA RC4 can also be the SPI Data In (SPI mode) or
data I/O (I2C mode).
RC5/SDO RC5 can also be the SPI Data Out (SPI mode).
RC6/TX/CK RC6 can also be the USART Asynchronous Transmit
or Synchronous Clock.
RC7/RX/DT RC7 can also be the USART Asynchronous Receive
or Synchronous Data.
Microcontroller Architecture

PIC16F877 Architecture Pin descriptions

PORTD is a bi-directional I/O port or parallel slave port


when interfacing to a microprocessor bus.
Pin Name Description
RD0/PSP0-RD7/PSP7

PORTE is a bi-directional I/O port.


Pin Name Description
RE0/RD/AN5 RE0 can also be read control for the parallel slave
port, or analog input5.
RE1/WR/AN6 RE1 can also be write control for the parallel slave
port, or analog input6.
RE2/CS/AN7 RE2 can also be select control for the parallel slave
port, or analog input7.
Microcontroller Architecture

Architecture - PIC Clock Generator

To provide a clock for executing a


program or program instructions of C.
Types of PIC clock generator:
A crystal & two capacitors
Resonators or external resistor-capacitor pair
Built-in resistor-capacitor
Microcontroller Architecture

Architecture - PIC Clock Generator (Cont..)

PIC16F877 can operate in four different


oscillation modes:
- LP low power crystal
- XT crystal/resonator
- HS high speed crystal/resonator
- RC resistor/capacitor
Two configuration bits, FOSC1 & FOSC0
are used to select one of these four modes
Microcontroller Architecture

Architecture - PIC Clock Generator (Cont..)

Crystal Oscillator/Ceramic Resonators


For XT, LP or HS OSC configurations
Crystal or ceramic resonator is connected to the
OSC1/CLKIN & OSC2/CLKOUT pins
Microcontroller Architecture

Architecture - PIC Clock Generator (Cont..)

External clock input operations

A parallel cut crystal is used to design


PIC16F877
The use of a series cut crystal may give a
freq. out of the crystal manufacturers
specifications
Microcontroller Architecture

Architecture - PIC Clock Generator (Cont..)

Capacitor selection for ceramic resonators

Capacitor selection for crystal oscillator


Microcontroller Architecture

Architecture - PIC Clock Generator (Cont..)

RC Oscillator

Reduce cost for timing insensitive applications


Variation of the oscillator frequency:
- operating temperature
- process parameter variation
- difference in lead frame capacitance between package types (low
CEXT values)
- tolerance of the external R & C components
Microcontroller Architecture

Reset
Value registers upon reset
Power-on Reset (POR)
Register Reset value (hex)
MCLR Reset during normal PC 000000
operation WREG 00

MCLR Reset during SLEEP SP 00


TRISA-TRISB FF
WDT Reset (during normal
operation)
WDT Wake-up (during SLEEP)
Brown Out Reset (BOR)
Reset (Cont..)
Review

1. Which pin is used to reset the PIC16F877 chip?


2. Upon power-up, the program counter (PC) has a
value of ____.
3. Upon power-up, the PIC16F877 fetches the first
opcode from ROM address location _____.
4. MCLR is an active-_____ (LOW, HIGH) pin.
5. How many Vdd and Gnd pins are in the PIC16F877
chip?
6. In the PIC16, the program counter is ____ bits wide.
Microcontroller Architecture

Center Processing Unit (CPU)

The brain of the C


Connect all parts of the C through a data bus &
and an address bus
Find, fetch, decode & execute the right
instruction
CPU resources:
Registers: store temporary information
ALU: performing arithmetic functions
Program counter: point to the address of the next
instruction to be executed
Instruction decoder: interpret the instruction
fetched into the CPU
Microcontroller Architecture

CPU (Cont..)

Arithmetic Logic Unit (ALU)


Add, subtract, move (left @ right within a register) and logic
operations
PIC16F877 contains an 8-bit ALU & 8-bit working registers
(WREG)
ALU instructions: two operands @ one operand
Two operands: WREG + file register @ immediate constant
Registers: GPR (General Purposes Registers) & SFP (Special
Function Registers)
One operand: WREG @ a file register
Execution of ALU instructions can affect STATUS bits which
are carry (C), digit carry (DC), and zero (Z).
Microcontroller Architecture

CPU (Cont..)

WREG 8-bit literal (from


register instruction word)

8-bit
8-bit
Carry bit

STATUS
ALU register

Z, DC, C flags
8-bit
Microcontroller Architecture

Ports

Physical connection of CPU and outside world


monitor @ control other components @
devices
A group of pins which can be accessed
simultaneously @ set the desired combination
of zeros and ones
All port pins can be designated as input @
output
Microcontroller Architecture

PORTS: PORTA & TRISA

PORTA is a 6-bit wide, bi-directional port


TRISA: data direction register of PORTA
TRISA = 1, PORTA
is an input (output
driver in HI-
impedance mode)
TRISA = 0, PORTA
is an output
(contents of the
output latch on the
selected pin)
Microcontroller Architecture

PORTS: PORTB & TRISB

PORTB is a 8-bit wide, bi-directional port


TRISB: data direction register of PORTB
TRISB = 1, PORTB
is an input (output
driver in HI-
impedance mode)
TRISB = 0, PORTB
is an output
(contents of the
output latch on the
selected pin)
Microcontroller Architecture

PORTS: PORTC & TRISC

PORTC is an 8-bit wide, bi-directional port. The


corresponding data direction register is TRISC.
Setting a TRISC bit (= 1) will make the corresponding
PORTC pin an input (i.e., put the corresponding output
driver in a Hi-Impedance mode).
Clearing a TRISC bit (= 0) will make the corresponding
PORTC pin an output (i.e., put the contents of the output
latch on the selected pin).
PORTC is multiplexed with several peripheral functions
PORTC pins have Schmitt Trigger input buffers
Microcontroller Architecture

PORTS: PORTD & TRISD

PORTD is an 8-bit port with Schmitt Trigger input


buffers.
Each pin is individually configurable as an input or
output.
PORTD can be configured as an 8-bit wide
microprocessor port (parallel slave port) by setting
control bit PSPMODE (TRISE<4>). In this mode, the
input buffers are TTL
Microcontroller Architecture

PORTE and TRISE Register

PORTE has three pins (RE0/RD/AN5, RE1/WR/AN6, and


RE2/CS/AN7) which are individually configureable as inputs or
outputs. These pins have Schmitt Trigger input buffers.
The PORTE pins become the I/O control inputs for the
microprocessor port when bit PSPMODE (TRISE<4>) is set.
In this mode, the user must make certain that the TRISE<2:0> bits
are set, and that the pins are configured as digital inputs. Also
ensure that ADCON1 is configured for digital I/O.
In this mode, the input buffers are TTL. Register 3-1 shows the
TRISE register, which also controls the parallel slave port operation.
PORTE pins are multiplexed with analog inputs. When selected for
analog input, these pins will read as 0s.
TRISE controls the direction of the RE pins, even when they are
being used as analog inputs. The user must make sure to keep the
pins configured as inputs when using them as analog inputs.
Review

1. There are total of ____ ports in the PIC16F877.


2. True or false. All of the PIC16F877 ports have 8 pins.
3. List the PIC16F877 port that has 8 pins.
4. True or false. Upon power-up, the I/O pins are
configured as output ports.
5. To make Port B an output port, we must place ____
in register _____.
6. To make Port B an input port, we must place ____ in
register _____.
Microcontroller Architecture

Memory organization

PIC16F877 has three memory blocks:


1) Program memory (flash)
2) Data memory
3) EEPROM data memory
Microcontroller Architecture

Memory organization
Microcontroller Architecture

Program memory map and stack


Microcontroller Architecture

Program memory

The PIC16F87X devices have a 13-bit program counter


capable of addressing an 8K x 14 program memory
space.
The PIC16F877/876 devices have 8K x 14 words of
FLASH program memory, and the
The RESET vector is at 0000h and the interrupt vector is
at 0004h.
Microcontroller Architecture

Data memory

The data memory is partitioned into multiple banks which contain the
General Purpose Registers and the Special Function Registers.
Bits RP1 (STATUS<6>) and RP0 (STATUS<5>) are the bank select
bits

Each bank extends up to 7Fh (128 bytes). The lower locations of


each bank are reserved for the Special Function Registers.
Above the Special Function Registers are General Purpose
Registers, implemented as static RAM.
All implemented banks contain Special Function Registers. Some
frequently used Special Function Registers from one bank may be
mirrored in another bank for code reduction and quicker access..
Microcontroller Architecture

Data memory (Cont..)


Microcontroller Architecture

General Purpose Register

General-Purpose registers are used for


storing temporary data and results created
during operation.
Each General Purpose Register (GPR) is
8-bits wide and is accessed either directly
or indirectly through the FSR.
Microcontroller Architecture

Special Purpose Register

Special-Function registers are also RAM memory


locations, but unlike general-purpose registers,
their purpose is predetermined during
manufacturing process and cannot be changed.
Since their bits are physically connected to
particular circuits on the chip (A/D converter, serial
communication module, etc.), any change of their
contents directly affects the operation of the
microcontroller or some of its circuits.
Microcontroller Architecture

Special Function Register Summary


Microcontroller Architecture

Special Function Register Summary (Cont..)


Microcontroller Architecture

Special Function Register Summary (Cont..)


Microcontroller Architecture

EEPROM Memory

Similar to program memory, the contents of EEPROM is


permanently saved, even the power goes off.
However, unlike ROM, the contents of the EEPROM can be
changed during operation of the microcontroller.
That is why this memory (256 locations) is a perfect one for
permanently saving results created and used during the
operation.

Potrebbero piacerti anche