The Texas Instruments MSP430
Total Page:16
File Type:pdf, Size:1020Kb
MSP430 Microcontroller Basics This page intentionally left blank MSP430 Microcontroller Basics John H. Davies AMSTERDAM • BOSTON • HEIDELBERG • LONDON NEW YORK • OXFORD • PARIS • SAN DIEGO SAN FRANCISCO • SINGAPORE • SYDNEY • TOKYO Newnes is an imprint of Elsevier Newnes is an imprint of Elsevier 30 Corporate Drive, Suite 400, Burlington, MA 01803, USA Linacre House, Jordan Hill, Oxford OX2 8DP, UK Copyright © 2008, Elsevier Ltd. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher. Permissions may be sought directly from Elsevier’s Science & Technology Rights Department in Oxford, UK: phone: (+44) 1865 843830, fax: (+44) 1865 853333, E-mail: [email protected]. You may also complete your request online via the Elsevier homepage (http://www.elsevier.com) by selecting “Support & Contact” then “Copyright and Permission” and then “Obtaining Permissions.” Recognizing the importance of preserving what has been written, Elsevier prints its books on acid-free paper whenever possible. Library of Congress Cataloging-in-Publication Data Application submitted British Library Cataloguing-in-Publication Data A catalogue record for this book is available from the British Library. ISBN: 978-0-7506-8276-3 For information on all Newnes publications, visit our Web site at: http://www.books.elsevier.com 08091011121310987654321 Printed in the United States of America “To Elizabeth.” This page intentionally left blank Contents Preface ........................................................................... xi Chapter 1: Embedded Electronic Systems and Microcontrollers ................... 1 1.1 What (and Where) Are Embedded Systems? .................................... 1 1.2 Approaches to Embedded Systems............................................... 2 1.3 Small Microcontrollers ........................................................... 5 1.4 Anatomy of a Typical Small Microcontroller.................................... 8 1.5 Memory........................................................................... 11 1.6 Software .......................................................................... 15 1.7 Where Does the MSP430 Fit? ................................................... 16 Chapter 2: The Texas Instruments MSP430 .....................................21 2.1 The Outside View—Pin-Out .................................................... 21 2.2 The Inside View—Functional Block Diagram.................................. 24 2.3 Memory........................................................................... 25 2.4 Central Processing Unit.......................................................... 30 2.5 Memory-Mapped Input and Output ............................................. 32 2.6 Clock Generator.................................................................. 33 2.7 Exceptions: Interrupts and Resets ............................................... 36 2.8 Where to Find Further Information ............................................. 37 Chapter 3: Development.........................................................43 3.1 Development Environment ...................................................... 44 3.2 The C Programming Language .................................................. 46 3.3 Assembly Language.............................................................. 55 3.4 Access to the Microcontroller for Programming and Debugging.............. 57 3.5 Demonstration Boards ........................................................... 59 3.6 Hardware ......................................................................... 64 3.7 Equipment ........................................................................ 65 www.newnespress.com viii Contents Chapter 4: A Simple Tour of the MSP430 .......................................67 4.1 First Program on a Conventional Desktop Computer .......................... 68 4.2 Light LEDs in C ................................................................. 70 4.3 Light LEDs in Assembly Language ............................................. 72 4.4 Read Input from a Switch ....................................................... 80 4.5 Automatic Control: Flashing Light by Software Delay ........................ 91 4.6 Automatic Control: Use of Subroutines......................................... 99 4.7 Automatic Control: Flashing Light by Polling Timer_A ......................105 4.8 Header Files and Issues Brushed under the Carpet ............................114 Chapter 5: Architecture of the MSP430 Processor .............................119 5.1 Central Processing Unit.........................................................119 5.2 Addressing Modes ..............................................................125 5.3 Constant Generator and Emulated Instructions................................131 5.4 Instruction Set ...................................................................132 5.5 Examples ........................................................................146 5.6 Reflections on the CPU and Instruction Set ...................................153 5.7 Resets ............................................................................157 5.8 Clock System....................................................................163 Chapter 6: Functions, Interrupts, and Low-Power Modes .......................177 6.1 Functions and Subroutines .....................................................178 6.2 What Happens when a Subroutine Is Called? .................................178 6.3 Storage for Local Variables .....................................................179 6.4 Passing Parameters to a Subroutine and Returning a Result ..................183 6.5 Mixing C and Assembly Language ............................................185 6.6 Interrupts ........................................................................186 6.7 What Happens when an Interrupt Is Requested? ..............................188 6.8 Interrupt Service Routines ......................................................190 6.9 Issues Associated with Interrupts...............................................196 6.10 Low-Power Modes of Operation ...............................................198 Chapter 7: Digital Input, Output, and Displays .................................207 7.1 Digital Input and Output: Parallel Ports .......................................208 7.2 Digital Inputs ....................................................................216 7.3 Switch Debounce ...............................................................225 7.4 Digital Outputs ..................................................................238 7.5 Interface between 3V and 5V Systems.........................................243 7.6 Driving Heavier Loads..........................................................247 7.7 Liquid Crystal Displays.........................................................252 7.8 Driving an LCD from an MSP430x4xx........................................256 7.9 Simple Applications of the LCD ...............................................264 www.newnespress.com Contents ix Chapter 8: Timers ..............................................................275 8.1 Watchdog Timer.................................................................276 8.2 Basic Timer1 ....................................................................281 8.3 Timer_A .........................................................................287 8.4 Measurement in the Capture Mode ............................................300 8.5 Output in the Continuous Mode ................................................318 8.6 Output in the Up Mode: Edge-Aligned Pulse-Width Modulation ............330 8.7 Output in the Up/Down Mode: Centered Pulse-Width Modulation ..........349 8.8 Operation of Timer_A in the Sampling Mode .................................352 8.9 Timer_B .........................................................................353 8.10 What Timer Where?.............................................................356 8.11 Setting the Real-Time Clock: State Machines .................................357 Chapter 9: Mixed-Signal Systems: Analog Input and Output ....................369 9.1 Comparator_A...................................................................371 9.2 Analog-to-Digital Conversion: General Issues ................................393 9.3 Analog-to-Digital Conversion: Successive Approximation ...................402 9.4 The ADC10 Successive-Approximation ADC.................................407 9.5 Basic Operation of the ADC10 .................................................412 9.6 More Advanced Operation of the ADC10 .....................................424 9.7 The ADC12 Successive-Approximation ADC.................................432 9.8 Analog-to-Digital Conversion: Sigma–Delta ..................................438 9.9 The SD16_A Sigma–Delta ADC ...............................................446 9.10 Operation of SD16_A...........................................................459 9.11 Signal Conditioning and Operational Amplifiers ..............................475 9.12 Digital-to-Analog Conversion ..................................................485 Chapter 10: Communication....................................................493 10.1 Communication Peripherals in the MSP430 ...................................495 10.2 Serial Peripheral Interface