MCU 03 Unlocked
MCU 03 Unlocked
Fall : 2024
MKT3811 Week3 27.10.2021
Recap (Week-2)
Execute Decode
Pipelining:
Memory Types
3
Recap (Week-2)
4
Lecture Contents of Week 3
Microcontroller Types
Criteria for Choosing a Microcontroller
PIC Microcontrollers
5
Microprocessors and Programming
Microcontroller Types
6
Types of Microcontroller
7
Microprocessors and Programming
8
Criteria for Choosing a Microcontroller
The main criteria in selecting a microcontroller are given below in the order of
importance;
A. System Requirement;
The design should start with a blank sheet of paper specifying the application
needs, if the system requires a single chip MCU or additional peripherals are to
be used with it.
To develop code for 4-bit architectures is harder and handling 4-bit instructions
and data widths can limit arithmetic capabilities. Most of the small scale
embedded applications are implemented using 8-bit microcontroller as the
technology has been around a long time and huge number of controllers is
available in the market.
9
Criteria for Choosing a Microcontroller
B. Memory Architecture
This is very important factor while designing any microcontroller based system.
Three different types of memory play an important role in the selection process
are
(a) Program memory i.e. Flash, OTP, ROM and ROM less components,
(b) Data memory i.e. on-chip SRAM or external SDRAM and
(c) Non Volatile Memory i.e. EEPROM or Flash.
Whether the memory is on-chip or off-chip and how much the size is required
may be a key factor defines cost of building the system and speed of operation.
10
Criteria for Choosing a Microcontroller
C. Availability
Before going to implement the system, the availability of the device should be
checked for both now and future. If sufficient quantities are available with bright future
then no need to be worried about the failure of the project.
D. Size
If IC of 15 I/O pins is required to develop the system there is no need to use 40 pin IC
with 32 I/O pins. In this way the size of the IC can be reduced and thus physical
space required to implement the system is also reduced. So, physical size of
IC may well be critical factor for specific applications.
E. Cost
This is the most important factor. If the system is to be implemented within the limit
of the budget calculated earlier the cost of each and every component (selected MCU
along with supporting ICs) used to build the system should be minimized tactfully to
fulfill the requirements. On chip features will trade with inventory and assembly cost
of using extra supporting external components. They can also cut development time
and effort by providing a ready integrated solution.
11
Criteria for Choosing a Microcontroller
F. Security
Hacking which targets IoT devices is rising, a threat that is especially relevant to
microcontrollers used in automobiles. In response, microcontroller makers are
implementing layers of security such as cryptography and physical security. Now,
users can purchase microcontrollers that have been certified to the latest security
standards or use MCUs with on-chip secure hardware.
G. Manufacturer’s Support
During the step by step implementation of the system if the design engineer faces
any kind of problem he/she may communicate with the marketing/sales, field
application engineers. The manufacturers should have some facilities like a help line,
toll free number, fax number, after-sales support, sufficient knowledgeable and helpful
expertise support personnel
12
Criteria for Choosing a Microcontroller
Trend towards programming in high level language like C is increasing day by day.
This language allows using of some portability of code and libraries. This provides
more practical consideration using different microcontroller family. Choosing the
appropriate Hardware and software development tools is also important while
selecting MCU.
I. Compatibility
The function of a system can be changed or upgraded by changing the software or
replacing one IC with another one without incurring heavy additional cost.
The new one will be pin compatible as well as function compatible.
13
Criteria for Choosing a Microcontroller
J. Power Management
Most microcontrollers have the features of power down, idle & sleep modes and
consideration needs to be given to maximize the use of intelligent power
management systems to reduce power consumption.
For an example product of Intel, NXP, Zilog, Renesas, Infineon, TI, ST and
Microchip Technology are stable, mature and single sourced.
L. Functionality Testing
To check the function of the implemented system correctly the function of the
MCU should be checked within the test circuit designed earlier before going to
develop the overall system. The function testing circuit should be in affordable
cost.
14
Microprocessors and Programming
Microchip Microcontrollers
15
PIC Microcontrollers
PIC MCs were designed firstly to help and lighten pheripheral processing
work of microprocessors…
16
Why PIC Microcontroller
Cost effective
high performance for arithmetic and as well as logic operations
quick access to data and program memory by using separate bus systems
the family of PIC microcontrollers includes 4-bit, 8-bit, 16-bit and 32-bit mC
availability of running in high clock frequencies
in sleep mode 1μA electric current is required
primitive oscillator architecture is supported such as 2 cap. + 1 res.
high and low level programmability; (C – Basic – JAL, … and PIC Assembly)
based on Harvard architecture by reduced instruction set…
MPLAB-X PIC assembly compiler is free of charge
from 6 to 80 pin I/O model is supported…
17
PIC Microcontrollers
18
PIC Microcontrollers
19
PIC 16FXXX Microcontroller
16F84 Vs 16F877
20
PIC 16F887 Basic Features
21
PIC 16F887
Overall Features
• 8 bit controller
• 40 pins (35 I/O)
• RISC software architecture
• 35 instructions
• Support for interrupts
• Direct, indirect and relative addressing modes
• Power saving features
• Watch dog timer
• Harvard hardware architecture
• Support for
8k x (14bit) words of Flash Program Memory
368 x (8bit) bytes of Data Memory (RAM)
256 x (8bit) bytes of EEPROM Data Memory
22
PIC 16F877A
23
PIC 16F887
24
PIC 16F8x
For example;
Other than call and goto, all the instructions processed in one instruction cycle.
25
PIC 16F887 I/O
E MCLR
5 Ports – (A,B,C,D,E) A0
A1
A2
AA3 B
A4
E VCC
GND
VCC
GND
OSC
D
A OSC
C C
D D
26
PIC 16F887 I/O
Resolution : 10 bit
27
PIC 16F887 Special Protocols
UART
Universal Asynchronous
Receiver and Transmitter
C7
C6
28
PIC 16F887 Special Protocols
ISPI
2C
Inter-Integrated Circuit
Requires two pins to operate
Pin 18 Clock C3 C4
29
PIC 16F887 Special Protocols
SPI
Serial Peripheral Interface
Requires special three pins to operate
• Clock (SCK : Serial Clock)
• Data In (SDI : SPI Data In )
• Data Out (SDO : SPI Data Out)
• Chip Enable or Slave Select (SS)
C5
Pin 18 Clock C3 C4
30
PIC 16F887 External Int & PWM
Interrupt
SPI
Pin 16 PWM 2 C1
Pin 17 PWM 1 C2
31
PIC 16F8X Memory Types
•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.
•Data Memory – This is RAM memory type, which contains a special registers like SFR
(Special Faction 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.
Program Memory and Data EEPROM they are non-volatile memories, which store the information
even after the power is turn off. These memories called Flash or EEPROM. In contrast, Data Memory
does not save the information because it needs power in order to maintain the information stored
in the chip.
32
PIC 16FXXX Microcontroller
PROGRAM REGISTER
ADDRESS ADDRESS
SPECIAL
FUNCTION
8-BIT
13-BIT REGISTER
Program (SFR)
CPU
Memory
DATA
14-BIT 8-BIT MEMORY –
GPR
INSTRUCTION DATA
33
PIC 16FXXX Microcontroller
34
PIC 16FXXX Microcontroller
Simplified internal block diagram of PIC 16FXXX mC;
36
PIC 16FXXX Microcontroller
10/13/2024 37
PIC 16FXXX Microcontroller
STACK
Ana Program
Goto Program 1
1000h 1000h 2050h 1000h
1000h
4
1
Son
Program 1
2000h
Goto Program 2
2050h
Dön
2 3
Program 2
3000h
38
Dön
PIC 16FXXX Microcontroller
39
PIC 16FXXX Microcontroller
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.
41
PIC 16FXXX Microcontroller
(Flag Register)
42
PIC 16FXXX Microcontroller
Status Register (Flag Register)
44
PIC 16FXXX Microcontroller
Status Register (Flag Register)
45
PIC 16FXXX Microcontroller
Status Register (Flag Register)
bit 7 (IRP): Register Bank Select bit (used for indirect addressing)
1 = Bank 2, 3 (100h - 1FFh)
0 = Bank 0, 1 (00h - FFh)
bit 6-5 (RP1:RP0): Register Bank Select bits (used for direct addressing)
11 = Bank 3 (180h - 1FFh)
10 = Bank 2 (100h - 17Fh)
01 = Bank 1 (80h - FFh)
00 = Bank 0 (00h - 7Fh)
Each bank is 128 bytes
46
PIC 16FXXX Microcontroller
General-Purpose Registers
General-Purpose registers are used for storing temporary data and results created
during operation. For example, if the program performs a counting (for example,
counting products on the assembly line), it is necessary to have a register which
stands for what we in everyday life call “sum”. Since the microcontroller is not
creative at all, it is necessary to specify the address of some general purpose
register and assign it a new function.
A simple program to increment the value of this register by 1, after each product
passes through a sensor, should be created.
Therefore, the microcontroller can execute that program because it now knows
what and where the sum which must be incremented is. Similarly to this simple
example, each program variable must be pre-assigned some of general-purpose
register.
47
PIC 16FXXX Microcontroller
ACCESSES
48
PIC 16FXXX Microcontroller
SFR Registers
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.
For example, by changing the TRISA register, the function of each port A pin can be
changed in a way it acts as input or output. Another feature of these memory
locations is that they have their names (registers and their bits), which considerably
facilitates program writing. Since high-level programming language can use the list
of all registers with their exact addresses, it is enough to specify the register’s name
in order to read or change its contents.
49
SFR Registers in Bank 0
50
SFR Registers in Bank 1
51
SFR Registers in Bank 2,3
52
INSTRUCTION SET
Conssist of 4 fields
Operand
Instruction from to
Assuming W=h’FB’
PORTB=h’03’
PORTB=b’00000001
(PORTB=h’01’ )
MOVLW b’00001010’
MOVLW h’0A’
MOVLW d’10’