Zum Hauptinhalt springen
Nicht aus der Schweiz? Besuchen Sie lehmanns.de
Programming 32-bit Microcontrollers in C -  Lucio Di Jasio

Programming 32-bit Microcontrollers in C (eBook)

Exploring the PIC32
eBook Download: EPUB
2011 | 1. Auflage
552 Seiten
Elsevier Science (Verlag)
978-0-08-056010-6 (ISBN)
Systemvoraussetzungen
51,92 inkl. MwSt
(CHF 49,95)
Der eBook-Verkauf erfolgt durch die Lehmanns Media GmbH (Berlin) zum Preis in Euro inkl. MwSt.
  • Download sofort lieferbar
  • Zahlungsarten anzeigen
"*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."
*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.

Front Cover 1
Programming 32-bit Microcontrollers in C: Exploring the PIC32 4
Copyright Page 5
Contents 10
Introduction 20
Part 1: Exploring 28
Day 1: The Adventure Begins 30
The Plan 30
Preparation 30
The Adventure Begins 33
Compiling and Linking 35
The Linker Script 37
Building the First Project 38
Using the Simulator 39
Finding a Direction 41
The JTAG Port 43
Testing PORTB 44
Mission Debriefing 46
Notes for the Assembly Experts 47
Notes for the PIC MCU Experts 49
Notes for the C Experts 49
Tips & Tricks
Exercises 50
Books 51
Links 51
Day 2: Walking in Circles 52
The Plan 52
Preparation 52
The Exploration 54
While Loops 55
An Animated Simulation 58
Using the Logic Analyzer 62
Debriefing 64
Notes for the Assembly Experts 65
Notes for the 8-Bit PIC Microcontroller Experts 65
Notes for the 16-Bit PIC Microcontroller Experts 65
Notes for the C Experts 66
Notes for the MIPS Experts 66
Tips & Tricks
Notes on Using the Peripheral Libraries 67
Exercises 69
Books 69
Links 69
Day 3: Message in a Bottle 70
The Plan 70
Preparation 70
The Exploration 70
Do Loops 71
Variable Declarations 72
for Loops 74
More Loop Examples 75
Arrays 76
Sending a Message 77
Testing with the Logic Analyzer 80
Testing with the Explorer 16 Demonstration Board 81
Testing with the PIC32 Starter Kit 82
Debriefing 84
Notes for the Assembly Experts 84
Notes for the PIC Microcontroller Experts 85
Notes for the C Experts 85
Tips & Tricks
Exercises 87
Books 87
Links 87
Day 4: NUMB3RS 88
The Plan 88
Preparation 88
The Exploration 88
On Optimizations (or Lack Thereof) 91
Testing 91
Going long long 92
Integer Divisions 94
Floating Point 96
Measuring Performance 97
Debriefing 100
Notes for the Assembly Experts 100
Notes for the 8-Bit PIC® Microcontroller Experts 102
Notes for the 16-Bit PIC and dsPIC® Microcontroller Experts 103
Tips & Tricks
Exercises 105
Books 106
Links 106
Day 5: Interrupts 108
The Plan 108
Preparation 108
The Exploration 108
Interrupts and Exceptions 109
Sources of Interrupt 111
Interrupt Priorities 112
Interrupt Handlers Declaration 115
The Interrupt Management Library 117
Single Vector Interrupt Management 117
Managing Multiple Interrupts 122
Multivectored Interrupt Management 125
A Simple Application 130
The Secondary Oscillator 135
The Real-Time Clock Calendar (RTCC) 136
Debriefing 138
Notes for the PIC Microcontroller Experts 138
Tips & Tricks
Exercises 140
Books 140
Links 140
Day 6: Memory 142
The Plan 142
Preparation 142
The Exploration 143
Memory Space Allocation 145
Looking at the MAP 150
Pointers 154
The Heap 155
The PIC32MX Bus 156
PIC32MX Memory Mapping 157
The Embedded-Control Memory Map 161
Debriefing 162
Notes for the C Experts 162
Notes for the Assembly Experts 163
Notes for the PIC Microcontroller Experts 163
Tips & Tricks
Exercises 164
Books 165
Links 165
Part 2: Experimenting 166
Day 7: Running 168
The Plan 168
Preparation 168
The Exploration 169
Performance vs. Power Consumption 171
The Primary Oscillator Clock Chain 173
The Peripheral Bus Clock 174
Initial Device Configuration 175
Setting Configuration Bits in Code 177
Heavy Stuff 179
Ready, Set, Go! 185
Fine-Tuning the PIC32: Configuring Flash Wait States 187
Fine-Tuning the PIC32: Enabling the Instruction and Data Cache 190
Fine-Tuning the PIC32: Enabling the Instruction Pre-Fetch 191
Fine-Tuning the PIC32: Final Notes 192
Debriefing 194
Notes for the Assembly Experts 194
Notes for the PIC® Microcontroller Experts 194
Tips & Tricks
Exercises 198
Books 198
Links 198
Day 8: Communication 200
The Plan 200
Preparation 200
The Exploration 201
Synchronous Serial Interfaces 201
Asynchronous Serial Interfaces 203
Parallel Interfaces 204
Synchronous Communication Using the SPI Modules 205
Testing the Read Status Register Command 209
Writing Data to the EEPROM 213
Reading the Memory Contents 214
A 32-bit Serial EEPROM Library 214
Testing the New SEE Library 218
Debriefing 220
Notes for the C Experts 220
Notes for the Explorer 16 Experts 220
Notes for the PIC24 Experts 221
Tips & Tricks
Exercises 222
Books 223
Links 223
Day 9: Asynchronous Communication 224
The Plan 224
Preparation 224
The Exploration 224
UART Configuration 227
Sending and Receiving Data 229
Testing the Serial Communication Routines 231
Building a Simple Console Library 233
Testing a VT100 Terminal 236
The Serial Port as a Debugging Tool 238
The Matrix Project 238
Debriefing 241
Notes for the C Experts 241
Notes for the PIC® Microcontroller Experts 242
Tips & Tricks
Exercises 243
Books 243
Links 244
Day 10: Glass = Bliss 246
The Plan 246
Preparation 246
The Exploration 246
HD44780 Controller Compatibility 248
The Parallel Master Port 250
Configuring the PMP for LCD Module Control 251
A Small Library of Functions to Access an LCD Display 252
Building an LCD Library and Using the PMP Library 258
Creating the include and lib Directories 264
Advanced LCD Control 267
Progress Bar Project 268
Debriefing 272
Notes for the PIC24 Experts 272
Tips & Tricks
Exercises 273
Books 274
Links 274
Day 11: It's an Analog World 276
The Plan 276
Preparation 276
The Exploration 276
The First Conversion 280
Automating Sampling Timing 281
Developing a Demo 282
Creating Our Own Mini ADC Library 284
Fun and Games 285
Sensing Temperature 288
Debriefing 293
Notes for the PIC24 Experts 293
Tips & Tricks
Exercises 294
Books 295
Links 295
Part 3: Expansion 296
Day 12: Capturing User Inputs 298
The Plan 298
Preparation 298
Buttons and Mechanical Switches 299
Button Input Packing 302
Button Inputs Debouncing 304
Rotary Encoders 307
Interrupt-Driven Rotary Encoder Input 310
Keyboards 315
PS/2 Physical Interface 315
The PS/2 Communication Protocol 316
Interfacing the PIC32 to the PS/2 317
Input Capture 317
Testing Using a Stimulus Scripts 323
The Simulator Profiler 328
Change Notification 329
Evaluating Cost 335
I/O Polling 336
Testing the I/O Polling Method 341
Cost and Efficiency Considerations 344
Keyboard Buffering 346
Key Code Decoding 351
Debriefing 355
Notes for the PIC24 Experts 356
Tips & Tricks
Exercises 357
Books 357
Links 358
Day 13: UTube 360
The Plan 360
Preparation 360
The Exploration 361
Generating the Composite Video Signal 364
The Output Compare Modules 369
Image Buffers 372
Serialization, DMA, and Synchronization 373
Completing a Video Library 380
Testing the Composite Video 384
Measuring Performance 387
Seeing the Dark Screen 387
Test Pattern 389
Plotting 391
A Starry Night 393
Line Drawing 395
Bresenham Algorithm 397
Plotting Math Functions 400
Two-Dimensional Function Visualization 403
Fractals 408
Text 416
Printing Text on Video 418
Text Test 421
The Matrix Reloaded 422
Debriefing 425
Notes for the PIC24 Experts 426
Tips & Tricks
Exercises 428
Books 429
Links 429
Day 14: Mass Storage 430
The Plan 430
Preparation 430
The Exploration 431
The Physical Interface 432
Interfacing to the Explorer 16 Board 433
Starting a New Project 434
Selecting the SPI Mode of Operation 435
Sending Commands in SPI Mode 435
Completing the SD Card Initialization 438
Reading Data from an SD/MMC Card 440
Writing Data to an SD/MMC Card 443
Testing the SD/MMC Interface 446
Debriefing 451
Tips & Tricks
Exercises 453
Books 453
Links 453
Day 15: File I/O 454
The Plan 454
Preparation 454
The Exploration 455
Sectors and Clusters 455
The File Allocation Table 456
The Root Directory 457
The Treasure Hunt 460
Opening a File 471
Reading Data from a File 481
Closing a File 486
The Fileio Module 487
Testing fopenM ( ) and freadM ( ) 490
Writing Data to a File 492
Closing a File, Take Two 498
Accessory Functions 500
Testing the Complete Fileio Module 503
Code Size 507
Debriefing 508
Tips & Tricks
Exercises 509
Books 509
Links 510
Day 16: Musica, Maestro! 512
The Plan 512
Preparation 512
The Exploration 513
OC PWM Mode 515
Testing the PWM as a D/A Converter 517
Producing Analog Waveforms 519
Reproducing Voice Messages 524
A Media Player 525
The WAVE File Format 527
The Play ( ) Function 528
The Audio Routines 537
A Simple WAVE File Player 540
Debriefing 542
Tips & Tricks
Exercises 543
Books 543
Links 544
Disclaimer 544
Final Note for the Experts 544
Index 546
A 546
B 546
C 546
D 547
E 547
F 548
G 548
H 548
I 548
J 549
K 549
L 549
M 550
N 550
O 550
P 551
Q 551
R 551
S 552
T 553
U 553
V 553
W 553
X 554
Z 554

Introduction

The first step in almost every rehabilitation program is A- Acknowledge … your limitations. So this is how I need to start this book, I will admit it: I am 8-bitter!

I have been programming 8-bit microcontrollers since I was in high school and for most of my professional career. And there is worse, while I am relatively fluent in several high level programming languages, I truly love assembly programming!

There, I said it! I love that kick that I get when I know I used every single machine cycle in every microsecond my embedded applications run. I am also obsessed with control: I like to know of every configuration bit in every peripheral I use. As a consequence, in general, I don’t trust compilers or other people’s libraries unless I really cannot live without them or I have them completely disassembled.

So why would I write a book about 32-bit programming in C?

In fact I started what I should call my “rehabilitation program” a couple of years ago by approaching the programming of 16-bit microcontrollers first. The introduction of the PIC24 family of microcontrollers gave me the motivation to try and migrate to C programming with a new and exciting architecture. As a result of my experience, I wrote the first book: “Programming 16-bit microcontrollers in C. Learning to fly the PIC24”. But by the time the book was published, rumors circulated in Microchip that a new 32-bit chip had just come out of the “ovens” and I had to have one!

I’ll spare you the details of how I got my hands around one of the very first test chips, but what you need to know is that in a matter of days I had most of the code, originally developed for the PIC24 book, ported and running on the PIC32 plugged in my old Explorer16 board.

Microchip marketing folks will tell you that the PIC32 architecture was specifically designed so to make the “migration” from 8-bit and 16-bit PIC architectures smooth and seamless, but I had to see it with my eyes to believe it.

So who better than an assembly-loving, control-obsessed, 8-bitter can tell you about the exploration of the PIC32?

Who Should Read this Book?


The PIC32 turns out to be a remarkably easy to use device, but nonetheless, it is a truly powerful machine based on a well established 32-bit core (MIPS) and supported by a large number of tools, libraries and documentation. This book can only offer you a small glimpse into such a vast world and in fact I call it a first “exploration”. It is my strong belief that learning should be fun, and I hope you will have a good time with some of the “playful” exercises and projects I present throughout each chapter in the book. However you will need quite some preparation and hard work in order to be able to digest the material I am presenting at a pace that will accelerate rapidly through the first few chapters.

This book is meant for programmers of a basic to intermediate level of experience, but not for “absolute” beginners; so don’t expect me to start with the basics of the binary numbers, the hexadecimal notation or the fundamentals of programming. Although, we will briefly review the basics of C programming as it relates to the applications for the latest generation of general-purpose 32-bit microcontrollers, before moving on to more challenging projects. My assumption is that you, the reader, belong to one of the following four categories:

• Embedded Control programmer: experienced in assembly-language microcontrollers programming, but with only a basic understanding of the C language.
• PIC® microcontroller expert: with a basic understanding of the C language.
• Student or professional: with some knowledge of C (or C ++) programming for PCs.
• Other SLF (superior life forms): I know programmers don’t like to be classified that easily so I created this special category just for you!

Depending on your level and type of experience, you should be able to find something of interest in every chapter. I worked hard to make sure that every one of them contained both C programming techniques and new hardware peripherals details. Should you already be familiar with both, feel free to skip to the experts section at the end of the chapter, or consider the additional exercises, book references and links for further research/reading.

A special note is reserved for those of you who have already read my previous book on programming 16-bit microcontrollers in C. First of all let me thank you, then let me explain why you will get a certain sensation of deja vu. No, I did not try to cheat my way through the old 16-bit material to produce a new book, but I have re-produced most of the projects to demonstrate practically the main claims of the PIC32 architecture and toolset: its seamless migration from 8 and 16-bit PIC applications, the vastly increased performance and nonetheless the great ease of use. For you, at the end of every chapter, I have included a special section where I detail the differences encountered, the enhancements and other information that will help you port your applications faster and with greater confidence.

These are some of the things you will learn:

• The structure of an embedded-control C program: loops, loops and more loops
• Basic timing and I/O operations
• Basic embedded control multitasking in C, using the PIC32 interrupts
• New PIC32 peripherals, in no specific order:
1. Input Capture
2. Output Compare
3. Change Notification
4. Parallel Master Port
5. Asynchronous Serial Communication
6. Synchronous Serial Communication
7. Analog-to-Digital conversion
• How to control LCD displays
• How to generate video signals
• How to generate audio signals
• How to access mass-storage media
• How to share files on a mass-storage device with a PC

Structure of the Book


Each chapter of the book is offered as a day of exploration in the 32-bit embedded programming world. There are three parts. The first part contains six small chapters of increasing levels of complexity. In each chapter, we will review one basic hardware peripheral of the PIC32MX family of microcontrollers and one aspect of the C language, using the MPLAB C32 compiler (Student Version included in the CD-ROM). In each chapter, we will develop at least one demonstration project. Initially, such projects will require exclusive use of the MPLAB SIM software simulator (a part of the MPLAB toolsuite included in the CD-ROM), and no actual hardware will be necessary; although, an Explorer 16 demonstration board or a PIC32 Starter kit might be used.

In the second part of the book, titled “Experimenting” and containing five more chapters, an Explorer 16 demonstration board (or third-party equivalent) will become more critical, as some of the peripherals used will require real hardware to be properly tested.

In the third part of the book, titled “Expansion”, there are five larger chapters. Each one of them builds on the lessons learned in multiple previous chapters while adding new peripherals to develop projects of greater complexity. The projects in the third part of the book require the use of the Explorer 16 demonstration board and basic prototyping skills too (yes, you might need to use a soldering iron). If you don’t want to or you don’t have access to basic PCB prototyping tools, an ad hoc expansion board (AV32) containing all the circuitry and components necessary to complete all the demonstration projects will be made available on the companion web site: http://www.exploringpic32.com

All the source code developed in each chapter is also available for immediate use on the companion CD-ROM.

What this Book is Not


This book is not a replacement for the PIC32 datasheet, reference manual and programmer’s manual published by Microchip Technology. It is also not a replacement for the MPLAB C32 compiler user’s guide, and all the libraries and related software tools offered by Microchip. Copies are available on the companion CD-ROM, but I expect you to download the most recent versions of all those documents and tools from Microchip’s Web site (http://www.microchip.com). Familiarize yourself with them and keep them handy. I will often refer to them throughout the book, and I might present small block diagrams and other excerpts here and there as necessary. But, my narration cannot replace the information presented in the official manuals. Should you notice a conflict between my narration and the official documentation, ALWAYS refer to the latter. However please send me an email if a conflict arises, I will appreciate your help and I will publish any correction and useful hint I will receive on the companion web site: http://www.exploringpic32.com

This book is also not a primer on the C language. Although a review of the language is performed throughout the first few chapters, the reader will find in the references several suggestions on more complete introductory courses and books on the subject.

Checklists


Although this book is not directly making references to aviation and flight training as my previous book was, I decided to maintain some important elements introduced...

Erscheint lt. Verlag 8.4.2011
Sprache englisch
Themenwelt Mathematik / Informatik Informatik
Technik Elektrotechnik / Energietechnik
ISBN-10 0-08-056010-5 / 0080560105
ISBN-13 978-0-08-056010-6 / 9780080560106
Informationen gemäß Produktsicherheitsverordnung (GPSR)
Haben Sie eine Frage zum Produkt?
EPUBEPUB (Adobe DRM)

Kopierschutz: Adobe-DRM
Adobe-DRM ist ein Kopierschutz, der das eBook vor Mißbrauch schützen soll. Dabei wird das eBook bereits beim Download auf Ihre persönliche Adobe-ID autorisiert. Lesen können Sie das eBook dann nur auf den Geräten, welche ebenfalls auf Ihre Adobe-ID registriert sind.
Details zum Adobe-DRM

Dateiformat: EPUB (Electronic Publication)
EPUB ist ein offener Standard für eBooks und eignet sich besonders zur Darstellung von Belle­tristik und Sach­büchern. Der Fließ­text wird dynamisch an die Display- und Schrift­größe ange­passt. Auch für mobile Lese­geräte ist EPUB daher gut geeignet.

Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen eine Adobe-ID und die Software Adobe Digital Editions (kostenlos). Von der Benutzung der OverDrive Media Console raten wir Ihnen ab. Erfahrungsgemäß treten hier gehäuft Probleme mit dem Adobe DRM auf.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen eine Adobe-ID sowie eine kostenlose App.
Geräteliste und zusätzliche Hinweise

Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.

Mehr entdecken
aus dem Bereich

von Herbert Voß

eBook Download (2025)
Lehmanns Media (Verlag)
CHF 19,50