PICkit™ 3 Starter Kit User’s Guide
DS41628B-page 84 2012 Microchip Technology Inc.
3.13 LESSON 12: LOOK-UP TABLE
3.13.1 Intro
It is sometimes useful to implement a table to convert from one value to another.
Expressed in a high-level language it might look like this:
EQUATION 3-6:
That is, for every value of x, the function returns the corresponding y value. Look-up
tables are a fast way to convert an input to meaningful data because the transfer func-
tion is pre-calculated and “looked up”, rather than calculated on the fly. A function that
converts hexadecimal numbers to the ASCII equivalent is one such example.
The great benefit of using a look-up table is that abundant Flash memory is used to
store constant values in lieu of the more limited RAM space. This allows greater flexi-
bility and expands the memory capability of the program.
3.13.2 Hardware Effects
Gray coded binary will be reflected on the LEDs in accordance with the POT reading.
3.13.3 Summary
This lesson shows multiple ways to access program memory. The table simply converts
from regular binary code to the gray code equivalent. Gray codes are frequently used
in encoder applications to avoid wild jumps between states.
Binary encoders are typically implemented an opaque disk sensed by light sensors.
Due to different threshold levels on different bits, bits may change at slightly different
times, yielding momentary invalid results. Gray code prevents invalid transitions,
because only one bit changes from one sequence to the next. The current code is
correct until it transitions to the next.
The algorithm to convert between binary and Gray code is fairly complex. For a small
number of bits, the table look-up is smaller and faster.
3.13.4 New Registers
3.13.4.1 BOTH
The PC addresses bytes in the program memory. Recall that the enhanced PIC16 has
a Program Counter size of 15 bits and the PIC18 has a Program Counter of 21 bits.
The two devices share the offset implementation rather closely still.
3.13.4.1.1 PCL:
The low byte, known as the PCL register, is both readable and writable. The high byte,
or PCH register is not directly readable or writable. Updates to this register are per-
formed through the PCLATH register.
For the PIC18, the PC contains another register called PCU. This register contains the
PIC18’s PC<20:16> bits; it is also not directly readable or writable. Updates to the PCU
register are performed through the PCLATU register.
TABLE 3-38: NEW REGISTERS FOR BOTH DEVICES
Register Purpose
PCL Program Counter (PC) Least Significant Byte
PCLATH Write Buffer for the higher 7 bits of the Program Counter (8 bits for PIC18)