*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*Includes handy checklists to help readers perform the most common programming and debugging tasksThe 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 CONTENTSDay 1 And the adventure beginsDay 2 Walking in circlesDay 3 Message in a BottleDay 4 NUMB3RSDay 5 InterruptsDay 6 Memory Part 2 ExperimentingDay 7 RunningDay 8 Communication Day 9 LinksDay 10 Glass = BlissDay 11 It's an analog worldPart 3 ExpansionDay 12 Capturing User InputsDay 13 UTubeDay 14 Mass StorageDay 15 File I/ODay 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.
Inhaltsverzeichnis
1;Front Cover;1 2;Programming 32-bit Microcontrollers in C: Exploring the PIC32;4 3;Copyright Page;5 4;Contents;10 5;Introduction;20 6;Part 1: Exploring;28 6.1;Day 1: The Adventure Begins;30 6.1.1;The Plan;30 6.1.2;Preparation;30 6.1.3;The Adventure Begins;33 6.1.4;Compiling and Linking;35 6.1.5;The Linker Script;37 6.1.6;Building the First Project;38 6.1.7;Using the Simulator;39 6.1.8;Finding a Direction;41 6.1.9;The JTAG Port;43 6.1.10;Testing PORTB;44 6.1.11;Mission Debriefing;46 6.1.12;Notes for the Assembly Experts;47 6.1.13;Notes for the PIC MCU Experts;49 6.1.14;Notes for the C Experts;49 6.1.15;Tips & Tricks;49 6.1.16;Exercises;50 6.1.17;Books;51 6.1.18;Links;51 6.2;Day 2: Walking in Circles;52 6.2.1;The Plan;52 6.2.2;Preparation;52 6.2.3;The Exploration;54 6.2.4;While Loops;55 6.2.5;An Animated Simulation;58 6.2.6;Using the Logic Analyzer;62 6.2.7;Debriefing;64 6.2.8;Notes for the Assembly Experts;65 6.2.9;Notes for the 8-Bit PIC Microcontroller Experts;65 6.2.10;Notes for the 16-Bit PIC Microcontroller Experts;65 6.2.11;Notes for the C Experts;66 6.2.12;Notes for the MIPS Experts;66 6.2.13;Tips & Tricks;66 6.2.14;Notes on Using the Peripheral Libraries;67 6.2.15;Exercises;69 6.2.16;Books;69 6.2.17;Links;69 6.3;Day 3: Message in a Bottle;70 6.3.1;The Plan;70 6.3.2;Preparation;70 6.3.3;The Exploration;70 6.3.4;Do Loops;71 6.3.5;Variable Declarations;72 6.3.6;for Loops;74 6.3.7;More Loop Examples;75 6.3.8;Arrays;76 6.3.9;Sending a Message;77 6.3.10;Testing with the Logic Analyzer;80 6.3.11;Testing with the Explorer 16 Demonstration Board;81 6.3.12;Testing with the PIC32 Starter Kit;82 6.3.13;Debriefing;84 6.3.14;Notes for the Assembly Experts;84 6.3.15;Notes for the PIC Microcontroller Experts;85 6.3.16;Notes for the C Experts;85 6.3.17;Tips & Tricks;86 6.3.18;Exercises;87 6.3.19;Books;87 6.3.20;Links;87 6.4;Day 4: NUMB3RS;88 6.4.1;The Plan;88 6.4.2;Preparation;88 6.4.3;The Exploration;88 6.4.4;On Optimizations (or Lack Thereof);91 6.4.5;Testing;91 6.4.6;Goin
g long long;92 6.4.7;Integer Divisions;94 6.4.8;Floating Point;96 6.4.9;Measuring Performance;97 6.4.10;Debriefing;100 6.4.11;Notes for the Assembly Experts;100 6.4.12;Notes for the 8-Bit PIC Microcontroller Experts;102 6.4.13;Notes for the 16-Bit PIC and dsPIC Microcontroller Experts;103 6.4.14;Tips & Tricks;104 6.4.15;Exercises;105 6.4.16;Books;106 6.4.17;Links;106 6.5;Day 5: Interrupts;108 6.5.1;The Plan;108 6.5.2;Preparation;108 6.5.3;The Exploration;108 6.5.4;Interrupts and Exceptions;109 6.5.5;Sources of Interrupt;111 6.5.6;Interrupt Priorities;112 6.5.7;Interrupt Handlers Declaration;115 6.5.8;The Interrupt Management Library;117 6.5.9;Single Vector Interrupt Management;117 6.5.10;Managing Multiple Interrupts;122 6.5.11;Multivectored Interrupt Management;125 6.5.12;A Simple Application;130 6.5.13;The Secondary Oscillator;135 6.5.14;The Real-Time Clock Calendar (RTCC);136 6.5.15;Debriefing;138 6.5.16;Notes for the PIC Microcontroller Experts;138 6.5.17;Tips & Tricks;139 6.5.18;Exercises;140 6.5.19;Books;140 6.5.20;Links;140 6.6;Day 6: Memory;142 6.6.1;The Plan;142 6.6.2;Preparation;142 6.6.3;The Exploration;143 6.6.4;Memory Space Allocation;145 6.6.5;Looking at the MAP;150 6.6.6;Pointers;154 6.6.7;The Heap;155 6.6.8;The PIC32MX Bus;156 6.6.9;PIC32MX Memory Mapping;157 6.6.10;The Embedded-Control Memory Map;161 6.6.11;Debriefing;162 6.6.12;Notes for the C Experts;162 6.6.13;Notes for the Assembly Experts;163 6.6.14;Notes for the PIC Microcontroller Experts;163 6.6.15;Tips & Tricks;164 6.6.16;Exercises;164 6.6.17;Books;165 6.6.18;Links;165 7;Part 2: Experimenting;166 7.1;Day 7: Running;168 7.1.1;The Plan;168 7.1.2;Preparation;168 7.1.3;The Exploration;169 7.1.4;Performance vs. Power Consumption;171 7.1.5;The Primary Oscillator Clock Chain;173 7.1.6;The Peripheral Bus Clock;174 7.1.7;Initial Device Configuration;175 7.1.8;Setting Configuration Bits in Code;177 7.1.9;Heavy Stuff;179 7.1.10;Ready, Set, Go!;185 7.1.11;Fine-Tuning the PIC32: Configuring Flash Wait St
ates;187 7.1.12;Fine-Tuning the PIC32: Enabling the Instruction and Data Cache;190 7.1.13;Fine-Tuning the PIC32: Enabling the Instruction Pre-Fetch;191 7.1.14;Fine-Tuning the PIC32: Final Notes;192 7.1.15;Debriefing;194 7.1.16;Notes for the Assembly Experts;194 7.1.17;Notes for the PIC Microcontroller Experts;194 7.1.18;Tips & Tricks;195 7.1.19;Exercises;198 7.1.20;Books;198 7.1.21;Links;198 7.2;Day 8: Communication;200 7.2.1;The Plan;200 7.2.2;Preparation;200 7.2.3;The Exploration;201 7.2.4;Synchronous Serial Interfaces;201 7.2.5;Asynchronous Serial Interfaces;203 7.2.6;Parallel Interfaces;204 7.2.7;Synchronous Communication Using the SPI Modules;205 7.2.8;Testing the Read Status Register Command;209 7.2.9;Writing Data to the EEPROM;213 7.2.10;Reading the Memory Contents;214 7.2.11;A 32-bit Serial EEPROM Library;214 7.2.12;Testing the New SEE Library;218 7.2.13;Debriefing;220 7.2.14;Notes for the C Experts;220 7.2.15;Notes for the Explorer 16 Experts;220 7.2.16;Notes for the PIC24 Experts;221 7.2.17;Tips & Tricks;221 7.2.18;Exercises;222 7.2.19;Books;223 7.2.20;Links;223 7.3;Day 9: Asynchronous Communication;224 7.3.1;The Plan;224 7.3.2;Preparation;224 7.3.3;The Exploration;224 7.3.4;UART Configuration;227 7.3.5;Sending and Receiving Data;229 7.3.6;Testing the Serial Communication Routines;231 7.3.7;Building a Simple Console Library;233 7.3.8;Testing a VT100 Terminal;236 7.3.9;The Serial Port as a Debugging Tool;238 7.3.10;The Matrix Project;238 7.3.11;Debriefing;241 7.3.12;Notes for the C Experts;241 7.3.13;Notes for the PIC Microcontroller Experts;242 7.3.14;Tips & Tricks;242 7.3.15;Exercises;243 7.3.16;Books;243 7.3.17;Links;244 7.4;Day 10: Glass = Bliss;246 7.4.1;The Plan;246 7.4.2;Preparation;246 7.4.3;The Exploration;246 7.4.4;HD44780 Controller Compatibility;248 7.4.5;The Parallel Master Port;250 7.4.6;Configuring the PMP for LCD Module Control;251 7.4.7;A Small Library of Functions to Access an LCD Display;252 7.4.8;Building an LCD Library and Using the PMP
Library;258 7.4.9;Creating the include and lib Directories;264 7.4.10;Advanced LCD Control;267 7.4.11;Progress Bar Project;268 7.4.12;Debriefing;272 7.4.13;Notes for the PIC24 Experts;272 7.4.14;Tips & Tricks;273 7.4.15;Exercises;273 7.4.16;Books;274 7.4.17;Links;274 7.5;Day 11: It's an Analog World;276 7.5.1;The Plan;276 7.5.2;Preparation;276 7.5.3;The Exploration;276 7.5.4;The First Conversion;280 7.5.5;Automating Sampling Timing;281 7.5.6;Developing a Demo;282 7.5.7;Creating Our Own Mini ADC Library;284 7.5.8;Fun and Games;285 7.5.9;Sensing Temperature;288 7.5.10;Debriefing;293 7.5.11;Notes for the PIC24 Experts;293 7.5.12;Tips & Tricks;294 7.5.13;Exercises;294 7.5.14;Books;295 7.5.15;Links;295 8;Part 3: Expansion;296 8.1;Day 12: Capturing User Inputs;298 8.1.1;The Plan;298 8.1.2;Preparation;298 8.1.3;Buttons and Mechanical Switches;299 8.1.4;Button Input Packing;302 8.1.5;Button Inputs Debouncing;304 8.1.6;Rotary Encoders;307 8.1.7;Interrupt-Driven Rotary Encoder Input;310 8.1.8;Keyboards;315 8.1.9;PS/2 Physical Interface;315 8.1.10;The PS/2 Communication Protocol;316 8.1.11;Interfacing the PIC32 to the PS/2;317 8.1.12;Input Capture;317 8.1.13;Testing Using a Stimulus Scripts;323 8.1.14;The Simulator Profiler;328 8.1.15;Change Notification;329 8.1.16;Evaluating Cost;335 8.1.17;I/O Polling;336 8.1.18;Testing the I/O Polling Method;341 8.1.19;Cost and Efficiency Considerations;344 8.1.20;Keyboard Buffering;346 8.1.21;Key Code Decoding;351 8.1.22;Debriefing;355 8.1.23;Notes for the PIC24 Experts;356 8.1.24;Tips & Tricks;356 8.1.25;Exercises;357 8.1.26;Books;357 8.1.27;Links;358 8.2;Day 13: UTube;360 8.2.1;The Plan;360 8.2.2;Preparation;360 8.2.3;The Exploration;361 8.2.4;Generating the Composite Video Signal;364 8.2.5;The Output Compare Modules;369 8.2.6;Image Buffers;372 8.2.7;Serialization, DMA, and Synchronization;373 8.2.8;Completing a Video Library;380 8.2.9;Testing the Composite Video;384 8.2.10;Measuring Performance;387 8.2.11;Seeing the Dark Screen;387 8.2
.12;Test Pattern;389 8.2.13;Plotting;391 8.2.14;A Starry Night;393 8.2.15;Line Drawing;395 8.2.16;Bresenham Algorithm;397 8.2.17;Plotting Math Functions;400 8.2.18;Two-Dimensional Function Visualization;403 8.2.19;Fractals;408 8.2.20;Text;416 8.2.21;Printing Text on Video;418 8.2.22;Text Test;421 8.2.23;The Matrix Reloaded;422 8.2.24;Debriefing;425 8.2.25;Notes for the PIC24 Experts;426 8.2.26;Tips & Tricks;426 8.2.27;Exercises;428 8.2.28;Books;429 8.2.29;Links;429 8.3;Day 14: Mass Storage;430 8.3.1;The Plan;430 8.3.2;Preparation;430 8.3.3;The Exploration;431 8.3.4;The Physical Interface;432 8.3.5;Interfacing to the Explorer 16 Board;433 8.3.6;Starting a New Project;434 8.3.7;Selecting the SPI Mode of Operation;435 8.3.8;Sending Commands in SPI Mode;435 8.3.9;Completing the SD Card Initialization;438 8.3.10;Reading Data from an SD/MMC Card;440 8.3.11;Writing Data to an SD/MMC Card;443 8.3.12;Testing the SD/MMC Interface;446 8.3.13;Debriefing;451 8.3.14;Tips & Tricks;452 8.3.15;Exercises;453 8.3.16;Books;453 8.3.17;Links;453 8.4;Day 15: File I/O;454 8.4.1;The Plan;454 8.4.2;Preparation;454 8.4.3;The Exploration;455 8.4.4;Sectors and Clusters;455 8.4.5;The File Allocation Table;456 8.4.6;The Root Directory;457 8.4.7;The Treasure Hunt;460 8.4.8;Opening a File;471 8.4.9;Reading Data from a File;481 8.4.10;Closing a File;486 8.4.11;The Fileio Module;487 8.4.12;Testing fopenM ( ) and freadM ( );490 8.4.13;Writing Data to a File;492 8.4.14;Closing a File, Take Two;498 8.4.15;Accessory Functions;500 8.4.16;Testing the Complete Fileio Module;503 8.4.17;Code Size;507 8.4.18;Debriefing;508 8.4.19;Tips & Tricks;508 8.4.20;Exercises;509 8.4.21;Books;509 8.4.22;Links;510 8.5;Day 16: Musica, Maestro!;512 8.5.1;The Plan;512 8.5.2;Preparation;512 8.5.3;The Exploration;513 8.5.4;OC PWM Mode;515 8.5.5;Testing the PWM as a D/A Converter;517 8.5.6;Producing Analog Waveforms;519 8.5.7;Reproducing Voice Messages;524 8.5.8;A Media Player;525 8.5.9;The WAVE File Format;527 8.5.10;The Play (
) Function;528 8.5.11;The Audio Routines;537 8.5.12;A Simple WAVE File Player;540 8.5.13;Debriefing;542 8.5.14;Tips & Tricks;543 8.5.15;Exercises;543 8.5.16;Books;543 8.5.17;Links;544 8.5.18;Disclaimer;544 8.5.19;Final Note for the Experts;544 9;Index;546 9.1;A;546 9.2;B;546 9.3;C;546 9.4;D;547 9.5;E;547 9.6;F;548 9.7;G;548 9.8;H;548 9.9;I;548 9.10;J;549 9.11;K;549 9.12;L;549 9.13;M;550 9.14;N;550 9.15;O;550 9.16;P;551 9.17;Q;551 9.18;R;551 9.19;S;552 9.20;T;553 9.21;U;553 9.22;V;553 9.23;W;553 9.24;X;554 9.25;Z;554