SEE 3223: Microprocessors Kamal Khalil ROOM : P04 - 125 Ext.: 35277, HP: 0197563004 Email: kamal@fke.utm.my Consultation: Tuesday 11:00 – 12:55 a.m. Thursday 11:00 – 12:55 a.m. Department of Microelectronics and Computer Engineering (MiCE) Faculty of Electrical Engineering Universiti Teknologi Malaysia Chip Plastic case Pins Introduction Microprocessor SEE3223 Aim This subject introduces the principle and the usage of microprocessor. Few topics that are emphasized are processor architecture, assembly language and basic interfacing in a microprocessor-based systems. Learning Outcomes At the end of this course, students will be able to : Describe and differentiate all the component of microprocessorbased systems. Analyze and design AVR Atmega32 assembly language programs. Analyze and design AVR Atmega32 microprocessor systems. Work with AVR Studio and communicate effectively in a team to solve complex AVR Atmega32 design problems. SEE3223 Microprocessor Systems What’s in this course: – Assembly language programming – Microprocessor concepts and architecture – Hardware interfacing Pre-Requisites – – – – – – – Number representation, coding, registers, state machines Realization of simple logic circuits Integrated circuit technologies Designing with MSI components Flip-Flops Counters and sequential MSI components Register transfer logic Course Policy Attendance is compulsory. You are responsible for whatever is taught in the lecture. If you miss a class, it is your responsibility to find out about assignment, quizzes and exam from elearning. Punctuality is expected. Makeup tests will not be given except in the case of actual emergencies with written evidence. You are encouraged to collaborate (not copy) on assignment problems with your "study buddies.” Grading Policy Assessment Breakdown: – 4 Quizzes (Best 3 out of 4) = 30% – 1 Group Assignment = 20% – Final = 50% Material Lecture notes Will be posted Textbooks Muhammad Ali Mazidi and, Sarmad Naimi and Sepehr Naimi (2010), The AVR Microcontroller and Embedded Systems: Using Assembly and C, 1st Ed., Prentice Hall. Chip Plastic case Pins Microprocessor-Based Systems Microprocessor-Based Systems Aims – To review the main elements of a microprocessor system. Intended Learning Outcomes – At the end of this module, students should be able to: • Define and explain important terms associated with both hardware and software elements of a microprocessor system • Tell the difference between general purpose computing and embedded computing • List down the major components inside a computer & processor • Tell the difference between computer, processor, microprocessor and microcontroller • Explain instruction execution cycles of a generic microprocessor What is Computer ? Computer Data Processing Data Storage Basic Functions of Computer • • • • Data Processing Data Storage Data Movement Control Microprocessor-Based Systems Whenever the word microprocessor is mentioned, it conjures up a picture of a desktop or laptop PC running an application such as a word processor or a spreadsheet. While this is a popular application for microprocessors, it is not the only one and the fact is most people use them indirectly in common objects and appliances without realizing it. Without the microprocessor, these products would not be as sophisticated or cheap as they are today. 20102011-I 12 Microprocessor-Based Systems Computing systems are everywhere. Its probably no surprise that millions of computing systems are built every year destined for desktop computers (Personal Computers, or PCs), workstations, mainframes and servers. What may be surprising is that billions of computing systems are built every year for a very different purpose: they are embedded within larger electronic devices, repeatedly carrying out a particular function, often going completely unrecognized by the devices user. Creating a precise definition of such embedded computing systems, or simply embedded systems, is not an easy task. 20102011-I 13 Computer Classifications • Classification of computers: – Servers: • Big, expensive, available 24x7 (read “24 by 7” or 24 hours a day, 7 days a week. Mainframes are old servers made by IBM. – Desktops: • computers on your desk – Laptops: • computers you carry in your bag – PDA (personal digital assistants): • Miniaturized computers you carry in your pocket – Embedded systems: • computers that have a specific application! What is an Embedded System? • a microprocessor-based system • built to control a function or range of functions • not designed to be programmed by the end user in the same way that a PC is • Usually embedded as part of a complete device including hardware and mechanical parts System SOFTWARE PROGRAM #include <16f876a.h> #use delay (clock=20000000) #byte PORTB=6 main() { set_tris_b(0); portb=255; //decimal delay_ms(1000); portb=0x55; //hexadecimal delay_ms(1000); portb=0b10101010; //binary delay_ms(500); } 20102011-I 15 Embedded System: Example 20102011-I 16 Specific Purpose Processors in Embedded Systems • Embedded Controllers: – General purpose for any embedded system – Small size, low power, integrated functions – Traffic light system, SCADA system etc. • Digital Signal Processors: – optimized for MAC operations especially for digital signal processing applications – Commonly found in hand-phones, modems, communications systems, motor driver, CNC machines etc. • Graphics Processors: – To speed up graphic processing such as physic calculations, image manipulation etc. – found in graphics cards of workstations and als o integrated with a CPU • Programmable Logic Controllers: – Optimized for control applications – Usually found in industrial and automation applications General Purpose Computing vs Embedded Systems General Purpose Embedded Intended to run a fully general set of applications Runs a single or limited applications often known at design time End-user programmable Not end-user programmable Resources are plenty, Faster is always better Resources are scarce, operates in fixed run-time constraints, additional performance may not be useful/valuable Differentiating features: • Speed (need not be fully predictable) • Cost (eg RM3k vs RM5k per laptop) • Software compatibility Differentiating features: • Speed (must be predictable) • Power • Cost (eg RM2 vs RM2.50) • Size • Software compatibility problems A Computer System – Simplified View 20112012-I 19/Module 1 A Computer System – Simplified View Stores and retrieves data Moves data between the computer and its external environment CPU Memory Input/Output Controls the operation of the computer Performs its data processing functions Address bus Provides internal communication among CPU, main memory and I/O Data bus Control bus An embedded system also has the same structure but at a smaller size What is Microprocessor ? Central Processing Unit (CPU): Control the operation of the computer and performs its data processing functions; often simply referred to as PROCESSPR CPU Processor or Central Processing Unit (CPU) A set of internal storage locations within the CPU To perform the arithmetic and logical operations within the CPU Control & Instruction Registers User-Visible Registers Registers Program Counter Instruction Register ... Control ... Unit Internal Bus Address Bus General-Purpose DataReg. Bus ALU Address Register Data Register Control Bus Flag Register To synchronize and control the overall operation of the P system To decode instruction and pass the necessary control signals to CU 20112012-I 22/Module 1 Microprocessor – Basic concept Address bus CPU Data bus Control bus 16-bit / 32-bit / 64-bit wide bidirectional 8-bit / 16-bit / 32-bit / 128-bit Timing signals, ready signals, interrupts etc Microprocessor, by-itself, completely useless – must have external peripherals to Interact with outside world Microprocessor – Basic concept Address Control Boot ROM CPU Used at startup Instruction (program) ROM Data RAM Input/ Output External Comm. Data Microprocessor, by-itself, completely useless – must have external peripherals to Interact with outside world Memory Memory Address-1 Memory Location-1 Memory Address-2 Memory Location-2 1 2 3 4 5 6 7 1 byte = 8-bit data 1 word= 2 bytes 1 double = 2 words Memory Address-n Memory Location-n Number of addresses 2N (where N is an integer) 8 Memory Devices • Read-Only Memory – Non-volatile memory: contents is retained even without power – In embedded systems, used to store application programs and test routines – Contents can be set by fixing it during manufacturing or “burning” it using a programming device – Common types include MROM, PROM, EPROM and flash memory – Erasable types can only be rewritten a fixed number of times • Random Access Memory – Contents lost without power (volatile memory) – Used to store temporary data. In embedded system, very little RAM is required. Some systems don’t even have RAM at all! – No limit to number of writes the device can handle – Fast writes (unlike EPROM/EEPROM) – Two major types are SRAM and DRAM Data & Address Buses 1. Smallest transferable amount of data from memory to CPU (and vice versa) is one byte. 2. Each byte has a unique location or address. 3. The address of each byte is written in hexadecimal (hex). For AVR, the prefix ‘0x’ means a hex value. 4. The range of addresses accessible by the processor is the memory space. (Limited by the size of the address bus). 5. The Atmega32 (and many other AVR models) does not have direct support for an external memory interface. 24-bit address bus CPU Memory 16-bit data bus Data bus 16 bits 15 0x000000 Address bus 24 bits 224-1= 8M locations 0xFFFFFF 0 Microcontroller – Basic concept 20112012-I 28/Module 1 Microcontroller – Basic concept Address Control Boot ROM CPU Program ROM Data RAM Input/ Output External Comm. Data Microcontroller - put a limited amount of most commonly used resources inside one chip Microprocessor vs Microcontroller • Microprocessor: – A chip that contains only the processor – Need other chips to make a working system – More flexible – Can have very few I/O or many I/O devices using the same processor chip • Microcontroller: – A chip that contains all the components of a computer – processor, memory, input/output, and essential peripherals. – Less flexibility – Less component count in system – Processing power is the same as long as using same processor Software • Why we need a program – When CPU was invented designer use machine code – To simplify work, assembly language was invented. • Program: – Sequence of instructions that perform tasks • Computer software – When hardware system was invented their functions are fixed, to make the system flexible the codes must be changeable (soft). Machine & Assembly Language • Machine instruction – A sequence of binary digits which can be executed by the processor, e.g. 0001 1011. – Can only be understood for specific CPU – Hard to understand and easy to forget for human being • Assembly language – An assembly program consists of assembly instructions – An assembly instruction is a mnemonic representation of a machine instruction e.g. ADD equivalent to “04H” – Assembly programs must be translated into object code (machine code) before it can be executed . Known as assembler. – Assemblers can be of two types: cross assembler and native assembler. – Cross assembler runs on one microprocessor and generates machine instructions that will be executed by another microprocessor that has different instruction set, e.g. freeware ASM68K. – Native assembler runs and generates instructions for the same microporcessor. – Drawbacks of assembly programs are: • dependent on hardware organization, difficult to understand long programs, low programmer productivity High-level language (HLL) • High-Level Language – Syntax of a high-level language instructions are closer to human language. – A translator is required to translate the program written in a high-level language into object code – known as a compiler. – There are cross compilers that run on one computer but translate programs into machine instructions to be executed on a computer with a different instruction set. – Main drawback is the generated machine code is longer compared to writing using assembly language. – System speed requirements may be hard to be fulfilled. – Shorter development time compared to assembly – So, C language has been extensively used in microcontroller programming in industry. Instruction Cycle (Fetch-Execute) • The processor executes instructions one-by-one according to the sequence found in memory • Everything is controlled by, what else, the control unit in the CPU. • To execute an instruction, the processor must fetch it from memory. • Each instruction is processed in instruction cycle or the fetchexecute cycle Fetch Execute Instruction Cycle Details • Fetch phase: 1. Read the instruction and put it into the instruction register (IR) 2. Control unit decodes the instruction; updates the PC for the next instruction • Execute phase: 3. Find the data required by the instruction. 4. Perform the required operation. 5. Store the results. 6. Repeat from Step 1. 0 31h 1 C4h 2 26h 3 81h 4 EAh 5 0h 6 5h A [17] BA A [6] AA+B [7]A 7 CS OE WE D0-D7 A0-An-1 GND VCC How computers work Logic circuit Address bus Data bus Write Control bus Read ALU CPU PC: 10 A B C D Inst. Dec. registers I/O 16 I/O 17 I/O 18 I/O n How computers work 0 31h 1 C4h VCC 2 26h 3 81h 4 EAh Address bus CS OE 6 5h WE D0-D7 A0-An-1 GND 5 0h A [17] BA A [6] AA+B [7]A 7 Logic circuit 17 Data bus Write Control bus Read ALU CPU PC: 1 A B C D Inst. Dec. 31 registers 9 I/O 16 I/O 17 I/O 18 I/O n How computers work 0 31h C4 1 C4h VCC 26 2 26h 3 81h 4 EAh Address bus CS OE 655h WE D0-D7 A0-An-1 GND 5 0h A [17] BA A [6] AA+B [7]A 7 Logic circuit 17 6 Data bus Write Control bus Read ALU CPU PC: 1 2 3 9 A B C D Inst. Dec. registers I/O 16 I/O 17 I/O 18 I/O n How computers work 0 31h 1 C4h VCC 2 26h 81 3 81h EAh 4 EA Address bus Data bus 7 CS OE 6 5h WE D0-D7 A0-An-1 GND 5 0h A [17] BA A [6] AA+B [7]A 7 Logic circuit Eh Write Control bus Read + E ALU CPU PC: 454 3 55E A 99 B C D Inst. Dec. registers I/O 16 I/O 17 I/O 18 I/O n Review Questions 1 Review Questions 2 Review Questions 2 (Cont’d) Selecting a Microprocessor • Choose the right one for your application – Primary criteria: Cost, Power, Size, Speed – Others: package options, integrated peripherals, potential for future growth • Choose one with good software development support – – – – development environment - good compiler and debugger availability evaluation boards in-circuit emulators for those with deep pockets Operating system availability • Other considerations – Code density: affects power consumption, performance and system cost – Hardware availability: make sure you can actually purchase the microcontroller before designing it in – Prior expertise, licensing, etc Summary • Microprocessors and embedded controllers are a ubiquitous part of life today • Concept of a microprocessor & microcontroller • Understand how a µP works • Headhunters report that EEs familiar with µC, µP design are in the highest possible demand • Web Resources: – How Microprocessors Work: • http://computer.howstuffworks.com/microprocessor.htm • http://www.intel.com/education/mpworks/ • http://www.cse.psu.edu/~cg471/03f/hw/pj5/how-micro.html – Great Microprocessors of the Past and Present: • http://www.sasktelwebsite.net/jbayko/cpu.html – Great Moments in Microprocessor History: • http://www-128.ibm.com/developerworks/library/pa-microhist.html