EE3248 Microprocessor & Microcontroller 1 Chapter 1 - Microprocessor Basics Basic microprocessor system: – – the CPU, memory, I/O, and buses subsystems Basic operation of microprocessor system: fetch & execute cycle, – – – the architecture of microprocessors & microcontrollers, some typical 8-bit microcontrollers and their features, memory read and write operations. 2 EE3248 Microcontroller and Microprocessor Systems Revision Bit: Basic unit of information in computer that stands for “binary digit,” with the values 0 or 1 (low or high) only. Byte: A group of 8 bits. Nibble: A group of 4 bits (half a byte). Processor word length: The size of the group of bits a processor is designed to use as a single unit or word. E.g. 8-bit, 16-bit, or 32-bit computer. Most Significant Bit (MSB) & Least Significant Bit (LSB): E.g. For an 8-bit binary number: 1 MSB 0 0 1 0 1 1 0 3LSB Review of Number Systems: Decimal to Binary & vice versa Hexadecimal to Binary & vice versa Octal to Binary & vice versa E.g. Convert 8210 to binary 8210 = 10100102 Convert 111001112 to decimal 111001112 = 23110 Convert F116 to binary F116 = 100100012 Alphanumeric Codes: Alphabets (A, B, C, …), Numbers (1,2,3,…), and characters ( $, *,%,@…) are represented by a unique binary code. 4 ASCII code: (American Standard Code for Information Interchange) A character is represented by a 7 bit binary number (X6…X0) A 100 00012 = 41H a 110 00012 = 61H E.g. BCD code: Binary-Coded Decimal Each decimal digit is represented by its' 4-bit binary equivalent. E.g. 9810 = 0110 00102 = 1001 1000BCD 5 1’s and 2’s Complement number: For a negative number, -A: 1's complement = A' 2’s complement = A' + 1 Eg. Find the 2’s complement number for a 4-bit system X = 710 = 01112 X’= -710 = 10002 2’s complement X’+ 1 = 10012 Range of an N-bit 2’s complement number, X: -2N-1 X 2N-1 - 1 What is the range of an 8-bit 2’s complement number? -128 X +127 6 . Combinational Logic Circuit Output is decided by current input only Basic logic gates: Inverter, AND, OR, NAND, NOR, XOR E.g. Adder, decoder, multiplexer and etc. OR A 0 0 1 1 B 0 1 0 1 AND Y A 0 0 1 1 B 0 1 0 1 NOR Y A 0 0 1 1 B 0 1 0 1 NAND Y A 0 0 1 1 B 0 1 0 1 XOR Y A 0 0 1 1 7 B 0 1 0 1 Y Arithmetic Operation Addition: • The sum of a binary number and its 2’s complement is zero E.g. Consider 4510 is added to its 2’s complement counterpart in an 8-bit system: auxiliary carry 1 0 carry out + 1 1 0 1 0 1 0 1 1 0 0 1 0 1 0 1 1 0 0 1 1 0 0 1 0 1 [45] 1 1 [-45] 0 0 8-bit results 8 Subtraction: Borrow 1 1 0 1 0 0 - 0 1 1 0 1 1 1 0 1 1 0 1 [77] 0 1 0 0 [100] 1 0 0 1 [-23] Results in 8-bit 2's complement Multiplication: x 0 1 1 0 0 0 0 1 0 0 1 0 1 0 0 0 0 1 1 1 0 1 0 1 0 1 0 1 0 0 0 1 Multiplicand Multiplier [13] [5] Partial product [65] Product 9 Division: [4] Divisor 0 1 0 0 0 0 1 0 0 1 0 0 Partial 0 remainder 1 1 0 1 1 0 0 0 1 1 1 0 1 1 0 1 1 0 0 0 1 0 0 1 Quotient Dividend [11] [45] Remainder Overflow: - Consider the addition of two 8-bit 2’s complement numbers 0 1 0 0 + 0 1 1 0 1 0 1 1 1 1 0 1 [77] 0 1 0 0 [100] 0 0 0 1 [-79!?] An error has occurred as the results is outside the range -128 X 127 10 Parity: number of ‘1’ Even parity: Set the parity bit to 1 or 0 to make the total number of ‘ones’ even Odd parity: Set the parity bit to 1 or 0 to make the total number of ‘ones’ odd Even parity 0 0 1 0 0 1 1 0 1 Odd parity 0 1 0 0 1 1 0 1 1 11 Example: 12 What is a system? Interconnection of components to perform specified functions is referred to as a system. If all the components are digital in nature, it is called a digital system. What is a computer system? A set of software and interconnected hardware which processes data in a meaningful way. 13 What is Computer ? Computer Automatic data processing Data Storage & retrieval Hardware - equipment Software - programs 14 Major Components of a Computer Mass storage, HID(human interface device:keyboard, mouse, VDU RAM, ROM MEMORY I/O SYSTEM BUS Computer Address, data and control buses CPU CU, ALU, registers 15 von Neumann Architecture Main Memory (Code & Data) ALU I/O CU CPU *Named after the mathematician, John von Neumann Von Neumann began the design of IAS (Institute for Advanced Studies) computer in 1946 and completed it in 1952. 16 Stored Program Computer Input CPU / P Output Memory 17 What is Microprocessor ? CPU Control unit, instruction decoder, ALU, registers Single-chip CPU 18 Past Microprocessors ... 1971 - Intel 4004, 1st single chip CPU, 4-bit processor 1972 - Intel 4040, enhanced 4004, 60 instructions 1972 - Intel 8008, 8-bit P 1972 - Texas Instrument TMS 1000, 1st single C, 4-bit 1974 - Intel 8080, successor to the 8008, used in Altair 8800 1975 - Motorola 6800, used MOS technology 1976 - Intel 8085, updated 8080, +5V power supply 1976 - Zilog Z80, improved 8080 1976 - TI TMS 9900, 1st 16-bit P 1978 - Zilog Z8000, Motorola 68000, 16-bit P 1978 - Intel 8086, 16-bit, IBM’s choice... 19 What is Microcontroller ? MEMORY I/O SYSTEM BUS CPU Single-chip microcomputer system 20 Past Microcontrollers ... 1972 - Texas Instrument TMS 1000, 1st single C, 4-bit 1976 - Intel 8048, 8-bit C, 1k ROM, 64b RAM, 27 I/O 1980 - Intel 8051, 4k ROM, 128b RAM, 32 I/O, 2 16-bits timers 1980s - MCS-51 family - Other Cs Intel 8031, 8052, 8751, … Atmel AT89C51, AT 89C1052/2051,… Dallas Semiconductor DS5000 series… Philips, National Semiconductor, ... Microchip PIC16 series Motorola 68HC11 Zilog’s Z86 21 General Structure of a C I/O Interrupt Control CPU Serial Interface Parallel Interface Internal address, data, & control buses Timers/ Counters RAM ROM Memory 22 Microprocessor System vs Microcontroller System Data Bus CPU RAM ROM I/O Port Timer Serial COM Port CPU RAM I/O Port Timer ROM Serial COM Port Address Bus General-Purpose Microprocessor System Microcontroller 23 Example of a Microprocessor system CPU Motorola 6802 EPROM 2732 I/O chip 6821 http://www.sbprojects.com/projects/nano6802/nano6802.htm 24 Example of a Microprocessor system CPU I/O EPROM http://www.sbprojects.com/projects/nano6802/nano6802.htm 25 Example of a Microcontroller system http://www.ozitronics.com/robotics.html 26 Microprocessor System Vs Microcontroller System P Hardware Architecture Application Instruction set Cost Single-chip CPU RAM-ROM ratio high Interrupt, I/O, Timer – external. Higher performance (+2GHz) Not much on Real-time Microcomputer system Processing information C Process intensive to handle large volume of data Operates on byte, words, pointers, and arrays. Longer development time ANDing, ORing, XORing in bit level is less easy Expensive (Celeron 2000MHz ~RM250) Single-chip computer ROM-RAM ration high Interrupt, I/O, timer-Internal Less performance (<80MHz) Need to respond to Real time Control– oriented activities Control of I/O devices Control intensive to handle I/O using single Bit Operates mostly on Bit & byte Shorter development time ANDing, ORing, XORing in bit level is easy Cheap(AT89S51 ~RM10 ) 27 Applications of uC / uP systems • • • • • • • • • • • • Automobiles Home security systems Televisions, DVD players Modems, Handphones Smartcards Digital clock Washing machines Microwaves ovens, Air Conditioners, etc 28 Major 8-bit Microcontrollers • Intel 8051 • Motorola 68HC11 • Microchip PIC16XX 29 Intel 8051 Power Control Modes 4KBytes On-Chip ROM / EPROM 128 x 8-bit RAM 32 Programmable I / O Lines Two 16- Bit Timers / Counters 5 Interrupt Sources Boolean Processor TTL & CMOS Compatible Logic 64KBytes External Program Memory Space 64KBytes External Data Memory Space Full Duplex UART Available in 12MHz & 16MHz Versions 30 INT1 INT0 Timer 1 Timer 0 Serial Port Interrupt control Intel 8051 T1 T0 Other registers Timer 1 RAM 128 bytes Timer 0 CPU Oscillator Bus control EA RST I/O Ports Serial port ALE PSE TxD* P0 A/D P1 P2 P3 A/D RxD* * Alternate pin assignment for P3 31 Motorola MC68HC11 256 bytes of on-chip RAM 512 bytes of on-chip EEPROM 4-channel 8-bit analogue-to- 16-bit timer system digital converter Asynchronous serial communication interface Real-time interrupt circuit Synchronous serial peripheral interface Power saving STOP and WAIT modes 32 Motorola MC68HC11 33 Microchip PIC16C64 RISC architecture (35 single In-circuit serial programming word instruction) 128 bytes RAM, 2Kbytes EPROM 3 Timer/Counters, 1 watchdog timer, 8 interrupt sources, 33 I/O pins 1 Capture/Compare/PWM module Synchronous serial port (SSP) with SPI, I2C Power saving SLEEP mode Universal synchronousasynchronous receiver transmitter (USART/SCI) Programmable code protection 8-bit Parallel slave port (PSP) 34 Microchip PIC16C64 35 General features of a microcontroller • On-chip RAM (data) and ROM (program) • Support external program and data memory • I/O ports for direct interfacing with other digital devices • On-chip timer/counter • Parallel and serial communication capabilities • Interrupt from external stimuli 36 Choosing the right microcontroller Critical decisions in a project: I/O requirement: Number of general purpose I/O ports/pins Special interfaces (UART, A/D, D/A) Size of RAM and ROM (type of ROM) On-chip peripherals (timers, counters) Speed requirement Cost Availability (now and future) Development support: Assembler, compiler, linker Debugging tools Support from manufacturer and users (forums) 37