A Table of Contents

Introduction

Software Choices

Contrary to previous books, this time it wasn’t  possible to write all the code from scratch. We will rely instead on the Microchip Library of Applications. Since this is provided in source code form, we will at least be able to say we read it all…

The first edition of this book is based on the June 2013 release of the MLA. As of February 2014 this has been re-branded by MCHP as the “legacy” release. A new version of the MLA is currently in beta and could not yet be covered in this book.

The book is also making exclusive use of the standard (free) MCHP tool chain, including the MPLAB X IDE and the MPLAB XC compiler suite. All projects in the book can be completed using the free (evaluation) versions of the XC compilers (using optimisation modes 0 and 1 exclusively).

Hardware Choices

While this book covers material and libraries that span across the entire 16-bit and 32-bit microcontrollers spectrum, all the example projects are based on the PIC24 Mikromedia board. Porting to the PIC24EP Mikromedia, PIC32 Mikromedia and PIC32 MIkromedia Plus examples are being offered on this web site.

What this Books is Not

Not an introduction to Embedded Programming in general. Not a primer on C programming. The reader is assumed to be already somewhat familiar with both subjects and is otherwise referred to the previous books: “Programming 16-bit microcontollers in C” and “Programming 32-bit micro controllers in C”.

Familiarity with PIC micro controllers is not strictly required as the libraries used will abstract quickly from the low level architectural details.

This book is also NOT replacing/duplicating device data sheets and/or MLA official documentation.

Chapter 1: Hello World

Getting and installing the right tools in the right places is the main objective of this chapter.

Numerous programming tools options are presented, although the author is strongly recommending the use of the PICKit3 universal In Circuit Programmer and Debugger  (or higher).

Most importantly , this chapter  introduces the basic working directory set up and presents the fundamental “Checklists” for the creation of new projects and new files using the MPLAB X IDE.

The traditional “Hello World” first demo project, often  replaced by a blinking LED in embedded applications, is “originally” performed by flashing the Mikromedia display backlight! This is the beginning of the gradual exploration of all Mikromedia hardware modules and the construction/customization of a small Board Support Package (/uMB).

To tease the readers’ curiosity, a small mystery case is offered at the end of the chapter and a small challenge is offered to the more advanced users.

Chapter 2: Hello MLA

This chapter is the first true encounter with the Microchip Library of Applications. A short introduction provides the basic lay of the land and the reader is invited to look “under the hood” and discover/recognize some of the main building blocks. This is an essential step to avoid that  sense of anxiety that invariably grips the novice as he approaches and briefly glances up what looks like a steep learning curve.

The Graphic Library is the first MLA module to be explored, this exploration will actually continue gradually throughout the rest of book.

The secret is, once more, to get the right tools in the right place, which really means setting up the project structure correctly from the beginning. The steps taken to develop the first MLA demo project (“Hello MLA!”) will be repeated (as a checklist) over and over in the following chapters until they will become second nature.

Two of the most important elements in the configuration of the MLA library for use with the target hardware (Mikromedia board) are introduced in this chapter: the GraphicscConfig and the HardwareProfile.

Various demo projects are developed in this chapter to start experimenting with the graphic primitives, colour and text.

Chapter 3: Graphics Resources

This chapter advances the understanding of the Graphic library by guiding the reader through the exploration of “resources” such as fonts and images.

Learning to use the right tools such as: the Graphic Resource Converter (GRC) and GIMP to package the resources required for an application is important just as understanding the cost (size) of each resource used.

A simple Terminal Emulation module is introduced in this chapter. This will make it easier in many of the examples in the rest of the book to use the TFT graphic display as a convenient tool for testing and occasionally debugging.

Chapter 4: Touch Input

Touch input is de-mystified in this chapter. While exploring the support modules used by MLA to include users touch input, the reader is once more invited to dig deep into the code to identify where and how the library can be adapted to new hardware configurations and how touch can be used without necessarily requiring a full blown graphical user interface but, in some applications, more simply and effectively  just replacing “invisible” buttons.

At the end of the chapter a challenge/project is offered asking  the reader to develop a game of 15 tiles.

Chapter 5: Storage

This chapter covers two important modules of the Mikromedia board: the micro SD card interface and the large (8M-bit) serial flash.

The first is addressed by using the MLA MDD File System module to access (read and write) files on SD cards.

The serial flash module is addressed via as board support module (m25p80).

Several examples are offered to mix and match the capabilities of the two, including: transferring a file from SD card to serial flash, reading an image file from SD card and displaying it on the screen eventually combing the touch input module and the terminal emulation module developed in the previous two chapters.

Several challenges are offered (and solved) stimulating the reader to explore further the possibilities offered by the mass storage modules of the Mikromedia board.

Chapter 6: Sound

This chapter is dedicated entirely to the exploration of an MP3 decoder and audio codec chip (VS1053) that is featured on all the Mikromedia boards and has become a standard of sorts in the embedded world.

A minimal support library is developed and added to the board support package, while examples of combined use with the storage devices/libraries and the touch and graphics modules are offered.

Tools (Audacity) and  techniques (python scripts) are discussed to extract the sound bytes and package them in resources that can be compiled with an application.

Chapter 7: Graphics Object Layer

The graphics object layer or GOL is perhaps the most recognisable part of the MLA. It offers a foundation of graphical user interface elements (widgets) and establishes a simple architecture for the interaction (message passing) among them and with the application.

Getting to use it effectively though would be impossible without a previous solid understanding  of the material presented in the previous chapters as it does require the seamless integration of all previous elements (primitives, images, fonts, storage, touch…)

While there are numerous example projects already included in the MLA distribution, this chapter focuses on the most fundamental building blocks of a GOL applications, those that are often obscured in the standard demo cases buried in the  surrounding application details noise.

The Graphic Display Designer tool ends up stealing much of the show in the second part of the chapter, but once more the discussion is mostly focused on understanding the architecture (looking under the hood)  rather than the how-to detail.

A final example/challenge is offered (and solved) to present the inputs from an Accelerometer using a variety of GUI widgets. This a good opportunity to introduce another Mikromedia support module and to interface to the ADXL345 3D accelerometer device via I2C.

Chapter 8: USB

The Mikromedia USB interface would by itself require an entire book to be properly covered in all its potential applications. The decision was made to focus solely on the two most common classes of applications: the Human Interface Device (HID) and the Communication Interface Class (CDC). Both have the fundamental advantage of NOT requiring drivers installation for the host PC and being readily available on all major operating system.

The HID class is introduced for its absolute simplicity and flexibility which makes it a perfect choice for  bi-directional data transfers and for implementing simple command/response protocols that are very common in embedded control applications. Examples of simple (python) scripts are offered to demonstrate rapid and  cross-platform  desktop application development options.

The CDC class is the preferred choice in “legacy” applications, where an existing desktop application is expecting a serial port connection but modern PC hardware would have none to offer. The code demonstrated in this chapter is focusing on how to use the MLA USB library to make the “porting” seamless by replacing directly calls to a UART with USB libraries that mimic its behaviour with minimal or no disruption to the application logic.

More

To discover more projects that did not make it into the first printed edition of the book continue to the Bonus Projects page.

To download the source code and all required files for the book projects continue to the Download page.

There is no software without bugs and no book without errata. For the most current list continue to the Errata page.