Lecture 1
Lecture 1
Microcontrollers
          Lecture 01
          Dr. Farzana Kulsoom
                                1
Objective of this Course
• Develop an understanding of the Intel family of
  microprocessors and its internals.
• Use the power of the microprocessor to process data from
  various I/O devices interfaced with the microprocessor over
  different channels.
• Gain practical insight in Interfacing Techniques with a course
  project.
                                                                   2
Recommended Books
1. The Intel Microprocessors Architecture, Programming and
   Interfacing by Barry B. Brey
2. The AVR Microcontroller and Embedded Systems by Mazidi ,
   Prentice Hall
                                                              3
Grading
• Rough Grade Breakdown
  Course Work
 Quizzes 15%
 Assignments 10%
 MID Semester Exam 25%
 End Semester Exam 50%
 Lab Work
 Lab Reports 40%
 Lab evaluation 20 %
 Project 40%
                          4
Microprocessors
•Uses of Microprocessors?
                             5
Microprocessor
• The microprocessor, also known as the Central Processing Unit
  (CPU),is the brain of all computers and many household and
  electronic devices. Multiple microprocessors, working together, are
  the "hearts" of data-centres, super-computers, communications
  products, and other digital devices.
• The microprocessor, is the controlling element in a computer
  system.
• The microprocessor controls memory and I/O through a series of
  connections called buses.
• The buses select an I/O and memory device, transfer data between
  an I/O device or memory and microprocessor, and control the I/O
  and memory system
• Memory and I/O are controlled through instructions that are stored
  in the memory and executed by the microprocessor
                                                                        6
Microprocessors
• A typical programmable machine can be represented with four
  components:
 microprocessor,
 memory,
 input, and output.
                                                                             7
• Microprocessor (MPU) - a semiconductor device (integrated
  circuit) manufactured by using the LSI technique.
  • It includes the ALU, register arrays, and control circuits on a single
    chip.
• These four components work together or interact with each
  other to perform a given task; thus, they comprise a system.
• The physical components of this system are called hardware.
• A set of instructions written for the microprocessor to perform
  a task is called a program, and a group of programs is called
  software.
Traditional block diagram of a computer
                                          8
Block Diagram
                9
Examples of Microprocessor Systems
•   Anti-lock brakes            •   Modems
•   Auto-focus cameras          •   MPEG decoders
•   Automatic teller machines   •   Network cards
•   Automatic toll systems      •   Network switches/routers
•   Automatic transmission      •   On-board navigation
•   Avionic systems             •   Pagers
•   Battery chargers            •   Photocopiers
•   Camcorders                  •   Point-of-sale systems
•   Cell phones                 •   Portable video games
•   Cell-phone base stations    •   Printers
•   Cordless phones             •   Satellite phones
•   Cruise control              •   Scanners
•   Curbside check-in systems   •   Smart ovens/dishwashers
•   Digital cameras             •   Speech recognizers
•   Disk drives                 •   Stereo systems
•   Electronic card readers     •   Teleconferencing systems
•   Electronic instruments      •   Televisions
•   Electronic toys/games       •   Temperature controllers
•   Factory control             •   Theft tracking systems
•   Fax machines                •   TV set-top boxes
•   Fingerprint identifiers     •   VCR’s, DVD players
•   Home security systems       •   Video game consoles
•   Life-support systems        •   Video phones
•   Medical testing systems     •   Washers and dryers         10
Why Use Microprocessors?
• Small in size
• Cheap to produce
• Able to take over a lot of tasks of varying nature
                                                       11
History of Computers
Abacus
• 500 BCE, used in Babylon
• beans or stones moved in grooves in sand or on tablets of
  wood, stone, or metal
• early form of beads on wires, used in China
• Primarily used in parts of Asia for performing arithmetic
  processes
12
                                  Chinese Abacus
Pascal Calculator
• Blaise Pascal invented the mechanical calculator in 1642
• The gears and wheels design helped in performing addition
  and subtraction
• Was able to perform the carry function
                                                              13
Charles Babbage
• Father of Modern Computer
• Babbage is credited with inventing the first mechanical
  computer
• In 1821 Babbage invented the Difference Engine to compile
  mathematical tables
• https://www.youtube.com/watch?v=BlbQsKpq3Ak
                                                              14
• Babbage conceived, in 1834, a more ambitious machine, later
  called Analytical Engine, a general-purpose programmable
  computing engine
• The Analytical Engine has many essential features found in the
  modern digital computer
• It was programmable using punched cards, an idea borrowed
  from the Jacquard loom used for weaving complex patterns in
  textiles
                                                                   15
Ada Lovelace
• First computer programmer.
• She wrote the programs for the analytical engine
                                                     16
Herman Hollerith
• He chose the punched card as the basis for storing and
  processing information
• He built the first punched-card tabulating and sorting
  machines as well as the first key punch
• He founded the company that was to later become IBM
                                                           17
   Hollerith Punched card
Alan Turing
• Alan Turing was an English mathematician, wartime code-
  breaker and pioneer of computer science.
• Invented Colossus, it was the world's first electronic, digital,
  fixed-program, single-purpose computer
• The Automatic Computing Engine (ACE) was an early
  electronic stored-program computer design produced by Alan
  Turing: The Imitation Game
                                                                     18
ENIAC
• In 1946, John Mauchly and John Presper Eckert developed the
  ENIAC I (Electrical Numerical Integrator And Calculator)
• The American military sponsored their research; the army
  needed a computer for calculating artillery-firing tables, the
  settings used for different weapons under varied conditions
  for target accuracy
• The ENIAC contained 17,468 vacuum tubes, along with 70,000
  resistors, 10,000 capacitors, 1,500 relays, 6,000 manual
  switches and 5 million soldered joints.
• It covered 1800 square feet (167 square meters) of floor
  space, weighed 30 tons, consumed 160 kilowatts of electrical
  power.                                                           19
ENIAC
        20
History of Microprocessors
• First transistor was invented in 1947.
• Fairchild Semiconductors (founded in 1957) invented the first
  IC in 1959.
• In 1968, Robert Noyce, Gordan Moore, Andrew Grove
  resigned from Fairchild Semiconductors.
• They founded their own company Intel (Integrated
  Electronics).
• Intel grown from 3 man start-up in 1968 to industrial giant by
  1981.
• It had 20,000 employees and $188 million revenue.
                                                                   21
Intel 4004
•   Introduced in 1971.
•   It was the first microprocessor by Intel.
•   It was a 4-bit microprocessor.
•   Its clock speed was 740KHz.
•   It had 2,300 transistors.
•   It could execute around 60,000 instructions per second.
                                                              22
INTEL 4040
• Introduced in 1974.
• It was also 4-bit μP.
                          23
INTEL 8008
•   Introduced in 1972.
•   It was first 8-bit μP.
•   Its clock speed was 500KHz.
•   Could execute 50,000 instructions per second.
                                                    24
INTEL 8080
•   Introduced in 1974.
•   It was also 8-bit μP.
•   Its clock speed was 2 MHz.
•   It had 6,000 transistors.
•   Was 10 times faster than 8008.
•   Could execute 5,00,000 instructions per second.
                                                      25
INTEL 8085 (Basic)
•   Introduced in 1976.
•   It was also 8-bit μP.
•   Its clock speed was 3 MHz.
•   Its data bus is 8-bit and address bus is 16-bit.
•   It had 6,500 transistors.
•   Could execute 7,69,230 instructions per second.
•   It could access 64 KB of memory.
•   It had 246 instructions.
•   Over 100 million copies were sold.
                                                       26
INTEL 8086(Revolution)
• Introduced in 1978.
• It was first 16-bit μP.
• Its clock speed is 4.77 MHz, 8 MHz and 10 MHz, depending on
  the version.
• Its data bus is 16-bit and address bus is 20-bit.
• It had 29,000 transistors.
• Could execute 2.5 million instructions per second.
• It could access 1 MB of memory.
• It had 22,000 instructions.
• It had Multiply and Divide
  instructions.                                                 27
INTEL 8088
•   Introduced in 1979.
•   It was also 16-bit μP.
•   It was created as a cheaper version of Intel’s 8086.
•   It was a 16-bit processor with an 8-bit external bus.
•   Could execute 2.5 million instructions per second.
•   This chip became the most popular in the computer industry
    when IBM used it for its first PC.
                                                                 28
INTEL 80186 & 80188
• Introduced in 1982.
• They were 16-bit μPs.
• Clock speed was 6 MHz.
• 80188 was a cheaper version of 80186 with an 8-bit external
  data bus.
• They had additional components like:
    •   Interrupt Controller
    •   Clock Generator
    •   Local Bus Controller
    •   Counters
                                                                29
INTEL 80286
•   Introduced in 1982.
•   It was 16-bit μP.
•   Its clock speed was 8 MHz.
•   Its data bus is 16-bit and address bus is 24-bit.
•   It could address 16 MB of memory.
•   It had 1,34,000 transistors.
•   It could execute 4 million
    instructions per second.
                                                        30
INTEL 80386 (Multitasking)
• Introduced in 1986.
• It was first 32-bit μP.
• Its data bus is 32-bit and address bus is 32-bit.
• It could address 4 GB of memory.
• It had 2,75,000 transistors.
• Its clock speed varied from 16 MHz to 33 MHz depending
  upon the various versions.
• Different versions:
    • 80386 DX
    • 80386 SX
    • 80386 SL
                                                                  31
• Intel 80386 became the best selling microprocessor in history
INTEL 80486
• Introduced in 1989.
• It was also 32-bit μP.
• It had 1.2 million transistors.
• Its clock speed varied from 16 MHz to 100 MHz depending
  upon the various versions.
• It had five different versions:
    •   80486 DX
    •   80486 SX
    •   80486 DX2
    •   80486 SL
    •   80486 DX4
                                                            32
• 8 KB of cache memory was introduced.
INTEL PENTIUM (Revolution..)
•   Introduced in 1993.
•   It was also 32-bit μP.
•   It was originally named 80586.
•   Its clock speed was 66 MHz.
•   Its data bus is 32-bit and address bus is 32-bit.
•   It could address 4 GB of memory.
•   First processor with multimedia games ability.
•   Could execute 110 million instructions per second.
•   Cache memory:
    • 8 KB for instructions.
    • 8 KB for data.                                     33
INTEL PENTIUM PRO
•   Introduced in 1995.
•   It was also 32-bit μP.
•   It had L2 cache of 256 KB.
•   It had 21 million transistors.
•   It was primarily used in server systems.
•   Cache memory:
    • 8 KB for instructions.
    • 8 KB for data.
    • It had L2 cache of 256 KB
                                               34
INTEL PENTIUM II
•   Introduced in 1997.
•   It was also 32-bit μP.
•   Its clock speed was 233 MHz to 500 MHz.
•   Could execute 333 million instructions per second.
•   MMX technology was supported.
•   L2 cache & processor were on one circuit.
                                                         35
INTEL PENTIUM II XEON
•   Introduced in 1998.
•   It was also 32-bit μP.
•   It was designed for servers.
•   Its clock speed was 400 MHz to 450 MHz.
•   L1 cache of 32 KB & L2 cache of 512 KB, 1MB or 2 MB.
•   It could work with 4 Xeons in same system.
                                                           36
INTEL PENTIUM III
•   Introduced in 1999.
•   It was also 32-bit μP.
•   Its clock speed varied from 500 MHz to 1.4GHz.
•   It had 9.5 million transistors.
                                                     37
INTEL PENTIUM IV
•   Introduced in 2000.
•   It was also 32-bit μP.
•   Its clock speed was from 1.3 GHz to 3.8 GHz.
•   L1 cache was of 32 KB & L2 cache of 256 KB.
•   It had 42 million transistors.
•   All internal connections were made from aluminium to copper.
                                                                   38
INTEL DUAL CORE
• Introduced in 2006.
• It is 32-bit or 64-bit μP.
• It has two cores.
• Both the cores have there own internal bus and L1 cache, but
  share the external bus and L2 cache
• It supported SMT technology.
    • SMT: Simultaneously Multi-Threading
    • E.g.: Adobe Photoshop supported SMT.
                                                                 39
INTEL CORE 2
•   Introduced in 2006.
•   It is a 64-bit μP.
•   Its clock speed is from 1.2 GHz to 3 GHz.
•   It has 291 million transistors.
•   It has 64 KB of L1 cache per core and 4 MB of L2 cache.
•   It is launched in three different versions:
    • Intel Core 2 Duo
    • Intel Core 2 Quad
    • Intel Core 2 Extreme
                                                              40
INTEL CORE I3
•   Introduced in 2010.
•   It is a 64-bit μP.
•   It has 2 physical cores.
•   Its clock speed is from 2.93 GHz to 3.33 GHz.
•   It has 781 million transistors.
•   It has 64 KB of L1 cache per core, 512 KB of L2 cache and 4 MB
    of L3 cache.
                                                                     41
INTEL CORE I5
•   Introduced in 2009.
•   It is a 64-bit μP.
•   It has 4 physical cores.
•   Its clock speed is from 2.40 GHz to 3.60 GHz.
•   It has 781 million transistors.
•   It has 64 KB of L1 cache per core, 256 KB of L2 cache and 8 MB
    of L3 cache.
                                                                     42
INTEL CORE I7
•   Introduced in 2008.
•   It is a 64-bit μP.
•   It has 4 physical cores.
•   Its clock speed is from 2.66 GHz to 3.33 GHz.
•   It has 781 million transistors.
•   It has 64 KB of L1 cache per core, 256 KB of L2 cache and 8 MB
    of L3 cache.
                                                                     43
INTEL CORE I9
•   Introduced in 2017.
•   It is a 64-bit μP.
•   It has 10 physical cores.
•   Its clock speed is from 3.3 GHz to 4.5 GHz.
•   It has 290 million transistors.(intel do not disclosed)
•   It has 16 MB of L3 cache.
                                                              44
Processor Generations
• Each generation has been made more power efficient
• lower heat generating.
• 7th generation laptop will be a lot thinner than a 4th
  generation.
• https://en.wikipedia.org/wiki/List_of_Intel_processors
                                                           45
  Hyper-Threading
• Turbo Boost is Intel’s marketing name for the technology that allows
  a processor to increase its core clock speed whenever the need
  arises. The maximum amount that Turbo Boost can raise clock speed
  depends on the number of active cores, the estimated current
  consumption, the estimated power consumption, and the processor
  temperature.
• Core i3 processors don’t have Turbo Boost, but i5 and i7s do. It
  means that Core i3 chips tend to have quite high ‘base’ clock speeds.
• If a processor model ends with a K, it means it is unlocked and can
  be ‘overclocked’. This means you can force the CPU to run at a
  higher speed than its base speed all the time for better
  performance.
• A dual-core processor running at a faster speed than a quad-core
  processor could have a similar performance overall.                     47
Types of Memory
                  48
Conti…
         49
Caches
• Cache: Smaller, faster storage device that acts as staging area
  for subset of data in a larger, slower device
• Fundamental idea of a memory hierarchy:
  • For each k, the faster, smaller device at level k serves as cache for
    larger, slower device at level k+1
• Why do memory hierarchies work?
  • Programs tend to access data at level k more often than they
    access data at level k+1
  • Thus, storage at level k+1 can be slower, and thus larger and
    cheaper per bit
  • Net effect: Large pool of memory that costs as little as the cheap
    storage near the bottom, but that serves data to programs at ≈
    rate of the fast storage near the top.
Types of cache memory
• Cache memory is fast and expensive. Traditionally, it is categorized
  as "levels" that describe its closeness and accessibility to the
  microprocessor. There are three general cache levels:
• L1 cache, or primary cache, is extremely fast but relatively small, and
  is usually embedded in the processor chip as CPU cache.
• L2 cache, or secondary cache, is often more capacious than L1. L2
  cache may be embedded on the CPU, or it can be on a separate chip
  or coprocessor and have a high-speed alternative system bus
  connecting the cache and CPU. That way it doesn't get slowed by
  traffic on the main system bus.
• Level 3 (L3) cache is specialized memory developed to improve the
  performance of L1 and L2. L1 or L2 can be significantly faster than
  L3, though L3 is usually double the speed of DRAM. With multicore
  processors, each core can have dedicated L1 and L2 cache, but they
  can share an L3 cache. If an L3 cache references an instruction, it is
  usually elevated to a higher level of cache.
• e.                                                                        51
• In the past, L1, L2 and L3 caches have been created using
  combined processor and motherboard components.
• Recently, the trend has been toward consolidating all three
  levels of memory caching on the CPU itself.
• That's why the primary means for increasing cache size has
  begun to shift from the acquisition of a specific motherboard
  with different chipsets and bus architectures to buying a CPU
  with the right amount of integrated L1, L2 and L3 cache.
                                                                  52
Number Systems
• There is a speculation of the fact that Humans use base 10 system is
  because they have 10 fingers.
• But there is no speculation behind the fact that the computers use
  binary system.
• The decimal number system (base 10) you should be familiar with
• A digit in base 10 ranges from 0 to 9.
• A digit in base 2 ranges from 0 to 1 (binary number system).
• A digit in base 2 is also called a ‘bit’.
• A digit in base R can range from 0 to R-1
• A digit in Base 16 can range from 0 to 16-1
• (0,1,2,3,4,5,5,6,7,8,9,A,B,C,D,E,F). Use letters A-F to represent values
  10 to 15. Base 16 is also called Hexadecimal or just ‘Hex’.
                                                                             53
Positional Notation
• Value of number is determined by multiplying each digit by a weight
  and then summing. The weight of each digit is a
• POWER of the BASE and is determined by position.
base10
  953.78 = 9 x 102 + 5 x 101 + 3 x 100 + 7 x 10-1 + 8 x 10-2
  = 900 + 50 + 3 + .7 + .08 = 953.78
  base2
  1011.11 = 1x23 + 0x22 + 1x21 + 1x20 + 1x2-1 + 1x2-2
  = 8 + 0 + 2 + 1 + 0.5 + 0.25
  = 11.75
  base16
  A2F = 10x162 + 2x161 + 15x160
  = 10 x 256 + 2 x 16 + 15 x 1
  = 2560 + 32 + 15 = 2607                                               54
Number Systems – Decimal
• Base 10
• Ten digits, 0-9
• Columns represent (from right to left) units, tens, hundreds
  etc.
                           123
                                                                     56
Binary
• Base 2
  • Two digits, 0 & 1
  • Columns represent (from right to left) units, twos, fours, eights
    etc.
1111011
(123)10 = (01111011)2
      You can’t unless you know whether you’re using signed or unsigned
       arithmetic:
          Unsigned  0  x  255
             Signed  128  x  127
Hexadecimal
• Base 16
  • Sixteen digits, 0-9 and A-F (ten to fifteen)
  • Columns represent (from right to left) units, 16s, 256s,
    4096s etc.
7B
0111 1011
                            7B
  • Even very long numbers can be converted easily, treating
    each hex digit independently.
                            B96FA
Binary Numbers Again
• Recall than N binary digits (N bits) can represent unsigned
  integers from 0 to 2N-1.
• 4 bits = 0 to 15
• 8 bits = 0 to 255
• 16 bits = 0 to 65535
• Besides simply representation, we would like to also do
  arithmetic operations on numbers in binary form.
• Principle operations are addition and subtraction
                                                                65
Binary Arithmetic
The rules for binary arithmetic are:
• 0 + 0 = 0, carry = 0
• 1 + 0 = 1, carry = 0
• 0 + 1 = 1, carry = 0
• 1 + 1 = 0, carry = 1
The rules for binary subtraction are:
• 0 - 0 = 0, borrow = 0
• 1 - 0 = 1, borrow = 0
• 0 - 1 = 1, borrow = 1
• 1 - 1 = 0, borrow = 0
• Borrows, Carries from digits to left of current of digit.
• Binary subtraction, addition works just the same as decimal   66
  addition, subtraction.
Binary, Decimal addition
                           67
Binary Arithmetic - Addition
                       1   0   0   1   1   1
                 +     0   0   1   1   1   0
                       0   1   1   1   0   0   Carried digits
                       1   1   0   1   0   1   Result
Subtraction
              69
Hex Addition
               70
Hex addition
• Why is Ah + 8h = 2 with a carry out of 1?
• The carry out has a weight equal to the BASE (in this case 16).
  The digit that gets left is the excess (BASE - sum).
       Ah + 8h = 10 + 8 = 18.
       18 is GREATER than 16 (BASE), so need a carry out!
       Excess is 18 - BASE = 18 - 16 = 2, so ‘2’ is digit.
• Exactly the same thing happens in Decimal.
       5 + 7 = 2, carry of 1.
       5 + 7 = 12, this is greater than 10!.
       So excess is 12 - 10 = 2, carry of 1.
                                                                    71
Hex Subtraction
                  72
Hex Subtraction
•   Why is 4h – 7h = D with a borrow of 1?
•   The borrow has a weight equal to the BASE (in this case 16).
•   BORROW+4h – 7h = 16 + 4 -7 = 20 -7 = 13 = Dh.
•   Dh is the result of the subtraction with the borrow.
•   Exactly the same thing happens in decimal.
         3 - 8 = 5 with borrow of 1
         borrow + 3 - 8 = 10 + 3 - 8 = 13 - 8 = 5.
                                                                   73
Subtracting Using Complements
• Computers don’t subtract this way
• They subtract by adding complements because it’s more
  efficient
        1101011001                         1101011001
      - 0010111010                       +1101000101
                                        (1)1010011110
Now you notice that there is an embarrassing (1) at the left of
the row. The rule now is to take this 1 across to the first column
on the right and add it there, as shown below:
         1010011110
                   1
                                                                     74
         1010011111
Computer Data Formats
• Coding Schemes are used to represent numeric or non-
  numeric data and instructions in binary for computers to
  understand.
• BCD
• ASCII
• EBCDIC
• Unicode
                                                             75
Binary-Coded Decimal (BCD)
• Four bits per digit
                        Digit   Bit pattern
                         0        0000
 Note: the following
 bit patterns are not    1        0001
 used:                   2        0010
                         3        0011
         1010
                         4        0100
         1011
                         5        0101
         1100
         1101            6        0110
         1110            7        0111
         1111            8        1000
                                              76
                         9        1001
Example
• 709310 = ? (in BCD)
7 0 9 3
                                             77
ASCII (American National Standard Code)
•   Each character is coded as a byte
•   Most common coding system is ASCII
•   Defined in ANSI document X3.4-1977
•   7-bit code
•   8th bit is unused (or used for a parity bit)
•   27 = 128 codes
•   Two general types of codes:
•   95 are “Graphic” codes (displayable on a console)
•   33 are “Control” codes (control features of the console or
    communications channel)
                                                                 78
ASCII Chart
        000   001   010   011   100   101   110   111
0000   NULL   DLE          0     @     P     `     p
0001   SOH    DC1   !      1     A     Q     a     q
0010   STX    DC2   "      2     B     R     b     r
0011   ETX    DC3   #      3     C     S     c     s
0100   EDT    DC4   $      4     D     T     d     t
0101   ENQ    NAK   %      5     E     U     e     u
0110   ACK    SYN   &      6     F     V     f     v
0111    BEL   ETB   '      7     G     W     g     w
1000    BS    CAN   (      8     H     X     h     x
1001    HT    EM    )      9     I     Y     i     y
1010     LF   SUB   *      :     J     Z     j     z
1011    VT    ESC   +      ;     K     [     k     {
1100     FF    FS   ,      <     L     \     l     |
1101    CR     GS   -      =     M     ]     m     }
1110    SO     RS   .      >     N     ^     n     ~
1111     SI    US   /      ?     O     _     o    DEL
                                                        79
“Hello, world” Example
80