KEMBAR78
Microprocessor and Microcontroller Based Systems.ppt
Microprocessor and Microcontroller Based Systems
Instructor: Eng.Moayed N. EL Mobaied
The Islamic University of Gaza
Faculty of Engineering
Electrical Engineering Department
‫الرحيم‬ ‫الرحمن‬ ‫هللا‬ ‫بسم‬
Lecture 3
EELE 4315 — Fall 2010
Microcontroller
Microcontroller
Microcontroller differs from a microprocessor in many ways. First and the
most important is its functionality.
In order for a microprocessor to be used, other components such as
memory, or components for receiving and sending data must be added to it.
On the other hand, microcontroller is designed to be all of that in one.
No other external components are needed for its application because all
necessary peripherals are already built into it.
Thus, we save the time and space needed to construct devices.
Microcontroller
A microcontroller is a microprocessor designed to perform simple control functions.
Microcontrollers usually have these features
• low cost,
• physically small,
• input/output intensive, and capable of easy interfacing,
• limited memory capability for program and data,
• instruction set leading to compact code, with limited arithmetic capability,
• ability to operate in a real-time environment.
In certain applications the following further features are essential:
• ability to operate in hostile environment, e.g. high or low temperature, tolerant to
electromagnetic interference,
• low power, with features adapted to battery power.
Microcontroller
A microcontroller = microprocessor core + memory + peripherals
Digital
Program
I/0
Microprocessor
Data
Memory
Memory
Core
Analog
I/0
& Timers
Counters
Reset
Power
Clock
Address Buses
Internal Data &
Further
Peripheral
Further
Peripheral
Interrupt(s)
Microcontroller
PIC is a family of microcontrollers made by Microchip Technology.
The original one was the PIC1650 developed by General Instruments.
This device was called:
PIC for “Programmable Intelligent Computer” although it is now associated with
“Programmable Interface Controller.”
Microchip does not use PIC as brand name . Instead they prefer the
brand name PICmicro.
PIC is a registered brand in Germany and Microchip is unable to use it
internationally.
Microcontroller
The original PIC was built to be used with General Instruments’ CP1600 processor,
which had poor I/O performance.
The PIC was designed to take over the I/O tasks for the CPU, thus improving
performance.
In 1985, the PIC was upgraded with EPROM to produce a programmable controller.
Today, a huge variety of PICs are available with many different on-board
peripherals and program memories ranging from a few hundred words to 32K.
Microcontroller
PICs use an instruction set that varies in length from about 35 instructions for the
low-end PICs to more than 70 for the high-end devices.
The PICs are programmable in their native Assembly Language, which is
straightforward and not difficult to learn.
In addition, C language and BASIC compilers have been developed for the PIC.
Open-source Pascal, JAL, and Forth compilers are also available for PIC
programming.
Microcontroller interface
Input
Variables
Output
(User Interface)
Variables
(Link to other Systems)
Embedded Computer
Software
Hardware
Signal
Conditioning
Data
Conversion
Output
Drive
(display, keypad etc.)
Microcontroller applications
Microcontroller
Electronics
Electric Motors &
Computer Architecture
Software Engineering
Integrated Circuit
Design
Digital
Analogue
Electronics
Actuators
Sensors and
Measurements
Control
Engineering
Data
Communications
PIC Microcontroller Architecture
a) The Von Neumann Way b) The Harvard Way
Data
Memory
Program
Memory
Address
Data
Central
Processing
Unit (CPU)
Input/
Output
Central
Processing
Unit (CPU)
Data
Memory
Input/
Output
Program
Memory
Address
Data
Address
Data
Address
Data
Instructions and Instruction Sets
Increment A
Decrement A
Add A to M
Subtract M from A
AND A with M
OR A with M
Exclusive OR A with M
Shift A left
Shift A right
Rotate A left
Rotate A right
Complement A
Clear A
A = A plus 1
A = A - 1
A = A plus M
A = A - M
A = A.M
A = A + M
A = A M
+
A = 2A
A = A/2
A = NOT A
A = 0
A computer “executes” instructions in its Arithmetic Logic Unit (ALU), running through a series of
instructions called a program. An ALU can only do a few things, but it can do them very fast. A
typical 8-bit ALU can do the list shown below. A is the “Accumulator”, a digital register where the
computations actually occur, and M is a location in memory. The ALU in turn forms part of the
Central Processing Unit (CPU).
How Instruction Sets are Made: the “CISC” Machine
Any CPU has a set of instructions that it recognizes and responds to; all programs
are built up in one way or another from this instruction set. We want computers to
execute code as fast as possible, but how to achieve this aim is not always an obvious
matter.
One approach is to build sophisticated CPUs with exotic instruction sets, with an
instruction ready for every foreseeable operation. This leads to the CISC, the
Complex Instruction Set Computer. A CISC has many instructions, and considerable
sophistication. Yet the complexity of the design needed to achieve this tends to lead
to slow operation. One characteristic of the CISC approach is that instructions have
different levels of complexity. Simple ones can be expressed in a short instruction
code, say one byte of data, and execute quickly. Complex ones may need several
bytes of code to define them, and take a long time to execute.
A CISC machine is generally recognised by:
• Many instructions (say over one hundred), some with considerable sophistication;
• Instruction words are of different length;
• Instructions take different lengths of time to execute.
How Instruction Sets are Made: the “RISC” Machine
Another approach is to keep the CPU very simple, and have a limited instruction
set. This leads to the RISC approach – the Reduced Instruction Set Computer. The
instruction set, and hence overall design, is kept simple. This leads to fast operation.
One characteristic of the RISC approach is that each instruction is contained within
a single binary word. That word must hold all information necessary, including the
instruction code itself, as well as any address or data information also needed. A
further characteristic, an outcome of the simplicity of the approach, is that every
instruction normally takes the same amount of time to execute.
A RISC machine is generally recognised by:
• Few instructions (say well below one hundred),
• Each performs a very simple action;
• All instructions are single word;
• All, or almost all instructions take the same length of time to execute.
PIC 16F84A Microcontroller
The 16F84A is available as an 18-pin device. The pin connection diagram is
shown here. This won’t make much sense just yet, but in the coming sessions you
will be surprised how quickly you get to know what most (if not all) of these pins
are used for.
RA2
RA3
RA4/T0CKI
MCLR
V
RB0/INT
RB1
RB2
RB3 RB4
RB5
RB6
RB7
RA1
RA0
OSC1/CLKIN
OSC2/CLKOUT
VDD
SS Supply voltage
Oscillator connections
Port A, Bit 0
Port A, Bit 1
Port A, Bit 2
Port A, Bit 3
*Port A, Bit 4
Ground
**Port B, Bit 0
Port B, Bit 1
Port B, Bit 2
Port B, Bit 3
Port B, Bit 7
Port B, Bit 6
Port B, Bit 5
Port B, Bit 4
*also Counter/Timer clock input
**also external Interrupt input
Reset
1
9 10
18
PIC 16F84A Microcontroller
We are going to look at the block diagram of the 16F84A, straight from the
manufacturer’s data sheet, shown below right. A good understanding of the block
diagram leads to an ability to design with the microcontroller, and to program it.
In the diagram, you should in time be able to recognise all the basic features of a
microcontroller. Let’s pick out the main features of the 16F84A, in the coming slides.
Digital
Program
I/0
Microprocessor
Data
Memory
Memory
Core
Analog
I/0
& Timers
Counters
Reset
Power
Clock
Address Buses
Internal Data &
Further
Peripheral
Further
Peripheral
Interrupt(s)
PIC 16F84A Microcontroller: Block diagram
The CPU
Address for Program Memory
Data from
Program
Memory,
carrying
instruction
word
Address for Data
Memory
Data bus for
Data Memory
and peripherals
Program Memory
Data
Memory
Extra “non-
volatile” Data
Memory
Counter/Timer
Peripheral
Digital Input/
Output Ports
PIC 16F84A Microcontroller: “Flow“
The Instruction word
flows here. The word will
contain the instruction, and
maybe also address and
data information
Address info.
flows here
Instruction info
flows here
The core is the “microprocessor
inside the microcontroller”,
centred around the ALU. It is
interesting to see the path that the
instruction takes from program
memory.
“Literal” data
flows along here
The Arithmetic
Logic Unit
The “Working
Register”
PIC 16F84A Microcontroller: Block diagram
Program Memory and Stack
Program
Counter
16 Series
instructions which
invoke the Stack
Unimplemented memory
space, still addressable by
the 13-bit 16F84A program
address bus.
Program Counter
points to locations in
program memory
The program
must start here
The Interrupt
Service Routine
must start here
Interfacing with Peripherals – the Special Function Register
Control SFR(s)
Peripheral
Data Transfer SFR(s)
Microcontroller
Core
"Outside
World"
Interrupt(s)
Microcontroller Interaction with its Peripherals, via Special Function Register (SFR) and Interrupt
 microcontroller peripherals can be configured in software to operate in a number of different
modes, to do this certain control data must be sent to them to set them up in the desired way
 once in use, there will be data flow between core and peripheral,
 there may still be need for further control data,
 these needs are commonly met by means of dedicated, memory - mapped registers, sometimes
called Special Function Registers,
 this approach gives the microcontroller manufacturer great flexibility to extend a microcontroller
family – SFRs for new peripherals can easily be located in gaps in the memory map.
Data Memory and Special Function Register Map
msb is “bank
select bit”
(Status register).
These are the Special Function
Registers, which allow the CPU
to interact with the peripherals
General purpose memory

Microprocessor and Microcontroller Based Systems.ppt

  • 1.
    Microprocessor and MicrocontrollerBased Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical Engineering Department ‫الرحيم‬ ‫الرحمن‬ ‫هللا‬ ‫بسم‬ Lecture 3 EELE 4315 — Fall 2010
  • 2.
  • 3.
    Microcontroller Microcontroller differs froma microprocessor in many ways. First and the most important is its functionality. In order for a microprocessor to be used, other components such as memory, or components for receiving and sending data must be added to it. On the other hand, microcontroller is designed to be all of that in one. No other external components are needed for its application because all necessary peripherals are already built into it. Thus, we save the time and space needed to construct devices.
  • 4.
    Microcontroller A microcontroller isa microprocessor designed to perform simple control functions. Microcontrollers usually have these features • low cost, • physically small, • input/output intensive, and capable of easy interfacing, • limited memory capability for program and data, • instruction set leading to compact code, with limited arithmetic capability, • ability to operate in a real-time environment. In certain applications the following further features are essential: • ability to operate in hostile environment, e.g. high or low temperature, tolerant to electromagnetic interference, • low power, with features adapted to battery power.
  • 5.
    Microcontroller A microcontroller =microprocessor core + memory + peripherals Digital Program I/0 Microprocessor Data Memory Memory Core Analog I/0 & Timers Counters Reset Power Clock Address Buses Internal Data & Further Peripheral Further Peripheral Interrupt(s)
  • 6.
    Microcontroller PIC is afamily of microcontrollers made by Microchip Technology. The original one was the PIC1650 developed by General Instruments. This device was called: PIC for “Programmable Intelligent Computer” although it is now associated with “Programmable Interface Controller.” Microchip does not use PIC as brand name . Instead they prefer the brand name PICmicro. PIC is a registered brand in Germany and Microchip is unable to use it internationally.
  • 7.
    Microcontroller The original PICwas built to be used with General Instruments’ CP1600 processor, which had poor I/O performance. The PIC was designed to take over the I/O tasks for the CPU, thus improving performance. In 1985, the PIC was upgraded with EPROM to produce a programmable controller. Today, a huge variety of PICs are available with many different on-board peripherals and program memories ranging from a few hundred words to 32K.
  • 8.
    Microcontroller PICs use aninstruction set that varies in length from about 35 instructions for the low-end PICs to more than 70 for the high-end devices. The PICs are programmable in their native Assembly Language, which is straightforward and not difficult to learn. In addition, C language and BASIC compilers have been developed for the PIC. Open-source Pascal, JAL, and Forth compilers are also available for PIC programming.
  • 9.
    Microcontroller interface Input Variables Output (User Interface) Variables (Linkto other Systems) Embedded Computer Software Hardware Signal Conditioning Data Conversion Output Drive (display, keypad etc.)
  • 10.
    Microcontroller applications Microcontroller Electronics Electric Motors& Computer Architecture Software Engineering Integrated Circuit Design Digital Analogue Electronics Actuators Sensors and Measurements Control Engineering Data Communications
  • 11.
    PIC Microcontroller Architecture a)The Von Neumann Way b) The Harvard Way Data Memory Program Memory Address Data Central Processing Unit (CPU) Input/ Output Central Processing Unit (CPU) Data Memory Input/ Output Program Memory Address Data Address Data Address Data
  • 12.
    Instructions and InstructionSets Increment A Decrement A Add A to M Subtract M from A AND A with M OR A with M Exclusive OR A with M Shift A left Shift A right Rotate A left Rotate A right Complement A Clear A A = A plus 1 A = A - 1 A = A plus M A = A - M A = A.M A = A + M A = A M + A = 2A A = A/2 A = NOT A A = 0 A computer “executes” instructions in its Arithmetic Logic Unit (ALU), running through a series of instructions called a program. An ALU can only do a few things, but it can do them very fast. A typical 8-bit ALU can do the list shown below. A is the “Accumulator”, a digital register where the computations actually occur, and M is a location in memory. The ALU in turn forms part of the Central Processing Unit (CPU).
  • 13.
    How Instruction Setsare Made: the “CISC” Machine Any CPU has a set of instructions that it recognizes and responds to; all programs are built up in one way or another from this instruction set. We want computers to execute code as fast as possible, but how to achieve this aim is not always an obvious matter. One approach is to build sophisticated CPUs with exotic instruction sets, with an instruction ready for every foreseeable operation. This leads to the CISC, the Complex Instruction Set Computer. A CISC has many instructions, and considerable sophistication. Yet the complexity of the design needed to achieve this tends to lead to slow operation. One characteristic of the CISC approach is that instructions have different levels of complexity. Simple ones can be expressed in a short instruction code, say one byte of data, and execute quickly. Complex ones may need several bytes of code to define them, and take a long time to execute. A CISC machine is generally recognised by: • Many instructions (say over one hundred), some with considerable sophistication; • Instruction words are of different length; • Instructions take different lengths of time to execute.
  • 14.
    How Instruction Setsare Made: the “RISC” Machine Another approach is to keep the CPU very simple, and have a limited instruction set. This leads to the RISC approach – the Reduced Instruction Set Computer. The instruction set, and hence overall design, is kept simple. This leads to fast operation. One characteristic of the RISC approach is that each instruction is contained within a single binary word. That word must hold all information necessary, including the instruction code itself, as well as any address or data information also needed. A further characteristic, an outcome of the simplicity of the approach, is that every instruction normally takes the same amount of time to execute. A RISC machine is generally recognised by: • Few instructions (say well below one hundred), • Each performs a very simple action; • All instructions are single word; • All, or almost all instructions take the same length of time to execute.
  • 15.
    PIC 16F84A Microcontroller The16F84A is available as an 18-pin device. The pin connection diagram is shown here. This won’t make much sense just yet, but in the coming sessions you will be surprised how quickly you get to know what most (if not all) of these pins are used for. RA2 RA3 RA4/T0CKI MCLR V RB0/INT RB1 RB2 RB3 RB4 RB5 RB6 RB7 RA1 RA0 OSC1/CLKIN OSC2/CLKOUT VDD SS Supply voltage Oscillator connections Port A, Bit 0 Port A, Bit 1 Port A, Bit 2 Port A, Bit 3 *Port A, Bit 4 Ground **Port B, Bit 0 Port B, Bit 1 Port B, Bit 2 Port B, Bit 3 Port B, Bit 7 Port B, Bit 6 Port B, Bit 5 Port B, Bit 4 *also Counter/Timer clock input **also external Interrupt input Reset 1 9 10 18
  • 16.
    PIC 16F84A Microcontroller Weare going to look at the block diagram of the 16F84A, straight from the manufacturer’s data sheet, shown below right. A good understanding of the block diagram leads to an ability to design with the microcontroller, and to program it. In the diagram, you should in time be able to recognise all the basic features of a microcontroller. Let’s pick out the main features of the 16F84A, in the coming slides. Digital Program I/0 Microprocessor Data Memory Memory Core Analog I/0 & Timers Counters Reset Power Clock Address Buses Internal Data & Further Peripheral Further Peripheral Interrupt(s)
  • 17.
    PIC 16F84A Microcontroller:Block diagram The CPU Address for Program Memory Data from Program Memory, carrying instruction word Address for Data Memory Data bus for Data Memory and peripherals Program Memory Data Memory Extra “non- volatile” Data Memory Counter/Timer Peripheral Digital Input/ Output Ports
  • 18.
    PIC 16F84A Microcontroller:“Flow“ The Instruction word flows here. The word will contain the instruction, and maybe also address and data information Address info. flows here Instruction info flows here The core is the “microprocessor inside the microcontroller”, centred around the ALU. It is interesting to see the path that the instruction takes from program memory. “Literal” data flows along here The Arithmetic Logic Unit The “Working Register”
  • 19.
  • 20.
    Program Memory andStack Program Counter 16 Series instructions which invoke the Stack Unimplemented memory space, still addressable by the 13-bit 16F84A program address bus. Program Counter points to locations in program memory The program must start here The Interrupt Service Routine must start here
  • 21.
    Interfacing with Peripherals– the Special Function Register Control SFR(s) Peripheral Data Transfer SFR(s) Microcontroller Core "Outside World" Interrupt(s) Microcontroller Interaction with its Peripherals, via Special Function Register (SFR) and Interrupt  microcontroller peripherals can be configured in software to operate in a number of different modes, to do this certain control data must be sent to them to set them up in the desired way  once in use, there will be data flow between core and peripheral,  there may still be need for further control data,  these needs are commonly met by means of dedicated, memory - mapped registers, sometimes called Special Function Registers,  this approach gives the microcontroller manufacturer great flexibility to extend a microcontroller family – SFRs for new peripherals can easily be located in gaps in the memory map.
  • 22.
    Data Memory andSpecial Function Register Map msb is “bank select bit” (Status register). These are the Special Function Registers, which allow the CPU to interact with the peripherals General purpose memory