You are on page 1of 66

Microprocessors and Laboratory

• Dr. Unal Kucuk


• Useful Resources
• 1. Book 1: Designing Embedded Systems with PIC Microcontrollers_Principles and
Applications-Newnes (2006), Tim Wilmshurst
• 2. Book 2: C programming for embedded systems, Kirk Zurell, Elsevier 2000
• 3. Book 3: Embedded Systems Architecture, Tammy Noergaard, Elsevier, 2006
• 4. Lecture Document Dr. Unal Kucuk
• MC-04 PIC Programming and experiment kit booklet.
• Arm Training https://www.arm.com/resources/education/education-kits/efficient-
embedded-systems
• STM32 training
https://www.st.com/content/st_com/en/support/learning/stm32-education.html
• MSP430 training
https://dev.ti.com/tirex/explore/node?node=AL1cTv9MtErSpQwUL56jsQ__IOGq
Zri__LATEST
• www.keil.com
Syllabus

Arel University Embedded Systems Club


Topics
• Introduction- History
• Number Systems and Code Systems 2
• Basic Microprocessor architectures
• ALU, Address and Buses, Registers 2
• Assembler programming 2
• Interrupts, Interrupt structures 1
• Introduction to C programming in embedded systems
• Compilers
• C language structure, basic concepts, Atoms
• Directives, pre-processors
• Identifiers, data types, constants, variables, arrays, pointers
• logical operators, relational operators,
• Decision and loop commands 4
• Microprocessor peripherals 3
• GPIO
• UART, SPI, I2C
• ADC
Development of computer systems
• Computer systems are developed according to what we can call
abstraction layers.
• Abstraction layers allow people to develop computer components
(hardware and software) without needing to have detailed
knowledge about the internal design of other layers in the system .
• Abstraction layers
1. Application - Software
2 . Operating System - Sofware
3 . Firmware
4 . Instruction Set Architecture – Low level software firmware specifications
5 . Microarchitecture - Hardware
6 . Physical Circuit Layout - Hardware
Microprocessor (MPU)
• A microprocessor is an integrated circuit that processes the commands given in
the desired order through the hardware on it.

• In this respect, there are 2 hardware basic components


• Hardware required to perform operations requested by commands
• Hardware used to receive and interpret given commands

• These hardware structures are called Micro Architecture . Microarchitectures are


different according to the processors models and manufacturers.

• The commands and operation structures to be used on a processors which are


interpreted and implemented by the microarchitecture are defined by
Instruction Set Architecture (ISA) .

• Instruction set architectures are common to many processors. For example, Intel
instruction set architecture IA32/IA64 is also used by AMD processors.

• Other most common ISAs include ARM, MIPS , Motorola 68K , Risc V.
Microprocessor (MPU)
• A computer system has 3 basic hardware
components.
• CPU (central processing unit) consists of ALU and
control unit. Control unit provides information
exchange and analyzes the meaning of the code
according to ISA. ALU makes computation
• Memory: It is where program commands and data are
stored.
• Input/Output units: Allow the CPU to receive
information from the outside world and transfer
information to the outside world. They are also called
Peripheral units .
• An integrated circuit containing a CPU is
called as microprocessor .

Microprocessors work using only binary numbers


Binary numbers 0: usually 0V and 1 are represented by a certain voltage level (such
as 3.3V, 1.8V, 5V).

Microprocessor units are units that process the information they receive from the
memories with which they communicate, on basic processing units such as an ALU
(unit where addition, subtraction, translation and logic operations are performed)
and Multiplier, and write it back to the appropriate location of the memory. These
memory units can also be input and output units.
Example of 2-bit multifunction ALU
• The following examples can be given to frequently
encountered commands
• Arithmetic commands : Addition, Subtraction, (Multiplication,
division): Arithmetic commands are performed as integers by
default. However, there are special units that can perform
floating-point operations for more precise numbers.
• Logic commands : Translation, Logic operations: AND, OR, XOR,
Inversion
• Data transfer : Move , Load , Store
• Branching and Jumping

PC: Program Counter


• The Number of the bits that ALU can process, the number of the
addresses of the memory and the size of the data stored in a
memory address in bits determine the capacity of the processor
and bit number.
• An 8-bit processor with a capacity of 1 MB can address 2 20 =
1,048,576 different addresses (20-bit addressing bus), and each
address has an 8-bit data (8-bit bus). It is specified by the CPU
bus width.
CPU, 8 Bit
Address Path
ALU 20 bits
8 bits
Memory

Control Units Data Bus


8 bits

Example: 1MB capacity, 8-bit processor and memory


Evolution of Processors
• The first computers, such as ENIAC (1945), were built with completely discrete systems. They
were very large architectures.
• With the invention of transistors, the emergence of microprocessors was with Intel's 4004 (4
bit data bus and composed of around 2300 transistors ) (1971)
Number of Number of
Bits Intel Motorola Other Release Year transistors Speed Address
4004 1971 2,250 0.05 MIPS 12 bit 10um
4 Rockwell PPS-4 1972
8008 1972 3,500 0.05 MIPS 14 bit
8080 6800 RCA 1802 1974 5,000 0.64 MIPS 16 bit
ZILOG Z80 1975 8,500 2 MIPS @8MHz 16 bit 4um
8 MOS Tech. 6502 1976 3,500 1MIPS @ 3MHz 16 bit
8086 1978 29,000
8088 68000 1979 68,000
16 80286 1982 120,000
80386 1985 275,000 20 -24 bits
1,180,000/
32 80486 DX ARM3MCU 1989 310,000 32bit 4GB
Pentium PowerPC 1993 3,100,000 32bit 4GB
Cyrix 6x86 1996
Pentium II MMX AMD K6 1997 7,500,000
Pentium III 1999 24,000,000
Pentium 4 2000 42,000,000 32bit 4GB
IBMPower PC G5 2003 58,000,000
Core 2 Duo, Dual Core
Xeon 2006 291,000,000 65nm
I define 9000 montecito,
128 bit FSB 2007 1,800,000,000 90nm
>100,000 MIPS/
i7 Skylake, 4 core ARM Cortex A72 MCU 2015 1,750,000,000 18,000 MIPS 36bit 64GB 14nm
64 AMD Ryzen 1000, Zen 2017 4,800,000,000 12nm
4004 core

8080 processor

ARM610 chip die

The highest number of transistors by 2022 is 134 billion


transistors with Apple ARM-based dual-die M2 Ultra SOC (MPU
+ Graphics processor) produced by TSMC with 5nm tech.
MCU (Micro Controller Unit )
• Following years, in order to reach more compact designs, especially small memory
processors, equipped with peripherals, the concept of microcontroller has emerged.
Today, microcontrollers with memory capacities extending to MB’s can be found in
the market.

The first popular microcontroller was Intel's 8-bit 8051 , introduced in 1980. In addition to
internal memories, it contained peripherals such as a timer, serial port, and programmable
input and output connections. Even today, there are different featured products from different
manufacturers that still use the 8051 core.

MSP430 family from TI, which continues to be used intensively today with its developing
content, was the first 16-bit microcontroller released in 1992.
• The ARM core, which emerged in the early 1990s , has been used extensively in the
mobile phone market since 1995, thanks to its RISC structure and low power,
became one of the first 32-bit microcontroller in the market.
• In the mid-2000s, NXP and ST introduced the LPC and STM32F1 ARM MCU families,
respectively, which would attracted great attention in the market with the ARMv7-
based ARM Cortex-M3 license.
• Today , the Microcontroller market hosts thousands of 8, 16 and 32 bit
microcontrollers from simple to advanced .

Embedded systems
• What is an embedded system ?
• Application specific computer system
• Integrates into larger systems
• Real time limitations embedded
• Why are embedded systems integrated into a system
larger system ?
• better performance
• More functions and content
• Lower costs
• Reliability
Embedded
Input from software
Computer Output to the
the hardware
environment
environment
User Connection to
Interface other systems
CPU → MCU → Embedded systems
• Embedded system
• Typically implemented with MCUs
• It is often integrated into the larger mechanical and
electronic system.
• They often have real-time limitations.

Embedded
system
WHERE ARE THE EMBEDDED SYSTEMS?
• Industrial Automation/Test/Production systems
• Aerospace industry
• Automation
• military devices
• production devices /robotic systems
• Radar/Sonar...
• CNC / 3D printers...
• weapon systems
• Industry 4.0 infrastructure devices
• Airplane/missile/ D rone ...
• ...
• Communication / network devices
• customer electronics
• Modem
• Phone/television/ monitor
• gateway
• fax /copier/printer/scanner
• router
• white goods
• Smart home and Buildings
• Sound and music systems
• Gateway
• small appliances
• sensors



and much more....
Cameras/projectors

IoT : Internet-connected devices




Actuators
Lighting
• Lift
• Automotive
• HVAC
• Brake system
• Smart grid devices
• ignition system
• counters
• fuel control system



Embedded systems are
Sound system
Sensors
Comfort systems



Quality analyzers
Protection and control devices
test equipment
• SCADA systems



everywhere.
Autonomous driving support systems
Battery management systems
Positioning systems...
• Energy production, collection,
• solar panels
• wind turbines
• inverters
• healthcare industry
• charging stations
• Diagnostic and treatment devices....
• Fuel pumps
• Prosthetics/headphones...
• ....
• agricultural applications
• Banking and commerce
• Dosing systems
• Payment systems POS devices
• seed systems
• cash registers
• Soilless agriculture...
• ATMs _
• measuring systems
• counting money
• Scales/distance meters/measuring instruments..
Basic concepts
• Memories
They are readable and writable units on which
data is stored. Accessing memory is done using
the memory address. MCUs have internal
memories. In MPUs , memory is usually
connected externally.

• Registers are special-purpose memories that


store data for data processing and configuration
of MPU. Registers used for configuration and
specific purposes are generally called as SFR
(Special Function Registers) . The others are
called as general purpose registers which are
used for data processing. Most of the register
are defined in special addresses on the memory
embedded in the MPU . Some are used with
direct access inside the CPU .
• Memory Types
• Temporary memories ( Volatile Memory): They lose the information
in them when the power is cut off. This type of memory can be read
and written an infinite number of times and very fast. Therefore, they
are fundamental components of computer architectures for
processing variable data.

• RAM Random Access Memory : Randomly accessed memories. Reading


and writing are unlimited. However, if the power is cut off, its contents are
deleted. Data memories are used as RAM. It is also used as code memory in
PCs or advanced systems. However, with a boot process, codes are
transferred from permanent memories to RAM memories.
• SRAM: Static RAM is the fastest type of memory and works in parallel (Address and
data buses are separate and in parallel structure. Today, SRAMs with sub-
nanosecond access speed are available. Typically, 5-6 transistors are used for each .
For example, a 1MB SRAM is on average It consists of 5 – 6 million transistors . Since
small size memories are sufficient, they are mostly used in embedded systems .
However, They are used as L1 and L2 caches in large systems . External SRAMs are
not used much today (except Dual Port)

• DRAM: Dynamic RAMs are mostly used PC, Laptop etc which requires large
memories. Since DRAMs typically use 1 transistor and capacity for each bit , they are 4GB
cheaper and larger in size than SRAMs . Their speeds are slower than SRAM . Even if
there is energy, the information inside will be deleted if it is not refreshed . DRAM
Therefore, control circuits for Refreshing DRAMs are alos required . Today Single
chip DRAMs up to 64GB are available. Embedded systems are rarely uses DRAMs.

• FRAM : It is a new generation technology and exhibits RAM features. But electricity
data is preserved when gone. Write lifetime is over 100 trillion . Since small sizes are
currently available, they are mostly used in Embedded systems. Serial
FRAM
• Non - Volatile Memory: These types of memories are used as program memories, boot
memories, data storage memories or configuration memories.
• ROM Read Only Memory-Parallel : Used to store program commands and constants. They can
only be read, but not written . They are parallel and fast. They are not much used today.

• FLASH memories - Parallel: These memories are mostly for reading purposes. However, the
writing process can be done several thousand times. Since the writing process is in blocks and
slow, it is not suitable for storing frequently variable information. They are mostly used as
program memory and to store some settings of constants. Today's MCUs mostly use Flash
memory as program memory. Although their reads are fast, their writes are slow and occur in
the form of sectors. In PC or Laptop applications, they are used only as boot software memory.
Their sizes can reach GBs . Since Parallel Flash memories are used directly inside MCUs , there is
usually no boot process. Therefore, embedded systems They can be activated within ms's .

• FLASH memories – Series : SSD, SDCard , MMC, eMMC , SPI-Flash memories are used for storage
and booting purposes. These types of memories are much slower than parallel memories
because they are used serially. Sizes reach TB s. It is appropriate to use this type of memory as
an I/O unit through serial buses (SPI, I2C etc..) .

• EEPROM ( Electrically erasable Programmable ROM ) Parallel-Serial: These are memories with a
write life of millions. These memories are often used to store parameters that need to be stored
but change frequently. Write speeds are slow. Data is preserved when the power goes out .
Their size can be 2 MB. It's not very big.
I/O units
• Units other than memory are considered I/O units. These
include serial memories connection structures.
• I/O units acn be accessed by
• Parallel addressing (with memory map and address resolvers)
• Serial communication (SPI, I2C, MODBUS, CAN, SATA, USB...)

• Among I/O units,


• GPIO, ADC, DAC, USART, Timers , I2S, SPI, Ethernet, USB, Wifi , BT control
units etc..
Classification of microprocessor architectures
• We can classify microprocessor architectures into two
categories with their subcategories.
Instruction Set Architecture (ISA) – Complexity based
classification
• Processors receive commands and data to be processed from memory and process them
on the ALU and control unit.
• Commands include addition, subtraction, assigning values, shifting, going to a specific
address, etc. They do a lot of things like.
• Commands are kept in memory with binary numbers called operand code (op - code ),
data can sometimes be included in the operand code and can range from one byte to
many bytes .
• There are two basic command structures according to the number of commands and
their complexity. ( EPIC, VLIW are rare)
• CISC ( Complex Instruction Set Computer )
• RISC ( Reduced Instruction Set Computer )

While CISC instructions can do more complex operations, they require more clock
cycles and more complex hardware. In a typical CISC processor, the number of
instructions can be 120 - 300 , while in RISC processors it does not exceed 35-60.
Commands are completed between 2 and 10 cycles . This reduces the amount of
transactions per second. To achieve the same speed as RISC, the CISC processor must
operate at a higher frequency. It both increases power consumption and heats up.
The LDAX B instruction for 8080 takes 7 c .
• In RISC processors, almost every instruction is completed in 1
cycle .
• Advantages of RISC Architecture
• Using a microprocessor with a RISC design offers many advantages over using
a comparable CISC design .
• Speed: Because the reduced instruction set allows for single cycle operation
and superscalar (parallel processing) design, RISC processors often 2 – 4
times outperform to CISC processors using comparable semiconductor
technology and the same clock rates .
• Simple Hardware: Since the instruction set of the RISC processor is very
simple, they use very little chip space. Extra functions, memory controllers or
floating point arithmetic units are also placed on the same chip .
• Short Design Time : Since RISC processors are simpler than CISC processors,
they can be designed more quickly and can apply the advantages of other
technological developments more quickly than CISC designs.
RISC processors are used more intensively today. Many
microcontrollers are in RISC structure.
Instruction Set Architecture - Classification based on
instruction processing methods

• Memory-to-Memory : This type of ISA allows more than one operand of most
instructions to be in memory . VAX and PDP series are examples of this type of
architecture .

• Register -Memory: These architectures allow one operand of an instruction to be


defined in memory , while the other operand is in the CPU register. x86 and Motorola
68k are examples of this architecture. In this ISA , individual instructions are executed
faster compared to memory-memory based ISA due to fewer memory accesses .
However, this may require more cycles to complete the same task.

• Register-Register : This ISA classification is also called load-store architecture . In this


ISA Direct access to memory is not allowed for most instructions . Only the so -called
Load and store instructions are responsible for any movement of data between
registers and memory. All instructions, except the load and store instructions, get
their operands from registers and keep their results in registers.
• load - store architecture are very fast, in most cases they are done in a single clock cycle. However
, the Load-Store structure requires a larger number of instructions to complete a given operation.
• ARM and MIPS, RISC-V processors belong to this ISA class.
Classification by Memory Access
• Basic processor architectures are concerned
with how the processor receives instructions
and data. There are two architectural
approaches to this issue.
• Von-Neumann Architecture :
Data and program codes are in the same
memory. So it runs slower. However, it provides
convenience and simplicity in structure.
• Harvard Architecture
Data and program codes are in separate memories. Thus, faster results are
achieved by working in parallel.

• Modified -Harvard Architecture ,


• Both architectures have their pros and cons . So, many processors, uses both
structure where Cache memories are used with Harvard architecture while external
memory uses Von-Neuman architecture.
• For example, x86-based processors use Von-Neuman Architecture, while RISC
processors use Harvard or most Modified -Harvard Architecture.
Software Environment
• Machine language (op - code ) is used in the programming of processors at
lowest level . However, this is very primitive and was only used in the early
years of processors.
• Assembler Language : Since machine codes were not useful, symbolic codes
representing these codes emerged. These codes are called assembler
codes. As the processors are different from each other, the assembler
languages are also different from each other. Separate assembler software
is required for each processor . Assembler codes are translated into
machine codes with a compiler and transferred to the processor.
A machine code for
multiplication operation

An Assembler code written for


the Atmel ATMega128 AVR
processor
IDE or text Assembler linker
editor Compiler
Assembler
code . out etc. machine
. asm etc. code
. hex , .bin
etc.

Today , the use of assembler language is negligible. Most embedded


systems does not contain any operating system, does not have enough
memory and memory management units to have a high level operating
system. Some of them uses primitive OS’s such as RTOS which only have
scheduler and simple task management. In these kind of systems C are
used extensively.

The Assembler language is only rarely used for code optimization


purposes (speed or memory footprint). Or it is used in processors with
very small memory that will do very simple simple operations.

In this course, Assembler will be used in a limited way to get acquainted


with the processor hardware and the concept, and we will mainly study
on C.
Lab and development environment
NUMBER SYSTEMS
• Decimal numbering system is used in our daily life . However, computer
systems use Binary numbering system. The base is 10 in the decimal
system and the base is 2 in the binary system .
• In numbering systems, each digit that makes up a number is called as
digit . While, In decimal systems, each digit is a decimal digit or just
digits , in binary systems It is called binary digit or bit for short .

123456 6 digit decimal number


100101 6 bit binary number
• Number symbols are between 0 .. (Base –1).
• In decimal, the digits are 0..9, in binary the digits are 0, 1 .

• Generating numbers
• 123456 = 1*10 5 + 2*10 4 + 3*10 3 + 4*10 2 + 5*10 1 + 6*10 0
• 100101 = 1*2 5 + 0*2 4 + 0*2 3 + 1*2 2 + 0*2 1 + 1*2 0
BYTE, WORD AND NIBBLE CONCEPTS
• eight-bit binary numbers are called as Byte
• 10011101 8 bit or one byte
• Althought Word is generally associated with 16-bit numbers,
This concept is sometimes paired with the number of the bus
length of the processor.
• 11001001 11100011 2 bytes or one word.
• Nibble is 4 bits
POSITIVE AND NEGATIVE NUMBERS
Let's look at the smallest and largest positive numbers of one byte

00000000 ( decimal 0) 11111111 ( decimal 255)


• All numbers here are positive. In other words, the number is unsigned.

• negative numbers, it can be said that half of these numbers are positive and half are
negative.
For example , 1 byte number will vary between -127 and +127 .
• In binary , negative numbers are represented by complementary numbers so that
subtraction can be done through addition .

• Complementary number is the number that completes the given number to the
largest number represented for that number of bits. (It is practically done by
inverting bits.)

• For example 00001010 Its complement is 11110101 . (255 –10). This type of
complement is called as 1 's complement. Notice that the most weighted (leftmost)
bit is 1 for negative numbers. It is not used much in practice because there are two
0's here (0000 0000 and 1000 0000) and subtraction cannot be obtained by direct
addition of the processor.
Two 's Complement (2's Complement )
two 's complement number has a single 0. The numbers range from -2 bitnumber-1 .. 0 .. (2
bitnumber-1-1 ) . For example -128 ..0 ..127 for 8 bits .

The two 's complement number is obtained as follows .


2 bits - number

Example : Let's express the number -20 - ( 0001 0100) as an 8-bit binary number
2 8 -20 =256 –20 =236= 1110 1100

practical method is to invert the number and add 1.


0001 0100
1110 1011 + 1 = 1110 1100

Subtraction: For example , 2 's complement 40 –20 Let's calculate.


Hexadecimal numbers ( Hex )
In computer systems , hexadecimal numbers are use to avoid very long bit
sequences. Hex numbers are 16 based numbers with each digit represent a
nibble. Symbols of Hexadecimal systems are as follows

0000 0 0001 1 0010 2 0011 3


0100 4 0101 5 0110 6 0111 7
1000 8 1001 9 1010 A 1011 B
1100 C 1101 D 1110 E 1111 F

Since hexadecimal numbers are used very often, they should be well known.
Example :
0011 1010 = 3A Hex, 1110 0101 = E5 Hex
0101 1101 1100 1001 0110 0111 =5DC967 Hex

0x3A convert these to decimal decimal equivalent 3* 16 1 + 10* 16 0 = 58


0x5DC967 5*16 5 + 13*16 4 + 12* 16 3 + 9*16 2 + 6*16 1 + 7*16 0 = 6 146 407
Fractional numbers
There are two ways in the representation of fractional numbers in
microprocessor architectures
• fixed point
• Floating Point

FIXED POINT NUMBERS


However, the representation of the decimal point in fixed-point arithmetic in
microprocessor systems is imaginary. There is no recorder keeping the position of the
point. The location of the point is controlled by software. Operations are done as
integers, but the location of the decimal point is controlled in software. The result is
considered fractional.
For example for fixed point if there is a 16 bit number
We can use the bc format. Here b will be the digit number of the integer part, and c
will be the digit number of the fractional part.

In addition, both formats must be the same. For example, both numbers must be in Q15
format. If not, it should be shifted to fit one of the numbers.

For example, let's consider 2 numbers of 8 bits.


110.11010 (a number in the format 3.5, its decimal value is 6+26/2 5 = 6.8125 )
10.010011 (a number in 2.6 format, decimal value is 2+19/2 6 =2.296875 )

The bottom number is shifted one right. It is converted to 3.5 format and summed (the
smallest digit will be lost.)

110.11010 (6.8125)
There was an overflow. the format will
010.01001 (2.28125)
be 4.4.
+__________
The smallest digit is shifted to the right
1 001.0001 1
and discarded.
Result : 1001.0001 (9.0625) (Rounding errors will occur due to shifts (actual value would be
9.109375). If these errors are not desired, more bit space should be reserved for numbers.
After the multiplication of fixed point numbers , 2 times length should be reserved for
the result . For example, at least 16 bits must be reserved for the product of 2, 8-bit
numbers.

multiplication of signed numbers : when msb bit is kept as sign bit, there will be 2 sign
bits as a result of multiplication, so the result is used by shifting 1 bit to the left.

For example, let's multiply two signed numbers in the format Q15 (1.15). Result will be
Q30 (2.30) . Since there will be two sign bits in this number, the number should be
converted to Q31 (1.31) format by shifting 1 bit.

• Let's multiply 2 8-bit numbers in Q7 format. The format is 1.7 and the numbers range
from -1 to 127/128.
0.1111100 (124/128= 0.96875) and
1.0100000 (-0.75 ) ( -96/128 (256-96 two's complement ))
X ___________________
Result 11.01 0001 1000 0000 (format 2.14). The result (because it carries 2 sign bits is
shifted to the left by 1 bit as (1.15) will be formatted.
1.010 0011 0000 0000 -0.7265625 ( for reversing to decimal (2 16 - 41728) / 2 15 )
Floating Point numbers
• Floating-point numbers are used to perform precision fractional operations and
mathematical operations with a wide dynamic range. Low - end and mid-range
processors often lack the necessary infrastructure for floating point operations.
• Floating point numbers are represented by a signed mantissa and exponent.
For example y= m* b e Here m: the mantissa part, b: base, e: exponential .

Floating-point numbers are stored in a variety of formats. The most widely used
format is IEEE/ANSI 754. This format is 32 bit and has the following structure.

Therefore, at least 2 registers are needed for the representation of numbers.


Floating-point processors perform these operations in 1 cycle thanks to their special
hardware, while fixed-point processors use library software for this work and do 20-
40 cycles .
LOGICAL OPERATIONS
• The ALU within a processor can perform bitwise AND, OR, XOR
and inversion operations.
Bit-based logical operations
!&|^

Depending on the ALU structure, more than one bit is processed simultaneously.
For example, an 8-bit ALU will perform operations on two 8-bit numbers .
Examples
• Let's use 8 bit numbers
• Let A: 0x35, B=0x28
• R=A&B=?
• A= 0011 0101
• B= 0010 1000
• R= 0010 0000 = 0x20

• R=A|B=? • R=!A=?
• A= 0011 0101 • A = 0011 0101
• B= 0010 1000 • R = 1100 1010 = 0xCA
• R= 0011 1101 = 0x3D
• R = A ^ 0xFF ?
• R=A^B=? • A = 0011 0101
• A = 0011 0101 • 1111 1111
• B= 0010 1000 • R= 1100 1010 = 0xCA
• R= 0001 1101 = 0x1D
If a number is xored with logic 1 ,
result will be inverted.
SHIFTING OPERATION
Logical shift Arithmetic shift

<<

>>

rotation
CODE SYSTEMS
• Computers only work with numbers, whereas we need letters and
other symbols as well. These symbols are also encoded in such a way
that they correspond to numbers. For example, if the program
encounters this number, it prints the corresponding symbol on the
screen, or prints the symbolic equivalent of the number coming from
the keyboard .

• Although there are many encoding types, ASCII (American National


Code for Information Interchange) was standardized by ANSI in 1963 in
computer systems in the world. Today, ASCII is still used in many
embedded systems, however UNICODE coding is used on computers,
since ASCII codes are insufficient to provide multilingualism .
UNICODE is the extended version of the ASCII system.

• ASCII is basically 7 bits. It consists of 127 characters. But with the


Extended part, 8 bits are used. However, the symbols in the
extended part may vary according to the software environment.
extended part
ASCII Communication SCREEN

DEVICE 0x48
0x45 H E

• Among other coding systems


• UNICODE
• UTF-8 (ASCII compatible) however, can use character codes of different
lengths.
Microcontrollers
• Microprocessors are mostly used in advanced systems with enhanced MMU’s (where they
have advanced operating systems on them such as computers, workstations ) , MCUs are
used in small systems and end consumer devices. This course will focus on MCUs.
• MCUs contain memory and peripherals in addition to the CPU and generally use the Harvard
architecture . They do not support parallel external memories (DDRAM etc. ) since dont have
MMU’s.
• MCU’s are classified according to the memory sizes and the number of the peripherals it
contains
• Lower segment ( Low-end )
• middle segment ( mid range )
• Upper segment (High - end )
For example;
• lower segment processor, Flash memory amounts of 2-4BK, RAM memory amounts up to
0.5 – 1KB and there are few peripherals such as timer, serial port and few I/O terminals.
• In mid-range processors, these quantities are found in 20 – 64KB Flash, 16 – 20K Ram,
ADC, I2C, SPI, UART, advanced timers, DMA, Large GPIO units.
• In the upper segment MCUs, Flash memory sizes are 4-16MB , RAM goes up to 1-2MB ,
There are much more advanced peripherals (ADC, I2C, SPI, UART, Very advanced timers,
USB, MAC, AES, LCD, DMA etc.) . )
POPULAR MCU series
• As mentioned earlier, there are many companies in the MCU market.
Leaving the custom MCUs aside, the main manufacturers are shown in the
table below .
• Accordingly, in the 8-bit cheap
processor market, Microchip is the
leader after Atmel 's acquisition. PIC
series and AVR series MCUs are
quite popular .

• In 16 bit market, the TI MSP430


family is at the top with the Renesas
RL78 family.

• 32-bit processors, they share the


first places with ARM core
processors Renesas RA series, NXP
LPC series, ST STM series.

• Apart from these, Wireless


connected Wifi , Bluetooth etc.
Nordic , TI, ST, Espressif , Onsemi ,
Silabs stand out in the MCU market
.
• Intel 8051 MCU with Von-Neuman architecture, which was once the market leader in 8 bit, is now
only used as processor core by some Far Eastern manufacturers ( Nuvoton , Vango etc. )

Example subsegment 8-bit processor table


https://www.microchip.com/en-us/parametric-search.html/717 _

UART
Program Max 8 Bit Max 16 with
Memory Pin Number Digital Bit Digital Protocol USB
Product Status Size (KB) RAM (B) Count of ADCs Timers Timers Support SPI™ I2C Interface
PIC10F220 In Production 0.375 16 6 1 1 0 0 0 None
PIC10F204 In Production 0.375 16 6 0 1 0 0 0 None
PIC10F200 In Production 0.375 16 6 0 1 0 0 0 None
PIC10F320 In Production 0.448 64 6 1 2 0 0 0 None
PIC16F54 In Production 0.75 25 18 0 1 0 0 0 None
PIC12F508 In Production 0.75 25 8 0 1 0 0 0 None
PIC10F222 In Production 0.75 23 6 1 1 0 0 0 None
PIC10F206 In Production 0.75 24 6 0 1 0 0 0 None
PIC10F202 In Production 0.75 24 6 0 1 0 0 0 None
PIC10F322 In Production 0.896 64 6 1 2 0 0 0 None
PIC16F527 In Production 1.5 68 20 1 1 0 0 0 None
PIC16HV540 In Production 1.5 25 18 0 1 0 1 1 None
PIC16F526 In Production 1.5 67 14 1 1 0 0 0 None
PIC16F506 In Production 1.5 67 14 1 1 0 0 0 None
PIC16F505 In Production 1.5 72 14 0 1 0 0 0 None
PIC12F519 In Production 1.5 41 8 0 1 0 0 0 None
PIC12F510 In Production 1.5 38 8 1 1 0 0 0 None
PIC12F509 In Production 1.5 41 8 0 1 0 0 0 None
PIC12F1571 In Production 1.75 128 8 1 2 4 0 0 None
PIC12F1501 In Production 1.75 64 8 1 2 1 0 0 None
PIC16F84A In Production 1.75 68 18 0 1 0 0 0 None
PIC16F818 In Production 1.75 128 18 1 2 1 0 0 None
Example 16-bit processor parametric table
https:// www.ti.com/microcontrollers-mcus-processors/microcontrollers/msp430-
microcontrollers/products.html
Example 32-
bit ARM
processors
STM32F1xx

STM32
product map
Data type and capacities
• Data types in MCUs can be of various types. These are bit, nibble
, byte , word , double word . The table below shows data types
and capacities.
Architectures of various processors
Intel 8051 microcontroller
ADSP2181 Digital Signal Processor block diagram
STM32F1xx
ARM
Cortex-M3
processor
block
diagram
Processing commands
• A Command states an operation which is done in 1 step. For example,
adding 2 numbers, shifting the number, writing or reading to memory
or to an input-output unit.
• In microprocessor architectures, the central processing unit generally
processes commands in the following order.
1. Read (command) address content in program memory, indicated by program
counter
2. Send the command to Instruction decoder.
3. The Instruction decoder parses the command and CPU performs the necessary
operations.
4. Create new value of program counter (PC=PC+1 or PC= PC + n or PC= X) Go back
to step 1.

To perform this operation, a clock period ( clock cycle ) is used. RISC processors
generally perform an operation in the same cycle . As the cycle gets shorter (as the
frequency increases), the number of commands processed per second will increase.
For example, in RISC processors, for 1MHz clock 1 million commands are processed in
second. In SuperScalar RISC processors, since more than one instruction will be
processed in 1 Cycle , the number of instructions processed per second is higher than
the operating frequency.
Coding of commands
• Instructions are encoded on the program memory according to the capability
of the processor. For example
Command Parameters 16 bit
code (6bit) 10 bits instruction
The size of the instructions is adjusted according to the number of bits of the processor
program memory. For example, the command code is 6 bits, the parameters are 10
bits, 16 bits in total.
Since commands would be difficult to prepare in this way, each command is encoded
with a representative word. This coding format is called assembler language.
Below are the instruction codes and symbolic definitions for the now obsolete 6800
processor with von-neumann architecture .
Memory Memory Command
Address Data Name Description
0x0020 0xA6 LDA Store Data to Accumulator Register A from Memory
0x0021 0x50 Memory Address H
0x0022 0x01 Memory Address L
0x0023 0xBB ADD Add Accumulator A and Memory Data to A
0x0024 0x50 Memory Address H
0x0025 0x02 Memory Address L
0x0026 0xB7 STA Store Accumulator To memory
0x0027 0x50 Memory Address H
0x0028 0x03 Memory Address L
0x0029 0x3E HLT Halt
A program example such as X+Y=Z

Assume X is stored in 5001H,


Y is stored in 5002H and
Z is stored in 5003;
then the operation will be (5001H) + (5002H) = (5003H)

Operation will be done in processor as follows;

• The value in 5001H is loaded to A register

• The value in 5002H will be added to A register

• Finally, The value in A Register is stored to 5003H

• Program stops
Stack
• It is one of the important concept in microprocessor systems.

• Stack is an area of memory necessary for the program flow to


resume when a subroutine is called from within a running
program or when returning from interrupt subroutines that
divide the program flow and call another subroutine.

• They are defined on RAM areas, usually in data memory or


specially allocated memory. There is an address pointer that
shows the address of the stack . This pointer is inaccessible in
most cases. It is kept inside the processor.

• Stack uses last in first out (LIFO) method


Stack work
Program program
address command Program program Program program
address command address command
… … 6000 CommandA 2 2000 CommandB1
1500 command1 1 1
2001 CommandB2
1501 command2 6001 CALL 2000
2002 Command B3
1502 CALL 6000 6002 Command
4 A3 3 2003 RETURN
1503 command4
… … 6003 RETURN
PC : Program
Stack counter The stack only
PC=6000 PC=2000 PC=6001+1 PC=1502+1 stores
Empty
Stack xxxx
addresses.
Indicator 1502 1502 1502 SP=SP-1 1502 After the
SP=SP+1 SP=SP-1 subprogram
6001 call, if the data
SP=SP+1 to be used
after the
return needs
to be stored
properly.
Program
should be
made
accordingly.

1 2 3 4
Stack
• PUSH is to add information to stack
• POP is to Get Info from Stack

A subroutine CALL, Interrupt calls and, if applicable, PUSH commands fall under the PUSH category.
RETURN and, if applicable, POP commands fall into the POP category.

STACK Overflow
If the stack depth is not handled properly, the microprocessor will overflow the stack to an unknown
address, the microprocessor will go to an unknown address, and the program will start to
malfunction. Until a reset procedure, the processor will not work properly.
To prevent overflow;
• Maximum consecutive stacks A number of push and pop operations that will not exceed the
depth should be performed.
• The number of POPs should be equal to the number of PUSH.
• first stack operation after reset should be PUSH.

You might also like