Introduction to Microcontrollers Courses 182.064 & 182.074

Total Page:16

File Type:pdf, Size:1020Kb

Introduction to Microcontrollers Courses 182.064 & 182.074 Introduction to Microcontrollers Courses 182.064 & 182.074 Vienna University of Technology Institute of Computer Engineering Embedded Computing Systems Group February 26, 2007 Version 1.4 Gunther¨ Gridling, Bettina Weiss Contents 1 Microcontroller Basics 1 1.1 Introduction ....................................... 1 1.2 Frequently Used Terms ................................. 6 1.3 Notation ......................................... 7 1.4 Exercises ........................................ 8 2 Microcontroller Components 11 2.1 Processor Core ..................................... 11 2.1.1 Architecture ................................... 11 2.1.2 Instruction Set ................................. 15 2.1.3 Exercises .................................... 21 2.2 Memory ......................................... 22 2.2.1 Volatile Memory ................................ 23 2.2.2 Non-volatile Memory .............................. 27 2.2.3 Accessing Memory ............................... 29 2.2.4 Exercises .................................... 31 2.3 Digital I/O ........................................ 33 2.3.1 Digital Input .................................. 34 2.3.2 Digital Output ................................. 38 2.3.3 Exercises .................................... 39 2.4 Analog I/O ....................................... 40 2.4.1 Digital/Analog Conversion ........................... 40 2.4.2 Analog Comparator ............................... 41 2.4.3 Analog/Digital Conversion ........................... 42 2.4.4 Exercises .................................... 51 2.5 Interrupts ........................................ 52 2.5.1 Interrupt Control ................................ 52 2.5.2 Interrupt Handling ............................... 55 2.5.3 Interrupt Service Routine ............................ 57 2.5.4 Exercises .................................... 59 2.6 Timer .......................................... 60 2.6.1 Counter ..................................... 60 2.6.2 Input Capture .................................. 62 2.6.3 Output Compare ................................ 65 2.6.4 Pulse Width Modulation ............................ 65 2.6.5 Exercises .................................... 66 2.7 Other Features ...................................... 68 2.7.1 Watchdog Timer ................................ 68 i 2.7.2 Power Consumption and Sleep ......................... 69 2.7.3 Reset ...................................... 70 2.7.4 Exercises .................................... 71 3 Communication Interfaces 73 3.1 SCI (UART) ....................................... 75 3.2 SPI ............................................ 82 3.3 IIC (I2C) ........................................ 83 3.3.1 Data Transmission ............................... 84 3.3.2 Speed Control Through Slave ......................... 87 3.3.3 Multi-Master Mode ............................... 87 3.3.4 Extended Addresses .............................. 88 3.4 Exercises ........................................ 88 4 Software Development 89 4.1 Development Cycle ................................... 91 4.1.1 Design Phase .................................. 91 4.1.2 Implementation ................................. 92 4.1.3 Testing & Debugging .............................. 94 4.2 Programming ...................................... 97 4.2.1 Assembly Language Programming ....................... 97 4.3 Download ........................................ 117 4.3.1 Programming Interfaces ............................ 117 4.3.2 Bootloader ................................... 118 4.3.3 File Formats .................................. 118 4.4 Debugging ........................................ 121 4.4.1 No Debugger .................................. 121 4.4.2 ROM Monitor ................................. 124 4.4.3 Instruction Set Simulator ............................ 124 4.4.4 In-Circuit Emulator ............................... 125 4.4.5 Debugging Interfaces .............................. 125 4.5 Exercises ........................................ 127 5 Hardware 129 5.1 Switch/Button ...................................... 129 5.2 Matrix Keypad ..................................... 130 5.3 Potentiometer ...................................... 132 5.4 Phototransistor ..................................... 132 5.5 Position Encoder .................................... 133 5.6 LED ........................................... 134 5.7 Numeric Display .................................... 135 5.8 Multiplexed Display .................................. 136 5.9 Switching Loads .................................... 138 5.10 Motors .......................................... 140 5.10.1 Basic Principles of Operation ......................... 140 5.10.2 DC Motor .................................... 142 5.10.3 Stepper Motor ................................. 146 5.11 Exercises ........................................ 153 ii A Table of Acronyms 155 Index 159 iii iv Preface This text has been developed for the introductory courses on microcontrollers taught by the Institute of Computer Engineering at the Vienna University of Technology. It introduces undergraduate stu- dents to the field of microcontrollers – what they are, how they work, how they interface with their I/O components, and what considerations the programmer has to observe in hardware-based and em- bedded programming. This text is not intended to teach one particular controller architecture in depth, but should rather give an impression of the many possible architectures and solutions one can come across in today’s microcontrollers. We concentrate, however, on small 8-bit controllers and their most basic features, since they already offer enough variety to achieve our goals. Since one of our courses is a lab and uses the ATmega16, we tend to use this Atmel microcontroller in our examples. But we also use other controllers for demonstrations if appropriate. For a few technical terms, we also give their German translations to allow our mainly German- speaking students to learn both the English and the German term. Please help us further improve this text by notifying us of errors. If you have any sugges- tions/wishes like better and/or more thorough explanations, proposals for additional topics, . , feel free to email us at [email protected]. v Chapter 1 Microcontroller Basics 1.1 Introduction Even at a time when Intel presented the first microprocessor with the 4004 there was alrady a demand for microcontrollers: The contemporary TMS1802 from Texas Instruments, designed for usage in cal- culators, was by the end of 1971 advertised for applications in cash registers, watches and measuring instruments. The TMS 1000, which was introduced in 1974, already included RAM, ROM, and I/O on-chip and can be seen as one of the first microcontrollers, even though it was called a microcom- puter. The first controllers to gain really widespread use were the Intel 8048, which was integrated into PC keyboards, and its successor, the Intel 8051, as well as the 68HCxx series of microcontrollers from Motorola. Today, microcontroller production counts are in the billions per year, and the controllers are inte- grated into many appliances we have grown used to, like • household appliances (microwave, washing machine, coffee machine, . ) • telecommunication (mobile phones) • automotive industry (fuel injection, ABS, . ) • aerospace industry • industrial automation • ... But what is this microcontroller we are talking about? What is the difference to a microprocessor? And why do we need microcontrollers in the first place? To answer these questions, let us consider a simple toy project: A heat control system. Assume that we want to • periodically read the temperature (analog value, is digitized by sensor; uses 4-bit interface), • control heating according to the temperature (turn heater on/off; 1 bit), • display the current temperature on a simple 3-digit numeric display (8+3 bits), • allow the user to adjust temperature thresholds (buttons; 4 bits), and • be able to configure/upgrade the system over a serial interface. So we design a printed-circuit board (PCB) using Zilog’s Z80 processor. On the board, we put a Z80 CPU, 2 PIOs (parallel I/O; each chip has 16 I/O lines, we need 20), 1 SIO (serial I/O; for commu- nication to the PC), 1 CTC (Timer; for periodical actions), SRAM (for variables), Flash (for program 1 2 CHAPTER 1. MICROCONTROLLER BASICS memory), and EEPROM (for constants).1 The resulting board layout is depicted in Figure 1.1; as you can see, there are a lot of chips on the board, which take up most of the space (euro format, 10 × 16 cm). Figure 1.1: Z80 board layout for 32 I/O pins and Flash, EEPROM, SRAM. Incidentally, we could also solve the problem with the ATmega16 board we use in the Microcon- troller lab. In Figure 1.2, you can see the corresponding part of this board superposed on the Z80 PCB. The reduction in size is about a factor 5-6, and the ATmega16 board has even more features than the Z80 board (for example an analog converter)! The reason why we do not need much space for the ATmega16 board is that all those chips on the Z80 board are integrated into the ATmega16 microcontroller, resulting in a significant reduction in PCB size. This example clearly demonstrates the difference between microcontroller and microprocessor: A microcontroller is a processor with memory and a whole lot of other components integrated on one chip. The example also illustrates why microcontrollers are useful: The reduction of PCB size saves time, space, and money. The difference
Recommended publications
  • Microcode Revision Guidance August 31, 2019 MCU Recommendations
    microcode revision guidance August 31, 2019 MCU Recommendations Section 1 – Planned microcode updates • Provides details on Intel microcode updates currently planned or available and corresponding to Intel-SA-00233 published June 18, 2019. • Changes from prior revision(s) will be highlighted in yellow. Section 2 – No planned microcode updates • Products for which Intel does not plan to release microcode updates. This includes products previously identified as such. LEGEND: Production Status: • Planned – Intel is planning on releasing a MCU at a future date. • Beta – Intel has released this production signed MCU under NDA for all customers to validate. • Production – Intel has completed all validation and is authorizing customers to use this MCU in a production environment.
    [Show full text]
  • Arithmetic and Logic Unit (ALU)
    Computer Arithmetic: Arithmetic and Logic Unit (ALU) Arithmetic & Logic Unit (ALU) • Part of the computer that actually performs arithmetic and logical operations on data • All of the other elements of the computer system are there mainly to bring data into the ALU for it to process and then to take the results back out • Based on the use of simple digital logic devices that can store binary digits and perform simple Boolean logic operations ALU Inputs and Outputs Integer Representations • In the binary number system arbitrary numbers can be represented with: – The digits zero and one – The minus sign (for negative numbers) – The period, or radix point (for numbers with a fractional component) – For purposes of computer storage and processing we do not have the benefit of special symbols for the minus sign and radix point – Only binary digits (0,1) may be used to represent numbers Integer Representations • There are 4 commonly known (1 not common) integer representations. • All have been used at various times for various reasons. 1. Unsigned 2. Sign Magnitude 3. One’s Complement 4. Two’s Complement 5. Biased (not commonly known) 1. Unsigned • The standard binary encoding already given. • Only positive value. • Range: 0 to ((2 to the power of N bits) – 1) • Example: 4 bits; (2ˆ4)-1 = 16-1 = values 0 to 15 Semester II 2014/2015 8 1. Unsigned (Cont’d.) Semester II 2014/2015 9 2. Sign-Magnitude • All of these alternatives involve treating the There are several alternative most significant (leftmost) bit in the word as conventions used to
    [Show full text]
  • FUNDAMENTALS of COMPUTING (2019-20) COURSE CODE: 5023 502800CH (Grade 7 for ½ High School Credit) 502900CH (Grade 8 for ½ High School Credit)
    EXPLORING COMPUTER SCIENCE NEW NAME: FUNDAMENTALS OF COMPUTING (2019-20) COURSE CODE: 5023 502800CH (grade 7 for ½ high school credit) 502900CH (grade 8 for ½ high school credit) COURSE DESCRIPTION: Fundamentals of Computing is designed to introduce students to the field of computer science through an exploration of engaging and accessible topics. Through creativity and innovation, students will use critical thinking and problem solving skills to implement projects that are relevant to students’ lives. They will create a variety of computing artifacts while collaborating in teams. Students will gain a fundamental understanding of the history and operation of computers, programming, and web design. Students will also be introduced to computing careers and will examine societal and ethical issues of computing. OBJECTIVE: Given the necessary equipment, software, supplies, and facilities, the student will be able to successfully complete the following core standards for courses that grant one unit of credit. RECOMMENDED GRADE LEVELS: 9-12 (Preference 9-10) COURSE CREDIT: 1 unit (120 hours) COMPUTER REQUIREMENTS: One computer per student with Internet access RESOURCES: See attached Resource List A. SAFETY Effective professionals know the academic subject matter, including safety as required for proficiency within their area. They will use this knowledge as needed in their role. The following accountability criteria are considered essential for students in any program of study. 1. Review school safety policies and procedures. 2. Review classroom safety rules and procedures. 3. Review safety procedures for using equipment in the classroom. 4. Identify major causes of work-related accidents in office environments. 5. Demonstrate safety skills in an office/work environment.
    [Show full text]
  • The Central Processing Unit(CPU). the Brain of Any Computer System Is the CPU
    Computer Fundamentals 1'stage Lec. (8 ) College of Computer Technology Dept.Information Networks The central processing unit(CPU). The brain of any computer system is the CPU. It controls the functioning of the other units and process the data. The CPU is sometimes called the processor, or in the personal computer field called “microprocessor”. It is a single integrated circuit that contains all the electronics needed to execute a program. The processor calculates (add, multiplies and so on), performs logical operations (compares numbers and make decisions), and controls the transfer of data among devices. The processor acts as the controller of all actions or services provided by the system. Processor actions are synchronized to its clock input. A clock signal consists of clock cycles. The time to complete a clock cycle is called the clock period. Normally, we use the clock frequency, which is the inverse of the clock period, to specify the clock. The clock frequency is measured in Hertz, which represents one cycle/second. Hertz is abbreviated as Hz. Usually, we use mega Hertz (MHz) and giga Hertz (GHz) as in 1.8 GHz Pentium. The processor can be thought of as executing the following cycle forever: 1. Fetch an instruction from the memory, 2. Decode the instruction (i.e., determine the instruction type), 3. Execute the instruction (i.e., perform the action specified by the instruction). Execution of an instruction involves fetching any required operands, performing the specified operation, and writing the results back. This process is often referred to as the fetch- execute cycle, or simply the execution cycle.
    [Show full text]
  • The Birth, Evolution and Future of Microprocessor
    The Birth, Evolution and Future of Microprocessor Swetha Kogatam Computer Science Department San Jose State University San Jose, CA 95192 408-924-1000 [email protected] ABSTRACT timed sequence through the bus system to output devices such as The world's first microprocessor, the 4004, was co-developed by CRT Screens, networks, or printers. In some cases, the terms Busicom, a Japanese manufacturer of calculators, and Intel, a U.S. 'CPU' and 'microprocessor' are used interchangeably to denote the manufacturer of semiconductors. The basic architecture of 4004 same device. was developed in August 1969; a concrete plan for the 4004 The different ways in which microprocessors are categorized are: system was finalized in December 1969; and the first microprocessor was successfully developed in March 1971. a) CISC (Complex Instruction Set Computers) Microprocessors, which became the "technology to open up a new b) RISC (Reduced Instruction Set Computers) era," brought two outstanding impacts, "power of intelligence" and "power of computing". First, microprocessors opened up a new a) VLIW(Very Long Instruction Word Computers) "era of programming" through replacing with software, the b) Super scalar processors hardwired logic based on IC's of the former "era of logic". At the same time, microprocessors allowed young engineers access to "power of computing" for the creative development of personal 2. BIRTH OF THE MICROPROCESSOR computers and computer games, which in turn led to growth in the In 1970, Intel introduced the first dynamic RAM, which increased software industry, and paved the way to the development of high- IC memory by a factor of four.
    [Show full text]
  • An Introduction to Microcontrollers and Embedded Systems
    AN INTRODUCTION TO MICROCONTROLLERS AND EMBEDDED SYSTEMS Tyler Ross Lambert MECH 4240/4250 Supplementary Information Last Revision: 6/7/2017 5:30 PM Summary Embedded systems in robotics are the framework that allows electro-mechanical systems to be implemented into modern machines. The key aspects of this framework are C programming in embedded controllers, circuits for interfacing microcontrollers with sensors and actuators, and proper filtering and control of those hardware components. This document will cover the basics of C/C++ programming, including the basics of the C language in hardware interfacing, communication, and algorithms for state machines and controllers. In order to interface these controllers with the world around us, this document will also cover electrical circuits required to operate controllers, sensors, and actuators accurately and effectively. Finally, some of the more commonly used hardware that is interfaced with microcontrollers is gone over. Table of Contents 1. Introduction ....................................................................................................................................... 4 2. Numbering Systems .......................................................................................................................... 5 3. Variable Types and Memory............................................................................................................. 6 4. Basic C/C++ Notes and Code::Blocks .............................................................................................
    [Show full text]
  • Itanium-Based Solutions by Hp
    Itanium-based solutions by hp an overview of the Itanium™-based hp rx4610 server a white paper from hewlett-packard june 2001 table of contents table of contents 2 executive summary 3 why Itanium is the future of computing 3 rx4610 at a glance 3 rx4610 product specifications 4 rx4610 physical and environmental specifications 4 the rx4610 and the hp server lineup 5 rx4610 architecture 6 64-bit address space and memory capacity 6 I/O subsystem design 7 special features of the rx4610 server 8 multiple upgrade and migration paths for investment protection 8 high availability and manageability 8 advanced error detection, correction, and containment 8 baseboard management controller (BMC) 8 redundant, hot-swap power supplies 9 redundant, hot-swap cooling 9 hot-plug disk drives 9 hot-plug PCI I/O slots 9 internal removable media 10 system control panel 10 ASCII console for hp-ux 10 space-saving rack density 10 complementary design and packaging 10 how hp makes the Itanium transition easy 11 binary compatibility 11 hp-ux operating system 11 seamless transition—even for home-grown applications 12 transition help from hp 12 Itanium quick start service 12 partner technology access centers 12 upgrades and financial incentives 12 conclusion 13 for more information 13 appendix: Itanium advantages in your computing future 14 hp’s CPU roadmap 14 Itanium processor architecture 15 predication enhances parallelism 15 speculation minimizes the effect of memory latency 15 inherent scalability delivers easy expansion 16 what this means in a server 16 2 executive The Itanium™ Processor Family is the next great stride in computing--and it’s here today.
    [Show full text]
  • Architecture of 8051 & Their Pin Details
    SESHASAYEE INSTITUTE OF TECHNOLOGY ARIYAMANGALAM , TRICHY – 620 010 ARCHITECTURE OF 8051 & THEIR PIN DETAILS UNIT I WELCOME ARCHITECTURE OF 8051 & THEIR PIN DETAILS U1.1 : Introduction to microprocessor & microcontroller : Architecture of 8085 -Functions of each block. Comparison of Microprocessor & Microcontroller - Features of microcontroller -Advantages of microcontroller -Applications Of microcontroller -Manufactures of microcontroller. U1.2 : Architecture of 8051 : Block diagram of Microcontroller – Functions of each block. Pin details of 8051 -Oscillator and Clock -Clock Cycle -State - Machine Cycle -Instruction cycle –Reset - Power on Reset - Special function registers :Program Counter -PSW register -Stack - I/O Ports . U1.3 : Memory Organisation & I/O port configuration: ROM RAM - Memory Organization of 8051,Interfacing external memory to 8051 Microcontroller vs. Microprocessors 1. CPU for Computers 1. A smaller computer 2. No RAM, ROM, I/O on CPU chip 2. On-chip RAM, ROM, I/O itself ports... 3. Example:Intel’s x86, Motorola’s 3. Example:Motorola’s 6811, 680x0 Intel’s 8051, Zilog’s Z8 and PIC Microcontroller vs. Microprocessors Microprocessor Microcontroller 1. CPU is stand-alone, RAM, ROM, I/O, timer are separate 1. CPU, RAM, ROM, I/O and timer are all on a single 2. designer can decide on the chip amount of ROM, RAM and I/O ports. 2. fix amount of on-chip ROM, RAM, I/O ports 3. expansive 3. for applications in which 4. versatility cost, power and space are 5. general-purpose critical 4. single-purpose uP vs. uC – cont. Applications – uCs are suitable to control of I/O devices in designs requiring a minimum component – uPs are suitable to processing information in computer systems.
    [Show full text]
  • Arduino and AVR
    Arduino and AVR Ke vin J Dola n a nd Eric Te ve lson Agenda • History of Arduino • Comparison to Other Platforms • Arduino Uno - Hardware • ATmega328P Peripherals • Instruction Set • Processor Components • Pipe lining • Programming • Applica tions • Future of Arduino History of Arduino • Fa mily of Microcontrolle rs cre a te d a s a ma ste rs the sis proje ct • intended for use by a non-technical audience of artists, designers, etc. • Made for accessibility and ease of use. • Programming made easy for the audience • Ability to program board via USB • Inexpensive price point • Expanded for other types and configurations • Example: Arduino Lilypad for wearable technologies • Popularity has expanded functionality including “shields” and Bluetooth. Comparison to Other Platforms • Raspberry Pi • Raspberry Pi is a full computer that can run and support an OS, and has built in graphics. • Porta bility is a n issue , since a n e xte rna l supply is ne e de d. • Network needs more setup on an Arduino • Raspberry Pi does not support analog sensors as well • Teensy • Less expensive • Compatible with Arduino “sketches” and “shields” • Be tte r ADC sa mpling, sa me functiona lity, be tte r re solution • Sma lle r physica l boa rd size Arduino Uno - Hardware • ATmega328P Microcontroller • 3 2 KB Fla s h Me m o ry (2 KB S RAM, 1 KB EEP RO M) • 16 MH z C lo c k • 14 Digita l I/O Pins • 6 PWM Digita l I/O Pins • 6 Analog Input Pins • Up to 20mA DC Current per I/O Pin up to 300mA total across all pins • 50mA DC Current on 3.3V Pin Arduino Uno - Hardware ATmega328P Peripherals • Total of 6 accessible A/D Pins on Port C • 14 GPIO (7 Pins each from PORT B & D) • UART (Se ria l) • SPI Support • Watchdog timer to reset CPU Instruction Set • Harvard Architecture, which is non-von Neumann memory, but still a von Neumann architecture.
    [Show full text]
  • The Central Processor Unit
    Systems Architecture The Central Processing Unit The Central Processing Unit – p. 1/11 The Computer System Application High-level Language Operating System Assembly Language Machine level Microprogram Digital logic Hardware / Software Interface The Central Processing Unit – p. 2/11 CPU Structure External Memory MAR: Memory MBR: Memory Address Register Buffer Register Address Incrementer R15 / PC R11 R7 R3 R14 / LR R10 R6 R2 R13 / SP R9 R5 R1 R12 R8 R4 R0 User Registers Booth’s Multiplier Barrel IR Shifter Control Unit CPSR 32-Bit ALU The Central Processing Unit – p. 3/11 CPU Registers Internal Registers Condition Flags PC Program Counter C Carry IR Instruction Register Z Zero MAR Memory Address Register N Negative MBR Memory Buffer Register V Overflow CPSR Current Processor Status Register Internal Devices User Registers ALU Arithmetic Logic Unit Rn Register n CU Control Unit n = 0 . 15 M Memory Store SP Stack Pointer MMU Mem Management Unit LR Link Register Note that each CPU has a different set of User Registers The Central Processing Unit – p. 4/11 Current Process Status Register • Holds a number of status flags: N True if result of last operation is Negative Z True if result of last operation was Zero or equal C True if an unsigned borrow (Carry over) occurred Value of last bit shifted V True if a signed borrow (oVerflow) occurred • Current execution mode: User Normal “user” program execution mode System Privileged operating system tasks Some operations can only be preformed in a System mode The Central Processing Unit – p. 5/11 Register Transfer Language NAME Value of register or unit ← Transfer of data MAR ← PC x: Guard, only if x true hcci: MAR ← PC (field) Specific field of unit ALU(C) ← 1 (name), bit (n) or range (n:m) R0 ← MBR(0:7) Rn User Register n R0 ← MBR num Decimal number R0 ← 128 2_num Binary number R1 ← 2_0100 0001 0xnum Hexadecimal number R2 ← 0x40 M(addr) Memory Access (addr) MBR ← M(MAR) IR(field) Specified field of IR CU ← IR(op-code) ALU(field) Specified field of the ALU(C) ← 1 Arithmetic and Logic Unit The Central Processing Unit – p.
    [Show full text]
  • Digital Preservation Guide: 3.5-Inch Floppy Disks Caralie Heinrichs And
    DIGITAL PRESERVATION GUIDE: 3.5-Inch Floppy Disks Digital Preservation Guide: 3.5-Inch Floppy Disks Caralie Heinrichs and Emilie Vandal ISI 6354 University of Ottawa Jada Watson Friday, December 13, 2019 DIGITAL PRESERVATION GUIDE 2 Table of Contents Introduction ................................................................................................................................................. 3 History of the Floppy Disk ......................................................................................................................... 3 Where, when, and by whom was it developed? 3 Why was it developed? 4 How Does a 3.5-inch Floppy Disk Work? ................................................................................................. 5 Major parts of a floppy disk 5 Writing data on a floppy disk 7 Preservation and Digitization Challenges ................................................................................................. 8 Physical damage and degradation 8 Hardware and software obsolescence 9 Best Practices ............................................................................................................................................. 10 Storage conditions 10 Description and documentation 10 Creating a disk image 11 Ensuring authenticity: Write blockers 11 Ensuring reliability: Sustainability of the disk image file format 12 Metadata 12 Virus scanning 13 Ensuring integrity: checksums 13 Identifying personal or sensitive information 13 Best practices: Use of hardware and software 14 Hardware
    [Show full text]
  • Chapter 1: Microprocessor Architecture
    Chapter 1: Microprocessor architecture ECE 3120 – Fall 2013 Dr. Mohamed Mahmoud http://iweb.tntech.edu/mmahmoud/ [email protected] Outline 1.1 Computer hardware organization 1.1.1 Number System 1.1.2 Computer hardware organization 1.2 The processor 1.3 Memory system operation 1.4 Program Execution 1.5 HCS12 Microcontroller 1.1.1 Number System - Computer hardware uses binary numbers to perform all operations. - Human beings are used to decimal number system. Conversion is often needed to convert numbers between the internal (binary) and external (decimal) representations. - Octal and hexadecimal numbers have shorter representations than the binary system. - The binary number system has two digits 0 and 1 - The octal number system uses eight digits 0 and 7 - The hexadecimal number system uses 16 digits: 0, 1, .., 9, A, B, C,.., F 1 - 1 - A prefix is used to indicate the base of a number. - Convert %01000101 to Hexadecimal = $45 because 0100 = 4 and 0101 = 5 - Computer needs to deal with signed and unsigned numbers - Two’s complement method is used to represent negative numbers - A number with its most significant bit set to 1 is negative, otherwise it is positive. 1 - 2 1- Unsigned number %1111 = 1 + 2 + 4 + 8 = 15 %0111 = 1 + 2 + 4 = 7 Unsigned N-bit number can have numbers from 0 to 2N-1 2- Signed number %1111 is a negative number. To convert to decimal, calculate the two’s complement The two’s complement = one’s complement +1 = %0000 + 1 =%0001 = 1 then %1111 = -1 %0111 is a positive number = 1 + 2 + 4 = 7.
    [Show full text]