Programming 32-bit Microcontrollers in C
eBook - ePub

Programming 32-bit Microcontrollers in C

Exploring the PIC32

Lucio Di Jasio

Share book
  1. 552 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Programming 32-bit Microcontrollers in C

Exploring the PIC32

Lucio Di Jasio

Book details
Book preview
Table of contents
Citations

About This Book

*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.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on ā€œCancel Subscriptionā€ - itā€™s as simple as that. After you cancel, your membership will stay active for the remainder of the time youā€™ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlegoā€™s features. The only differences are the price and subscription period: With the annual plan youā€™ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, weā€™ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Programming 32-bit Microcontrollers in C an online PDF/ePUB?
Yes, you can access Programming 32-bit Microcontrollers in C by Lucio Di Jasio in PDF and/or ePUB format, as well as other popular books in Technology & Engineering & Microelectronics. We have over one million books available in our catalogue for you to explore.

Information

Part I
Exploring
Day 1 The Adventure Begins

The Plan

This will be our first experience with the PIC32 32-bit microcontroller and, for some of you, the first project with the MPLABĀ® IDE Integrated Development Environment and the MPLAB C32 language suite. Even if you have never heard of the C language, you might have heard of the famous ā€œHello World!ā€ programming example. If not, let me tell you about it.
Since the very first book on the C language, written by Kernighan and Ritchie several decades ago, every decent C language book has featured an example program containing a single statement to display the words ā€œHello Worldā€ on the computer screen. Hundreds, if not thousands, of books have respected this tradition, and I donā€™t want my books to be the exception. However, our example will be just a little different. Letā€™s be realisticā€”we are talking about programming microcontrollers because we want to design embedded-control applications. Though the availability of a monitor screen is a perfectly safe assumption for any personal computer or workstation, this is definitely not the case in the embedded-control world. For our first embedded application weā€™d better stick to a more basic type of output: a digital I/O pin. In a later and more advanced chapter, we will be able to interface to an LCD display and/or a terminal connected to a serial port. But by then we will have better things to do than writing ā€œHello World!ā€

Preparation

Whether you are planning a small outdoor trip or a major expedition to the Arctic, youā€™d better make sure you have the right equipment with you. Our exploration of the PIC32 architecture is definitely not going to be a matter of life or death, but you will appreciate the convenience of following the few simple steps outlined here before getting your foot out the door ā€¦ ahem, I mean before starting to type the first few lines of code.
So, letā€™s start by verifying that we have all the necessary pieces of equipment ready and installed (from the attached CD-ROM and/or the latest version available for download from Microchipā€™s PIC32 Web site at www.microchip.com/PIC32). You will need the following:
ā€¢ MPLAB IDE, free Integrated Development Environment (v8.xx or later)
ā€¢ MPLAB SIM, free software simulator (included in MPLAB)
ā€¢ MPLAB C32, C compiler (free Student Edition)
Now letā€™s use the New Project Setup checklist to create a new project with the MPLAB IDE. From the Project menu, select the Project Wizard. This will bring up a short but useful sequence of little dialog boxes that will guide us through the few steps required to create a new project in an orderly and clean way:
1. The first dialog box will ask you to choose a specific device model. Select the PIC32MX360F512L device and click Next. Although we will use only the simulator, and for the purpose of this project we could use pretty much any PIC32 model, we will stick to this particular part number throughout our exploration.
2. In the second dialog box, select the PIC32 C-Compiler Tool Suite and click Next. Many other tool suites are available for all the other PICĀ© architectures, and at least one other tool suite is already available for development on the PIC32 in assembly; donā€™t mix them up!
3. In the third dialog box, you are asked to assign a name to the new project file. Instead click the Browse button and create a new folder. Name the new folder Hello, and inside it create the project file Hello World, then click Next.
4. In the fourth dialog box, simply click Next to proceed to the following dialog box since there is no need to copy any source files from any previous projects or directories.
5. Click Finish to complete the project setup.
Since this is our first time, letā€™s continue with the following additional steps:
6. Open a new editor window by selecting File | New, typing the Ctrl + Ī keyboard
shortcut or by clicking the corresponding
image
(New File) button in the MPLAB standard toolbar.
7. Type the following three comment lines:
image
8. Select File | Save As to save the file as Hello.c.
9. Now right-click with your mouse on the editor window to bring up the editorā€™s context menu and select the Add To Project item. This will tell MPLAB that the newly created file is an integral part of the project.
10. Select Project | Save Project to save the project.
Note
You will notice that, after saving the file, the color of the three lines of text in the editor window changes to green. This is because the MPLAB Editor has been able to recognize your file as a C language source file (the .c extension tipped it off) and is now applying the default context-sensitive color rules. According to theses rules, green is the color assigned to comments, blue is the color assigned to language keywords, and black is used for all the remaining code.
Once you are finished, your project window should look like the one in Figure 1.1. If you cannot see the project window, select View | Project. A small check mark should appear next to the item in the View menu. Also make sure that the Files tab is selected. We will review the use of the other tab (Symbols) in a later chapter.
image
Figure 1.1 The ā€œHello Worldā€ Project window.
Depending on your personal preferences, you might now want to ā€œdockā€ this window to assign it a specific place on your workspace rather than keeping it floating. You can do so by right-clicking with your mouse on the title bar of the small window to access the context menu and selecting the Dockable option. You can then drag it to the desired edge of the screen, where it will stick and split the available space with the editor.

The Adventure Begins

It is time to start writing some code. I can sense your trepidation, especially if you have never written any C code for an embedded-control application before. Our first line of code is:
image
This is not yet a proper C statement but an instruction for the preprocessor (which feeds the compiler) with the request to include the content of a device-specific file before proceeding any further. The pic32xxxx.h file, in its turn, contains more #include instructions designed so that the file relative to the device currently selected in the project is included. That file in our case is p32mx360f5121.h. We could have used its name directly, but we chose not to in order to make the code more independent and hopefully easier to port, in the future, to new projects using different models.
If you decide to further inspect the contents of the p32mx360f5121.h file (it is a simple text file that you can open with the MPLAB editor), you will see that it contains an incredibly long list of definitions for all the names of the internal special-function registers (often referred to in the documentation as the SFRs) of the chosen PIC32 model. If the include file is accurate, those names reflect exactly those being used in the device datasheet a...

Table of contents