[go: up one dir, main page]

0% found this document useful (0 votes)
15 views33 pages

Cha 2.0

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 33

Chapter Two

Microcontroller

1
Outline
– Introduction
– Types of Microcontrollers
– Microchip PIC
• PIC16F877a
– External view of PIC16F877a
• Pin diagram and functionality of PIC16F877a
– Block diagram and description of functionalities(PIC16F877a)
• Architecture
• Internal block diagram
– Memory
» Program memory
» Data memory
• GPRs
• SFRS
• Memory banks
– PIC16F877a Registers
» CPU register
– I/O ports and peripherals modules
2
Introduction
What is a microcontroller?
 A microcontroller (sometimes abbreviated µC, uC or MCU) is a small
computer on a single integrated circuit containing a processor core,
memory, and programmable input/output peripherals. It can only
perform simple task. A microcontroller is often described as a
‘computer-on-a-chip’.

3
Introduction
• Microcontrollers are purchased ‘blank’ and then programmed with a specific
control program.
• Once programmed the microcontroller is build into a product to make the
product more intelligent and easier to use.

• A designer will use a Microcontroller to:


- Gather input from various sensors
- Process this input into a set of actions
- Use the output
mechanisms on
the microcontroller
to do something
useful.
The Difference between microcomputer system and
microcontroller based system
Embedded System
• Microcontrollers are sometimes called embedded
microcontrollers, which just means that they are part of an
embedded system -- that is, one part of a larger device or
system.

• The majority of microcontrollers in use today are embedded


in other machinery, such as automobiles, telephones,
appliances, and peripherals for computer systems. These are
called embedded system.

6
Examples of Embedded System
• Consumer Electronic : DVD player, wi-fi, air-conditioner,
washing machine etc.
• Medical Monitoring Devices : ECG (electrocardiogram), blood
pump, blood pressure meter, etc.
• Security System : Alarm, remote sueveilance, smart card +
reader etc.
• Closed Loop Process Control : Motor speed control, robot, etc.
• Personal Computing : Keyboard, printer, USB hub, SCSI HD, etc.
• Automotive : Ignition control, Automatic transmission, anti-lock
brake system (ABS), active suspension, etc
• Military : Missile, torpedo, ejection seat, etc
• Communications : Handphone, modem, radar, satelite etc.

7
Types of Microcontroller
• Parallax Propeller
• Freescale 68HC11 (8-bit)
• Intel 8051
• Silicon Laboratories Pipelined 8051 Microcontrollers
• ARM processors (from many vendors) using ARM7 or Cortex-M3
cores are generally microcontrollers
• STMicroelectronics STM8 (8-bit), ST10 (16-bit) and STM32 (32-bit)
• Atmel AVR (8-bit), AVR32 (32-bit), and AT91SAM (32-bit)
• Freescale ColdFire (32-bit) and S08 (8-bit)
• Hitachi H8, Hitachi SuperH (32-bit)
• Hyperstone E1/E2 (32-bit, First full integration of RISC and DSP on
one processor core [1996])
• Infineon Microcontroller: 8, 16, 32 Bit microcontrollers for
automotive and industrial applications.
…cont’d
• MIPS (32-bit PIC32)
• NEC V850 (32-bit)
• Microchip PIC (8-bit PIC16, PIC18, 16-bit dsPIC33/PIC24)
• PowerPC ISE
• PSoC (Programmable System-on-Chip)
• Rabbit 2000 (8-bit)
• Texas Instruments Microcontroller MSP 430 (16-bit), C2000 (32-
bit), and Stellaris (32-bit)
• Toshiba TLCS-870 (8-bit/16-bit)
• Zilog eZ8 (16-bit), eZ80 (8-bit)
• etc
Microchip PIC
• PIC is a family of Harvard architecture microcontroller made by
Microchip Technology. The name PIC initially referred to
"Peripheral Interface Controller“ . PIC microcontrollers were the
first RISC microcontroller.

Why PIC is popular?


• PICs are popular with both industrial developers and hobbyists alike due to:-
– Low cost, wide availability with high clock speed
– Availability of low cost or free development tools
– large user base and extensive collection of application notes
– Serial programming and re-programming with flash memory capability
– Its code is extremely efficient, allowing the PIC to run with typical less
memory than its larger competitors
Two Different Architectures
PIC Microcontroller product family
• 8-bit microcontrollers • 32-bit microcontrollers
– PIC10 – PIC32
– PIC12
• 16-bit digital signal
– PIC14
controllers
– PIC16
– dsPIC30
– PIC17
– dsPIC33F
– PIC18
• 16-bit microcontrollers
– PIC24F
– PIC24H
PIC Microcontroller product family
• The F in a name generally indicates the PICmicro uses flash memory
and can be erased electronically.
• The C generally means it can only be erased by exposing the die to
ultraviolet light (which is only possible if a windowed package style is
used). An exception to this rule is the PIC16C84 which uses EEPROM
and is therefore electrically erasable.

1:
Why use PIC16F877A?

Why PIC16F877A is very popular?


 This is because PIC16F877A is very cheap. Apart from that
it is also very easy to be assembled. Additional components
that you need to make this IC work is just a 5V power supply
adapter, a 20MHz crystal oscillator and 2 units of 22pF
capacitors.
What is the advantages of PIC16F877A?
 This IC can be reprogrammed and erased up to 10,000
times. Therefore it is very good for new product
development phase.
What is the disadvantages of PIC16F877A?
 This IC has no internal oscillator so you will need an external
crystal of other clock source.
Features of Key Features PIC16F877

PIC16F877 MAX Operating Frequency 20MHz

FLASH Program Memory


8K
(14-bit words)

Data Memory (bytes) 368

EEPROM Data Memory (bytes) 256


8
RA0-5 (6)
RB0-7 (8)
RC0-7 (8)
I/O Ports RD0-7 (8)
RE0-2 (3)

Timers 3

CCP 2

Serial Communications MSSP, USART

Parallel Communications PSP

10-bit Analog-to-Digital Module 8 Channels

Instruction Set 35 Instructions

Pins (DIP) 40 Pins


Pin Diagram of PIC16F877
 Quad Flat Package  Plastic Leaded Chip Carrier Package
(QFP) (PLCC)
Pin Diagram
of PIC16F877

• Plastic dual in-line


package (DIP)
PIC16F877
Architecture
PIC16F877 Architecture
• The PIC contains
– ALU – which does arithmetic and logic operations
– program counter – stores the address of the next instruction to be fetched
– instruction register –stores instructions read from the program memory
– Instruction decoder – it decodes the instruction
– memory section
• RAM – which is also called the “register-file”
• program Memory – stores users program
– Different peripheral modules – for additional capabilities
– “W” register – working register (also called an “accumulator”)
• The ALU, the RAM, the “W” register, and the data EEPROM each
manipulate & hold 8-bit-wide data, which ranges in value from 0 -255
PIC16F877 Architecture
• The PIC’s program Memory has addresses that range from 0 to
8191 (0x1FFF). The user’s program occupies this memory space
– data bus has 14 wires and address bus has 13 wires
• Every instruction is represented by a 14-bit binary number.
– If the instruction is a move to/from a data memory location the address of
this memory location will be contained in the instruction
• The PIC’s RAM addresses range from 0 to 511 but the user can only
access a RAM byte in a set of four “banks” of 128 bytes each and
only one bank at a time.
– data bus has 8 wires and address bus has 9 wires
– Not all of this RAM is available to the user as read-write memory, however.
– Many addresses are dedicated to special functions within the processor but
they “look-like” RAM and are accessed the same way
PIC16F877
Internal Block Diagram(simplified)

• The basic architecture of PIC16F877 consists


of Program memory, file registers and RAM,
ALU and CPU registers.

PIC16F877 Internal Block Diagram


Memory of the PIC16F877
• divided into 3 types of memories:

1. Program Memory – A memory that contains the program (which we


had written), after we've burned it. As a reminder, Program Counter
executes commands stored in the program memory, one after the other.
2. Data Memory – This is RAM memory type, which contains a special
registers like SFR (Special Function Register) and GPR (General Purpose
Register). The variables that we store in the Data Memory during the
program are deleted after we turn of the micro. These two memories
have separated data buses, which makes the access to each one of them
very easy.
3. Data EEPROM (Electrically Erasable Programmable Read-Only
Memory) – A memory that allows storing the variables as a result of
burning the written program.
…cont’d
• Each one of them has a different role. Program Memory
and Data Memory two memories that are needed to
build a program, and Data EEPROM is used to save data
after the microcontroller is turn off.
PIC16F877A
Program Memory
• Is Flash Memory
• Used for storing compiled
code (user’s program)
• Program Memory capacity is
8K x 14 bit  Each location is
14 bits long
 Every instruction is coded
as a 14 bit word
• PC can address up to 8K
addresses
• Addresses H’000’ and H’004’
are treated in a special way
PIC16F877A Program Memory
• Addresses H’000’:-’being a go to
mainline’ instruction
• Address H’004:-’being a go to in
service’ instruction can be
assigned to this addresses to make
the CPU jump to the beginning of
the interrupt Service routine
located elsewhere in the memory
space
• When we deal with tables they are
assigned to address in the range
H’005-H’0FF b/c for most
applications this space is enough
PIC16F877A Data Memory (RAM)
• Memory storage for variables
• Data Memory is also known as Register File and consists of
two components.
– General purpose register file (same as RAM).
– Special purpose register file.
• Addresses range from 0 to 511 and partitioned
into 4 banks  each bank extends up to 7Fh (128 bytes).
• The user can only access a RAM byte in a set of 4 banks and
only one bank at a time. The default bank is BANK0.
• To access a register that is located in another bank, one should
access it inside the program. There are special registers which
can be accessed from any bank, such as STATUS register.
General Purpose Registers (GPR)
• GPRs are used for storing temporary data and result created
during operation.
– e.g. if the program performs counting(product on the assembly), it is
necessary to have a register which stands for what we in the everyday
life call ‘sum’.
– As the MC is not creative at all, it is necessary to specify the address
of some general purpose register and assign it that function
• Data can be written to each 8-bit location, updated and
retrieved any number of times
• These register files can be accessed either directly, or
indirectly, through the File Select Register (FSR)
Special Function Registers (SFR)
• The special function registers are also memory registers which is used
for special dedicated functions.
• Unlike the GPRs, the SFRs purpose is predetermined during
manufacturing process and cannot be changed
• Each special function inside this PIC chip is controlled by using these
registers.
• These registers are used by the CPU and peripheral modules for
controlling the desired operation of the device.
• These registers are normally implemented as in the form of static
RAM memory.
• The Special Function Registers can be classified into two sets:
– core (CPU)
– peripheral.
Special Function Registers(SFR)
How to Use SFRs?
• There is a long list of SFRs and their bits. Each of them controls some process.
• It looks like a big control table with a lot of instructions and switches
• Thus select field you are interested in and study what you need to know.
– when you completely understand the h/w operation, study SFRs which are in
control of it(there are usually a few of them)
Memory Banks
• RAM memory bank is partitioned into four banks
• Prior to accessing any register during program writing, it is
necessary to select the bank which contains that register
• Handling banks may be difficult only if you write a program in
assembly language.
• When using higher programming languages such as C and
cross-compilers MikroC PRO for PIC, all you have to do is
specify the register name
– The compiler selects necessary bank and appropriate instructions used for
bank selection will be built in the code during the process of compilation
PIC16F877A register file map

You might also like