You are previewing Programming 32-bit Microcontrollers in C.
O'Reilly logo
Programming 32-bit Microcontrollers in C

Book Description

*Just months after the introduction of the new generation of 32-bit PIC microcontrollers, a Microchip insider and acclaimed author takes you by hand at the exploration of the PIC32

*Free CD-ROM includes source code in C and the Microchip MPLAB C32 compiler

*Includes handy checklists to help readers perform the most common programming and debugging tasks

The new 32-bit microcontrollers bring the promise of more speed and more performance while offering an unprecedented level of compatibility with existing 8 and 16-bit PIC microcontrollers. In sixteen engaging chapters, using a parallel track to his previous title dedicated to 16-bit programming, the author puts all these claims to test while offering a gradual introduction to the development and debugging of embedded control applications in C.
Author Lucio Di Jasio, a PIC and embedded control expert, offers unique insight into the new 32-bit architecture while developing a number of projects of growing complexity.
Experienced PIC users and newcomers to the field alike will benefit from the text’s many thorough examples which demonstrate how to nimbly side-step common obstacles, solve real-world design problems efficiently and optimize code using the new PIC32 features and peripheral set.

You will learn about:
*basic timing and I/O operation
*debugging methods with the MPLAB SIM *simulator and ICD tools
*multitasking using the PIC32 interrupts
*all the new hardware peripherals
*how to control LCD displays
*experimenting with the Explorer16 board and *the PIC32 Starter Kit
*accessing mass-storage media
*generating audio and video signals
*and more!

TABLE OF CONTENTS
Day 1 And the adventure begins
Day 2 Walking in circles
Day 3 Message in a Bottle
Day 4 NUMB3RS
Day 5 Interrupts
Day 6 Memory
Part 2 Experimenting
Day 7 Running
Day 8 Communication
Day 9 Links
Day 10 Glass = Bliss
Day 11 It’s an analog world
Part 3 Expansion
Day 12 Capturing User Inputs
Day 13 UTube
Day 14 Mass Storage
Day 15 File I/O
Day 16 Musica Maestro!

*32-bit microcontrollers are becoming the technology of choice for high performance embedded control applications including portable media players, cell phones, and GPS receivers.
*Learn to use the C programming language for advanced embedded control designs and/or learn to migrate your applications from previous 8 and 16-bit architectures.
*All code examples and software tools required to get acquainted with Microchip’s MPLAB development environment, and to complete all the projects described in the book, are offered in the attached CDROM including the MPLAB C32 C Compiler (free Student Edition) and the full source code for more than 15 entertaining projects.

Table of Contents

  1. Cover
  2. Title Page
  3. Copyright
  4. Dedication
  5. Acknowledgments
  6. Introduction
    1. Who Should Read this Book?
    2. Structure of the Book
    3. What this Book is Not
    4. Checklists
  7. Table of Contents
  8. Part I: Exploring
    1. Day 1: The Adventure Begins
      1. The Plan
      2. Preparation
      3. The Adventure Begins
      4. Compiling and Linking
      5. The Linker Script
      6. Building the First Project
      7. Using the Simulator
      8. Finding a Direction
      9. The JTAG Port
      10. Testing PORTB
      11. Mission Debriefing
      12. Notes for the Assembly Experts
      13. Notes for the PIC MCU Experts
      14. Notes for the C Experts
      15. Tips & Tricks
      16. Exercises
      17. Books
      18. Links
    2. Day 2: Walking in Circles
      1. The Plan
      2. Preparation
      3. The Exploration
      4. While Loops
      5. An Animated Simulation
      6. Using the Logic Analyzer
      7. Debriefing
      8. Notes for the Assembly Experts
      9. Notes for the 8-Bit PIC Microcontroller Experts
      10. Notes for the 16-Bit PIC Microcontroller Experts
      11. Notes for the C Experts
      12. Notes for the MIPS Experts
      13. Tips & Tricks
      14. Notes on Using the Peripheral Libraries
      15. Exercises
      16. Books
      17. Links
    3. Day 3: Message in a Bottle
      1. The Plan
      2. Preparation
      3. The Exploration
      4. Do Loops
      5. Variable Declarations
      6. for Loops
      7. More Loop Examples
      8. Arrays
      9. Sending a Message
      10. Testing with the Logic Analyzer
      11. Testing with the Explorer 16 Demonstration Board
      12. Testing with the PIC32 Starter Kit
      13. Debriefing
      14. Notes for the Assembly Experts
      15. Notes for the PIC Microcontroller Experts
      16. Notes for the C Experts
      17. Tips & Tricks
      18. Exercises
      19. Books
      20. Links
    4. Day 4: NUMB3RS
      1. The Plan
      2. Preparation
      3. The Exploration
      4. On Optimizations (or Lack Thereof)
      5. Testing
      6. Going long long
      7. Integer Divisions
      8. Floating Point
      9. Measuring Performance
      10. Debriefing
      11. Notes for the Assembly Experts
      12. Notes for the 8-Bit PIC® Microcontroller Experts
      13. Notes for the 16-Bit PIC and dsPIC® Microcontroller Experts
      14. Tips & Tricks
      15. Exercises
      16. Books
      17. Links
    5. Day 5: Interrupts
      1. The Plan
      2. Preparation
      3. The Exploration
      4. Interrupts and Exceptions
      5. Sources of Interrupt
      6. Interrupt Priorities
      7. The Interrupt Management Library
      8. Managing Multiple Interrupts
      9. Multivectored Interrupt Management
      10. A Simple Application
      11. The Real-Time Clock Calendar (RTCC)
      12. Debriefing
      13. Tips & Tricks
      14. Books
      15. Links
    6. Day 6: Memory
      1. The Plan
      2. Preparation
      3. The Exploration
      4. Memory Space Allocation
      5. Looking at the Map
      6. Pointers
      7. The Heap
      8. The PIC32MX Bus
      9. PIC32MX Memory Mapping
      10. The Embedded-Control Memory Map
      11. Debriefing
      12. Notes for the C Experts
      13. Notes for the Assembly Experts
      14. Notes for the PIC Microcontroller Experts
      15. Tips & Tricks
      16. Exercises
      17. Books
      18. Links
  9. Part II: Experimenting
    1. Day 7: Running
      1. The Plan
      2. Preparation
      3. The Exploration
      4. Performance vs. Power Consumption
      5. The Primary Oscillator Clock Chain
      6. The Peripheral Bus Clock
      7. Initial Device Configuration
      8. Setting Configuration Bits in Code
      9. Heavy Stuff
      10. Ready, Set, Go!
      11. Fine-Tuning the PIC32: Configuring Flash Wait States
      12. Fine-Tuning the PIC32: Enabling the Instruction and Data Cache
      13. Fine-Tuning the PIC32: Enabling the Instruction Pre-Fetch
      14. Fine-Tuning the PIC32: Final Notes
      15. Debriefing
      16. Notes for the Assembly Experts
      17. Notes for the PlC® Microcontroller Experts
      18. Tips & Tricks
      19. Exercises
      20. Books
      21. Links
    2. Day 8: Communication
      1. The Plan
      2. Preparation
      3. The Exploration
      4. Synchronous Serial Interfaces
      5. Asynchronous Serial Interfaces
      6. Parallel Interfaces
      7. Synchronous Communication Using the SPI Modules
      8. Testing the Read Status Register Command
      9. Writing Data to the EEPROM
      10. Reading the Memory Contents
      11. A 32-Bit Serial EEPROM Library
      12. Testing the New SEE Library
      13. Debriefing
      14. Notes for the C Experts
      15. Notes for the Explorer 16 Experts
      16. Notes for the PIC24 Experts
      17. Tips & Tricks
      18. Exercises
      19. Books
      20. Links
    3. Day 9: Asynchronous Communication
      1. The Plan
      2. Preparation
      3. The Exploration
      4. UART Configuration
      5. Sending and Receiving Data
      6. Testing the Serial Communication Routines
      7. Building a Simple Console Library
      8. Testing a VT100 Terminal
      9. The Serial Port as a Debugging Tool
      10. The Matrix Project
      11. Debriefing
      12. Notes for the C Experts
      13. Notes for the PIC® Microcontroller Experts
      14. Tips & Tricks
      15. Exercises
      16. Books
      17. Links
    4. Day 10: Glass = Bliss
      1. The Plan
      2. Preparation
      3. The Exploration
      4. HD44780 Controller Compatibility
      5. The Parallel Master Port
      6. Configuring the PMP for LCD Module Control
      7. A Small Library of Functions to Access an LCD Display
      8. Building an LCD Library and Using the PMP Library
      9. THE EXPLORER.C LIBRARY
      10. Creating the include and lib Directories
      11. Advanced LCD Control
      12. Progress Bar Project
      13. Debriefing
      14. Notes for the PIC24 Experts
      15. Tips & Tricks
      16. Exercises
      17. Books
      18. Links
    5. Day 11: It’s an Analog World
      1. The Plan
      2. Preparation
      3. The Exploration
      4. The First Conversion
      5. Automating Sampling Timing
      6. Developing a Demo
      7. Creating Our Own Mini ADC Library
      8. Fun and Games
      9. Sensing Temperature
      10. Debriefing
      11. Notes for the PIC24 Experts
      12. Tips & Tricks
      13. Exercises
      14. Books
      15. Links
  10. Part III: Expansion
    1. Day 12: Capturing User Inputs
      1. The Plan
      2. Preparation
      3. Buttons and Mechanical Switches
      4. Button Input Packing
      5. Button Inputs Debouncing
      6. Rotary Encoders
      7. Interrupt-Driven Rotary Encoder Input
      8. Keyboards
      9. PS/2 Physical Interface
      10. The PS/2 Communication Protocol
      11. Interfacing the PIC32 to the PS/2
      12. Input Capture
      13. Testing Using a Stimulus Scripts
      14. The Simulator Profiler
      15. Change Notification
      16. Evaluating Cost
      17. I/O Polling
      18. Testing the I/O Polling Method
      19. Cost and Efficiency Considerations
      20. Keyboard Buffering
      21. Key Code Decoding
      22. Debriefing
      23. Notes for the PIC24 Experts
      24. Tips & Tricks
      25. Exercises
      26. Books
      27. Links
    2. Day 13: UTube
      1. The Plan
      2. Preparation
      3. The Exploration
      4. Generating the Composite Video Signal
      5. The Output Compare Modules
      6. Image Buffers
      7. Serialization, DMA, and Synchronization
      8. Completing a Video Library
      9. Testing the Composite Video
      10. Measuring Performance
      11. Seeing the Dark Screen
      12. Test Pattern
      13. Plotting
      14. A Starry Night
      15. Line Drawing
      16. Bresenham Algorithm
      17. Plotting Math Functions
      18. Fractals
      19. Text
      20. Printing Text on Video
      21. Text Test
      22. The Matrix Reloaded
      23. Debriefing
      24. Notes for the PIC24 Experts
      25. Tips & Tricks
      26. Exercises
      27. Books
      28. Links
    3. Day 14: Mass Storage
      1. The Plan
      2. Preparation
      3. The Exploration
      4. The Physical Interface
      5. Interfacing to the Explorer 16 Board
      6. Starting a New Project
      7. Selecting the SPI Mode of Operation
      8. Sending Commands in SPI Mode
      9. Completing the SD Card Initialization
      10. Reading Data from an SD/MMC Card
      11. Writing Data to an SD/MMC Card
      12. Testing the SD/MMC Interface
      13. Debriefing
      14. Tips & Tricks
      15. Exercises
      16. Books
      17. Links
    4. Day 15: File I/O
      1. The Plan
      2. Preparation
      3. The Exploration
      4. Sectors and Clusters
      5. The File Allocation Table
      6. The Root Directory
      7. The Treasure Hunt
      8. Opening a File
      9. Reading Data from a File
      10. Closing a File
      11. The Fileio Module
      12. Testing fopenM() and freadM()
      13. Writing Data to a File
      14. Closing a File, Take Two
      15. Accessory Functions
      16. Testing the Complete Fileio Module
      17. Code Size
      18. Debriefing
      19. Tips & Tricks
      20. Exercises
      21. Books
      22. Links
    5. Day 16: Musica, Maestro!
      1. The Plan
      2. Preparation
      3. The Exploration
      4. OC PWM Mode
      5. Testing the PWM as a D/A Converter
      6. Producing Analog Waveforms
      7. Reproducing Voice Messages
      8. A Media Player
      9. The WAVE File Format
      10. The play() Function
      11. The Audio Routines
      12. A Simple WAVE File Player
      13. Debriefing
      14. Tips & Tricks
      15. Exercises
      16. Books
      17. Links
      18. Disclaimer
      19. Final Note for the Experts
  11. Index