DM164120-2 Microchip Technology, DM164120-2 Datasheet - Page 36

BOARD DEMO PICKIT 2 44PIN

DM164120-2

Manufacturer Part Number
DM164120-2
Description
BOARD DEMO PICKIT 2 44PIN
Manufacturer
Microchip Technology
Type
MCUr
Datasheets

Specifications of DM164120-2

Contents
3 Boards (1 Populated, 2 Bare)
Processor To Be Evaluated
PIC16F
Silicon Manufacturer
Microchip
Kit Contents
PIC16F Device, 2 PCB Boards
Features
Small Surface Mount Prototype Area, Two Bare PCB Boards
Development Tool Type
Hardware - Daughter Card
Rohs Compliant
Yes
Lead Free Status / RoHS Status
Lead free / RoHS Compliant
For Use With/related Products
PIC16F887
Lead Free Status / Rohs Status
Lead free / RoHS Compliant

Available stocks

Company
Part Number
Manufacturer
Quantity
Price
Part Number:
DM164120-2
Manufacturer:
Microchip Technology
Quantity:
135
44-Pin Demo Board User’s Guide
DS41296B-page 32
3.2.12
Lesson 8 introduced function calls. Lesson 12 shows how function calls and calculated
modification of the Program Counter may be used to implement a look-up table (see
Example 3-11).
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:
That is for every value of x, it returns the corresponding y value.
Look-up tables are a fast way to convert an input to meaningful data because the trans-
fer function is pre-calculated and “looked up” rather than calculated on the fly.
PIC microcontrollers implement these by directly modifying the Program Counter (PC).
An example might be a function that converts hexadecimal numbers to the ASCII
equivalent. Each digit’s individual nibble can be pulled out of the number and used as
the index to the look-up table. The index advances the PC to the appropriate RETLW
instruction to load WREG with the corresponding constant and returns to the calling
program.
EXAMPLE 3-11:
If the table falls across a 256 byte program memory boundary, or if somehow the
look-up table is called with an out of bounds index value, it will jump to a location out of
the table.
Good programming practices dictate a few additional instructions. First, since the table
has only sixteen entries, make sure a number no larger than 16 is passed in. The sim-
plest way to do this is to logically AND the contents of WREG before modifying PCL:
ANDLW 0x0F. More complex error recovery schemes may be appropriate, depending
on the application.
In addition, there are some nuances to be aware of should the table cross a 256 word
boundary. The Program Counter is 13 bits wide, but only the lower 8 bits are repre-
sented in PCL (see Figure 3-12). The remaining 5 bits are stored in PCLATH. However,
an overflow of the lower 8 bits is not automatically carried over into PCLATH. Instead,
be sure to check for and handle that case in the code. See the PCL and PCLATH
section in the PIC16F882/883/884/886/887 Data Sheet (DS41291) for more details of
how PCLATH is used.
;Enter with index in Wreg
LookupTable
y = function(x);
ADDWF
RETLW
RETLW
...
RETLW
Lesson 12: Look-up Table (ROM Array)
LOOK-UP TABLE
PCL,f
'0'
'1'
'F'
;jump to
;index 0
;index 1
;index 15
© 2007 Microchip Technology Inc.

Related parts for DM164120-2