Example code from the textbook

This page gives example PIC24 code accompanying the textbook titled "Microcontrollers: From Assembly to C with the PIC24 Family" by R. Reese, B. Jones and J.W. Bruce to be published by Cengage Learning in December 2008.

The next section discussing using the example code, while the example directory lists all available examples.

Using the example code

First, make sure you've read the getting started guide, insuring that your hardware and software are correctly configured.

You can place this directory anywhere that you wish; the project files use relative path names.

Documentation starts at docs/index.html. These examples have minimal reliance on the libraries shipped with the PIC24 compiler, and instead use libraries that have been developed by the authors. The new libraries are meant to be more friendly to programmers who are new to the PIC24 Family, as this material and code examples are used in an introductory microprocessors class at Mississippi State University.

Most of the examples are meant for a reference PIC24HJ32GP202 system (some examples in Chapter 13 use the PIC24HJ64GP502, which is pin compatible with the PIC24HJ32GP202 but has additional on-chip peripherals). The projects all have a custom linker file intended for use with a serial bootloader - if you want generated hex files to be compatible with the PICKIT2 programmer then delete the linker file from the MPLAB project. The MPLAB project files do not have workspace files associated with them - this means that double-clicking on a MPLAB project file opens a blank workspace, and you do not see the project files. Instead of double-clicking on a project file, start MPLAB manually, and use 'Project->Open' to open one of the example projects. This creates a new workspace for that project, which you can save when you close the project.

If you have a different PIC24 Family member, simply change the target device in the MPLAB to that device. When you compile the files, you will get warnings that the internal oscillator with PLL is being used, and that the default configuration bit settings are being used.

To change clock options, see the documentation on common/pic24_clockfreq.c and include/pic24_clockfreq.h. To change config bits, see the documentation on common/pic24_configbits.c

All of the examples assume a serial port using UART1; our reference system uses pins RP10 (RX) and RP11 (TX) with a default baudRate of 57600. To change these assignments, edit the function called configUART1() in common/pic24_uart.c. To change the default baudrate, edit the #define DEFAULT_BAUDRATE in include/pic24_libconfig.h (The file include/pic24_libconfig.h includes all of the macros for configuring user-defineable behavior for library functions).

If the end-of-line (EOL) output behavior is not correct for the serial terminal program that you are using (i.e, printed new lines do not return to the left edge of the screen), then you can change this by selecting an appropriate value for the SERIAL_EOL_DEFAULT macro contained in include/pic24_libconfig.h. The three choices are SERIAL_EOL_CR_LF, SERIAL_EOL_CR, or SERIAL_EOL_LF. By default, the library uses SERIAL_EOL_LF (an EOL is a LF only).

Our examples also assume an LED tied to port RB15 - this is used as a 'heartbeat' and is blinked by our examples when waiting for input. You can reassign this to another port (see HB_LED) or remove it entirely (see USE_HEARTBEAT) by editing pic24_libconfig.h.

The best project to start with is chap8/reset.mcp - this just assumes serial port functionality. Chapter 8 examples are parallel port I/O, while Chapter 9 gives some interrupt examples. See the following listing for descriptions of individual code examples.

Example code directory

Example code includes:

Examples converted to be compatible with the Explorer-16, 100-pin demo board

Other examples not tied to textbook Figures:


Generated on Sun Mar 15 11:14:22 2009 for PIC24 Support Libraries by  doxygen 1.5.8