DM164120-1 Microchip Technology, DM164120-1 Datasheet - Page 37

BOARD DEMO PICKIT 2 LP COUNT

DM164120-1

Manufacturer Part Number
DM164120-1
Description
BOARD DEMO PICKIT 2 LP COUNT
Manufacturer
Microchip Technology
Type
MCUr
Datasheet

Specifications of DM164120-1

Contents
3 Boards (1 Populated, 2 Bare)
Processor To Be Evaluated
PIC16F690
Silicon Manufacturer
Microchip
Core Architecture
PIC
Core Sub-architecture
PIC16
Silicon Core Number
PIC16F
Silicon Family Name
PIC16F6xxx
Rohs Compliant
Yes
Lead Free Status / RoHS Status
Lead free / RoHS Compliant
For Use With/related Products
28-pin PIC16C, 16F, 18C, 18F
Lead Free Status / Rohs Status
Lead free / RoHS Compliant

Available stocks

Company
Part Number
Manufacturer
Quantity
Price
Part Number:
DM164120-1
Manufacturer:
Microchip Technology
Quantity:
135
© 2005 Microchip Technology Inc.
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
transfer function is pre-calculated and “looked up” rather than calculated on the fly.
PICmicro MCUs implement these by directly modifying the Program Counter. For
example, a function that converts hexadecimal numbers to the ASCII equivalent. We
can strip out the individual nibble and call the Look-up Table. The index advances the
program counter to the appropriate RETLW instruction to load Wreg with the constant
and returns to the calling program.
EXAMPLE 3-11:
Calling the Look-up Table works most of the time. However, if the table falls across a
256 byte page 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
is only sixteen entries, make sure a number no larger than 16 is passed in. The simplest
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
represented 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 our code. See the PCL and
PCLATH Section in the PIC16F685/687/689/690 Data Sheet (DS41262) for more
details of how PCLATH is used.
FIGURE 3-12:
;Enter with index in Wreg
Look-upTable
y = function(x);
ADDWF
RETLW
RETLW
...
RETLW
Lesson 12: Look-up Table (ROM Array)
PC
PCL,f
'0'
'1'
'F'
12
LOOK-UP TABLE
PC LOADING AS DESTINATION OF INSTRUCTION
5
PCH
PCLATH<4:0>
;jump to
;index 0
;index 1
;index 15
PCLATH
8 7
LPC Demo Board Lessons
PCL
8
0
ALU Result
Instruction with
Destination
PCL as
DS51556A-page 33

Related parts for DM164120-1