eee237 introduction to microprocessors
DESCRIPTION
EEE237 Introduction to Microprocessors. Week 1 Course overview İntroduction to Microprocessor, microcontroller and programming basics . Course objectives. to develop an in- depth understanding of the operation of microprocessors and microcontrollers - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/1.jpg)
EEE237 Introduction to Microprocessors
Week 1Course overviewİntroduction to Microprocessor,
microcontroller and programming basics
![Page 2: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/2.jpg)
Course objectives• to develop an in-depth understanding of
– the operation of microprocessors and microcontrollers
– Assembly language programming and using C language.
– microprocessor interfacing techniques
• to be able to use PIC16F877 microcontroller
![Page 3: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/3.jpg)
Course objectives• to be able to design and implement
microprocessor-based systems in both hardware and software
• Ultimate goal: to be able to apply this knowledge to more advanced structures
![Page 4: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/4.jpg)
Outline• Microcontroller Basics and Programming
Concepts
• PIC microcontroller Architecture
• Programming Model, Addressing Modes and Instruction Set
• Programming examples
• The Stack, Subroutines and Interrupts
![Page 5: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/5.jpg)
Outline• Timer Operations
• Analog to Digital Conversion
• Data acquisition and control examples
• Interfacing Concepts
• Parallel Input/Output
• Serial Communications
![Page 6: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/6.jpg)
Common computer organization (simplified view)
• ALU (Arithmetic Logic Unit) is a circuitry, which is capable of doing various operations (for example ADD, SHIFT, AND, OR, etc) on certain on-chip registers.
• CPU (Central Processing Unit) is the combination of the control logic, associated registers and the arithmetic logic unit.
![Page 7: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/7.jpg)
Common computer organization (simplified view)
MemoryInput/Output
(I/O)
ALU
Control
CPU
![Page 8: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/8.jpg)
Common computer organization (1/2)
![Page 9: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/9.jpg)
Common computer organization (2/2)
![Page 10: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/10.jpg)
Computer Buses• Address bus: carries the address of a unique
memory or input/output (I/O) device
• Data bus: carries data stored in memory (or an I/O device) to the CPU or from the CPU to the memory (or I/O device)
• Control bus: is a collection of control signals that coordinate and synchronize the whole system
![Page 11: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/11.jpg)
Block diagram of a typical CPU
![Page 12: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/12.jpg)
CPU Structure• The main functions are
– data transfer– arithmetic and logic operations– decision making (instructional flow control)
• The register array consists of at least one accumulator, program counter and stack pointer
• The control unit controls all the operations in a CPU and basically it puts the CPU in one of the fetch and execution phases
![Page 13: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/13.jpg)
Memory (1/2)• The memory in a computer system stores
the data and instructions of the programs.
Adress decoder Storage
Area
Adress bus
Data bus
Other signals (Vcc,Gnd, CS, etc.)
![Page 14: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/14.jpg)
Memory (2/2)
![Page 15: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/15.jpg)
Main memory types• ROM (read-only memory)
– programmed permanently at the factory, cannot be altered
• RAM (random-access memory) – read and write memory
• EPROM (erasable programmable ROM) – nonvolatile, written electrically but erased
optically• EEPROM (electrically ROM)
– nonvolatile, both written and erased electrically
![Page 16: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/16.jpg)
Operation of the CPU (1/2)• Fetch cycle (phase):
– The CPU puts the address of the instruction to be executed on the address bus. The address info comes from the program counter (PC) maintained by the control unit.
– The control bus holds the info. for reading the memory location and the data bus holds the instruction from the memory which is stored into the instruction register (IR)
– PC is updated to point to the next instruction.
![Page 17: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/17.jpg)
Operation of the CPU (2/2)• Execute cycle (phase):
– Instruction in the IR is decoded – The required data transfer and the required
logical and arithmetic operation are performed– The result is written back either to one of the
registers or memory or I/O device• Common operations performed in ALU are:
– addition, subtraction, – logical AND, OR, XOR, NOT– increment, decrement, shift, clear, etc.
![Page 18: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/18.jpg)
Operation of the CPU (2/2)
![Page 19: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/19.jpg)
Detailed Block Diagram
![Page 20: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/20.jpg)
Microcomputer (1/2)• CPU on a single IC microprocessor (µP).
• the terms CPU, µP and MPU (microprocessor unit) are synonymous.
• CPU is the combination of the ALU and control unit of any computer.
• When the CPU is a single IC; it is called a µP and is also referred to as the MPU.
• When the MPU ‘s connected to memory and I/O, the arrangement becomes a MICROCOMPUTER.
![Page 21: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/21.jpg)
Microcomputer (2/2)• Many different MPUs are produced by many
different IC vendors (e.g., Motorola, Intel, Texas Instruments, Zilog, National Semiconductors, etc.).
• Major differences are in
– word size,– the number and types of instructions that can be
performed,– the types of external control signals available,– the amount of memory that can be addressed.
![Page 22: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/22.jpg)
Microcontroller• A microcontroller unit (MCU) contains an MPU,
memory, and I/O circuitry on a single chip.
• Such a chip can perform control operations without the need for any external circuitry.
• e.g. PIC16F877
• e.g. Intel 8051
![Page 23: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/23.jpg)
Microprocessor vs microcontroller (1/3)• Microprocessors: high performance, general
purpose “brains” for PCs and workstations– Instruction decode and control, arithmetic/logic
operations, registers, timing, external control– Typical cost: $75 -- $500– Annual demand: 10s of millions
• Microcontrollers: devices with high levels of integration for embedded control– Microprocessor functions plus on-chip memory and
peripheral functions (e.g. ports, timers)– "Swiss army knife" of microprocessor technology– Typical cost: $1-- $25– Annual demand: billions!
![Page 24: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/24.jpg)
Microprocessor vs microcontroller (2/3)
ALU
Control
Memory I/O Peripheralfunctions
Address
Data
Control
Microprocessor
Microcontroller
![Page 25: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/25.jpg)
Microprocessor vs microcontroller (3/3)Not always a clear distinction: today’s mP may be tomorrow’s mC• Microprocessor
– Includes memory management unit, lots of cache– Performance is the most important feature (cost is
important, but secondary)– Used mainly in desktop machines
• Microcontroller– Integrated RAM and ROM, no cache– Includes lots of peripherals– Used mainly in “embedded” applications– Often involves real-time control– Important features include: low cost, low power
consumption, number of integrated peripherals, interrupt response time, amount of RAM and ROM
![Page 26: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/26.jpg)
Bottom-up view of microcontroller systems (1/3)
![Page 27: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/27.jpg)
Bottom-up view of microcontroller systems (2/3)
![Page 28: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/28.jpg)
Bottom-up view of microcontroller systems (3/3)
![Page 29: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/29.jpg)
Microcontroller Use
![Page 30: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/30.jpg)
What will you study in EEE237?
• PIC16F877 is the MCU choice in EEE237• Why?
– Much easier to use, have attractive features and suitable for wide range applications
– Harward architecture makes PICs faster
• You will be studying– how it is programmed to perform various operations
![Page 31: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/31.jpg)
Embedded System
• Microcontrollers are sometimes called embedded microcontrollers, which just means that they are part of an embedded system -- that is, one part of a larger device or system.
• The majority of microcontrollers in use today are embedded in other machinery, such as automobiles, telephones, appliances, and peripherals for computer systems. These are called embedded system.
![Page 32: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/32.jpg)
• Typical input and output devices include switches, relay, solenoids, LEDs, small or custom LCD displays, radio frequency devices, and sensors for data such as temperature, humidity, light level etc.
• Embedded systems usually have no keyboard, screen, disks, printers, or other recognizable I/O devices of a personal computer, and may lack human interaction devices of any kind.
![Page 33: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/33.jpg)
Microchip PIC• PIC is a family of Harvard architecture
microcontroller made by Microchip Technology. The name PIC initially referred to "Peripheral Interface Controller“ . PIC microcontrollers were the first RISC microcontroller.
• PICs are popular with both industrial developers and hobbyists alike due to their low cost, wide availability, large user base, extensive collection of application notes, availability of low cost or free development tools, and serial programming (and re-programming with flash memory) capability.
![Page 34: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/34.jpg)
Two Different Architectures
![Page 35: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/35.jpg)
Fetch & Execution Cycles / Pipelining• There are 35 single word instructions. A two-stage
pipeline overlaps fetch and execution of instructions. As a result, all instructions execute in a single cycle except for program branches. These take two cycles since the fetch instruction is “flushed” from the pipeline while the new instruction is being fetched and then executed.
• A typical picture of the pipeline is shown below.
![Page 36: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/36.jpg)
Clock And Instruction Cycles• Clock from the oscillator enters a
microcontroller via OSC1 pin where internal circuit of a microcontroller divides the clock into four even clocks Q1, Q2, Q3 and Q4 which do not overlap.
• These four clocks make up one instruction cycle (also called machine cycle) during which one instruction is executed.
![Page 37: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/37.jpg)
• Execution of instruction starts by calling an instruction that is next in string.
• Instruction is called from program memory on every Q1 and is written in Instruction Register (IR) on Q4.
• Decoding and execution of instruction are done between the next Q1 and Q4 cycles. The following diagram shows the relationship between instruction cycle and clock of the oscillator (OSC1) as well as that of internal clocks Q1 – Q4.
• Program Counter (PC) holds information about the address of the next instruction.
![Page 38: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/38.jpg)
Why use PIC16F877? Why PIC16F877A is very popular? This is because PIC16F877A is very cheap.
Apart from that it is also very easy to be assembled. Additional components that you need to make this IC work is just a 5V power supply adapter, a 20MHz crystal oscillator and 2 units of 22pF capacitors.
What is the advantages of PIC16F877A? This IC can be reprogrammed and erased up to
10,000 times. Therefore it is very good for new product development phase.
What is the disadvantages of PIC16F877A?
This IC has no internal oscillator so you will need an external crystal of other clock source.
![Page 39: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/39.jpg)
Features of PIC16F877
8
Key Features PIC16F877MAX Operating Frequency 20MHz
FLASH Program Memory(14-bit words) 8K
Data Memory (bytes) 368
EEPROM Data Memory (bytes) 256
I/O Ports
RA0-5 (6)RB0-7 (8)RC0-7 (8)RD0-7 (8)RE0-2 (3)
Timers 3
CCP 2
Serial Communications MSSP, USART
Parallel Communications PSP
10-bit Analog-to-Digital Module 8 Channels
Instruction Set 35 Instructions
Pins (DIP) 40 Pins
![Page 40: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/40.jpg)
Bubble diagram of PIC16F877As you can see the PIC16F877A is rich in peripherals so you can use it for many different projects.
![Page 41: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/41.jpg)
Pin Diagram of PIC16F877
• Plastic dual in-line package (DIP)
![Page 42: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/42.jpg)
Pin Diagram of PIC16F877 Quad Flat
Package (QFP) Plastic Leaded Chip
Carrier Package (PLCC)
![Page 43: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/43.jpg)
PIC16F877 Internal Block Diagram • The basic architecture of PIC16F877
consists of Program memory, file registers and RAM, ALU and CPU registers.
PIC16F877 Internal Block Diagram
![Page 44: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/44.jpg)
Memory of the PIC16F877• divided into 3 types of memories:
1.Program Memory – A memory that contains the program (which we had written), after we've burned it. As a reminder, Program Counter executes commands stored in the program memory, one after the other.
2.Data Memory – This is RAM memory type, which contains a special registers like SFR (Special Function Register) and GPR (General Purpose Register). The variables that we store in the Data Memory during the program are deleted after we turn of the micro. These two memories have separated data buses, which makes the access to each one of them very easy.
3.Data EEPROM (Electrically Erasable Programmable Read-Only Memory) – A memory that allows storing the variables as a result of burning the written program.
![Page 45: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/45.jpg)
• Each one of them has a different role. Program Memory and Data Memory two memories that are needed to build a program, and Data EEPROM is used to save data after the microcontroller is turn off.
![Page 46: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/46.jpg)
PIC16F877A Program Memory • Is Flash Memory• Used for storing
compiled code (user’s program)
• Program Memory capacity is 8K x 14 bit Each location is 14 bits long Every instruction is coded as a 14 bit word
• PC can address up to 8K addresses
• Addresses H’000’ and H’004’ are treated in a special way
![Page 47: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/47.jpg)
PIC16F877A Data Memory (RAM)Memory storage for variables Data Memory is also known as Register File and consists of two components.
General purpose register file (same as RAM). Special purpose register file (similar to SFR in 8051). Addresses range from 0 to 511 and partitioned into 4 banks each bank extends up to 7Fh (128 bytes). The user can only access a RAM byte in a set of 4 banks and only one bank at a time. The default bank is BANK0. To access a register that is located in another bank, one should access it inside the program. There are special registers which can be accessed from any bank, such as STATUS register.
![Page 48: EEE237 Introduction to Microprocessors](https://reader036.vdocuments.net/reader036/viewer/2022062501/56816939550346895de0a259/html5/thumbnails/48.jpg)