Presentation on theme: "EEE237 Introduction to Microprocessors"— Presentation transcript:
1 EEE237 Introduction to Microprocessors Week 1Course overviewİntroduction to Microprocessor, microcontroller and programming basics
2 Course objectives to develop an in-depth understanding of the operation of microprocessors and microcontrollersAssembly language programming and using C language.microprocessor interfacing techniquesto be able to use PIC16F877 microcontroller
3 Course objectivesto be able to design and implement microprocessor-based systems in both hardware and softwareUltimate goal: to be able to apply this knowledge to more advanced structures
4 Outline Microcontroller Basics and Programming Concepts PIC microcontroller ArchitectureProgramming Model, Addressing Modes and Instruction SetProgramming examplesThe Stack, Subroutines and Interrupts
5 Outline Timer Operations Analog to Digital Conversion Data acquisition and control examplesInterfacing ConceptsParallel Input/OutputSerial Communications
6 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.
7 Common computer organization (simplified view) MemoryInput/Output(I/O)ALUControlCPU
10 Computer BusesAddress bus: carries the address of a unique memory or input/output (I/O) deviceData 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
12 CPU Structure The main functions are data transferarithmetic and logic operationsdecision making (instructional flow control)The register array consists of at least one accumulator, program counter and stack pointerThe control unit controls all the operations in a CPU and basically it puts the CPU in one of the fetch and execution phases
13 Memory (1/2)The memory in a computer system stores the data and instructions of the programs.Adress decoderStorageAreaData busAdress busOther signals (Vcc,Gnd, CS, etc.)
15 Main memory types ROM (read-only memory) RAM (random-access memory) programmed permanently at the factory, cannot be alteredRAM (random-access memory)read and write memoryEPROM (erasable programmable ROM)nonvolatile, written electrically but erased opticallyEEPROM (electrically ROM)nonvolatile, both written and erased electrically
16 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.
17 Operation of the CPU (2/2) Execute cycle (phase):Instruction in the IR is decodedThe required data transfer and the required logical and arithmetic operation are performedThe result is written back either to one of the registers or memory or I/O deviceCommon operations performed in ALU are:addition, subtraction,logical AND, OR, XOR, NOTincrement, decrement, shift, clear, etc.
20 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.
21 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 inword 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.
22 MicrocontrollerA 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. PIC16F877e.g. Intel 8051
23 Microprocessor vs microcontroller (1/3) Microprocessors: high performance, generalpurpose “brains” for PCs and workstationsInstruction decode and control, arithmetic/logic operations, registers, timing, external controlTypical cost: $75 -- $500Annual demand: 10s of millionsMicrocontrollers: devices with high levels of integration for embedded controlMicroprocessor functions plus on-chip memory and peripheral functions (e.g. ports, timers)"Swiss army knife" of microprocessor technologyTypical cost: $1-- $25Annual demand: billions!
24 Microprocessor vs microcontroller (2/3) ALUMemoryI/OPeripheralfunctionsControlAddressDataControlMicrocontroller
25 Microprocessor vs microcontroller (3/3) Not always a clear distinction: today’s mP may be tomorrow’s mCMicroprocessorIncludes memory management unit, lots of cachePerformance is the most important feature (cost is important, but secondary)Used mainly in desktop machinesMicrocontrollerIntegrated RAM and ROM, no cacheIncludes lots of peripheralsUsed mainly in “embedded” applicationsOften involves real-time controlImportant features include: low cost, low power consumption, number of integrated peripherals, interrupt response time, amount of RAM and ROM
26 Bottom-up view of microcontroller systems (1/3)
27 Bottom-up view of microcontroller systems (2/3)
28 Bottom-up view of microcontroller systems (3/3)
30 What will you study in EEE237? PIC16F877 is the MCU choice in EEE237Why?Much easier to use, have attractive features and suitable for wide range applicationsHarward architecture makes PICs fasterYou will be studyinghow it is programmed to perform various operations
31 Embedded SystemMicrocontrollers 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.
32 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.
33 Microchip PICPIC 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.
35 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.
36 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.
37 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.
38 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.
39 Features of PIC16F877 Key Features PIC16F877 8 MAX Operating Frequency 20MHzFLASH Program Memory (14-bit words)8KData Memory (bytes)368EEPROM Data Memory (bytes)256I/O PortsRA0-5 (6) RB0-7 (8) RC0-7 (8) RD0-7 (8) RE0-2 (3)Timers3CCP2Serial CommunicationsMSSP, USARTParallel CommunicationsPSP10-bit Analog-to-Digital Module8 ChannelsInstruction Set35 InstructionsPins (DIP)40 Pins8
40 Bubble diagram of PIC16F877As you can see the PIC16F877A is rich in peripherals so you can use it for many different projects.
41 Pin Diagram of PIC16F877Plastic dual in-line package (DIP)
43 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
44 Memory of the PIC16F877 divided into 3 types of memories: 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 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.Data EEPROM (Electrically Erasable Programmable Read-Only Memory) – A memory that allows storing the variables as a result of burning the written program.
45 Each one of them has a different role 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.
46 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 wordPC can address up to 8K addressesAddresses H’000’ and H’004’ are treated in a special way
47 PIC16F877A Data Memory (RAM) Memory storage for variablesData 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.