Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
46 Chapter 3 Notes for the PIC ® Microcontroller Experts Depending on the target microcontroller architecture, and ultimately the arithmetic logic unit (ALU), operating on bytes versus operating on word quantities can make a big difference in terms of code compactness and efficiency. While in the PIC16 and PIC18 8-bit architectures there is a strong incentive to use byte-sized integers wherever possible, in the PIC24 16-bit architecture word-sized integers can be manipulated just with the same efficiency. The only limiting factor preventing us from always using 16-bit integers with the MPLAB C compiler is the consideration of the relative preciousness of the internal resources of the microcontroller, in this case the RAM memory. Notes for the C Experts Even if PIC24 microcontrollers have a relatively large RAM memory array, embedded control applications will always have to contend with the reality of cost and size limitations. If you learned to program in C on a PC or a workstation, you probably never considered using anything smaller than an int as a loop index. Well, this is the time to think again. Shaving one byte at a time off the requirements of your application might, in some cases, mean the ability to select a smaller model of PIC24 microcontroller, saving fractions of a dollar that, when multiplied by the thousands or millions of units (depending on your production run rates), can mean real money saved from the bottom line. In other words, if you learn to keep the size of your variables to the strict minimum necessary, you will become a better embedded-control designer and ultimately this is what engineering is all about. Tips & Tricks In this last exercise we declared an array called bitmap[] and we asked for it to be prefilled with a specific series of values. The array, being a data structure, resides in RAM during execution. But since RAM is volatile, the compiler has to make sure that the right values (assigned with the curly brackets {} notation) are copied from a non-volatile memory namely a table in FLASH memory. As mentioned already in both previous chapters, this is the kind of task that the crt0 code is meant to do for us. The compiler and linker will take complete care of it though. You won't have to move a finger. Expect more on this in the coming chapters as we will learn how and when to optimize RAM usage, a precious resource in all embedded control applications. Notes for PIC24 GA1 and GB1 Users For those among you who have planned on using the newer GA1, GB1 and later families of PIC24F devices, there is an important enhancement to the I/O system that will require a little additional study: the Peripheral Pin Select or PPS. This feature was designed to allow a much increased flexibility in the allocation of pins for devices that are particularly rich in