44-Pin Demo Board User’s Guide
3.2.12
Lesson 12: Look-up Table (ROM Array)
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:
y = function(x) ;
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:
LOOK-UP TABLE
;Enter with index in Wreg
LookupTable
ADDWF
RETLW
RETLW
...
RETLW
PCL,f
'0'
'1'
'F'
;jump to
;index 0
;index 1
;index 15
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.
DS41296B-page 32
? 2007 Microchip Technology Inc.
相关PDF资料
DM240011 KIT STARTER MPLAB FOR PIC24F MCU
DM240021 KIT STARTER MPLAB FOR PIC24H
DM240311 BOARD DEV PIC24F16KA102 XLP
DM300018 BOARD DEMO DSPICDEM 2
DM300019 BOARD DEMO DSPICDEM 80L STARTER
DM300024 KIT DEMO DSPICDEM 1.1
DM330012 KIT USB STARTER FOR DSPIC33E
DM330013 MICROSTICK DSPIC33F/PIC24H BOARD
相关代理商/技术参数
DM240002 制造商:Microchip Technology Inc 功能描述:Explorer 16 kit(44-PIN) w/ PIC24FJ64GA00
DM240011 功能描述:开发板和工具包 - PIC / DSPIC MPLAB Starter Kit for PIC24F MCU RoHS:否 制造商:Microchip Technology 产品:Starter Kits 工具用于评估:chipKIT 核心:Uno32 接口类型: 工作电源电压:
DM240012 功能描述:开发板和工具包 - PIC / DSPIC PIC24E USB Starter Kit RoHS:否 制造商:Microchip Technology 产品:Starter Kits 工具用于评估:chipKIT 核心:Uno32 接口类型: 工作电源电压:
DM240013-1 功能描述:开发板和工具包 - PIC / DSPIC Microstick for 3V PIC24F K-series RoHS:否 制造商:Microchip Technology 产品:Starter Kits 工具用于评估:chipKIT 核心:Uno32 接口类型: 工作电源电压:
DM240013-2 功能描述:开发板和工具包 - PIC / DSPIC RoHS:否 制造商:Microchip Technology 产品:Starter Kits 工具用于评估:chipKIT 核心:Uno32 接口类型: 工作电源电压:
DM240014 制造商:Microchip Technology Inc 功能描述:MICROSTICK FOR USB PIC24F - Boxed Product (Development Kits) 制造商:Microchip Technology Inc 功能描述:ACCY MICROSTICK USB PIC24F 制造商:Microchip Technology Inc 功能描述:MICROSTICK USB PIC24F
DM240015 制造商:Microchip Technology Inc 功能描述:MPLAB STARTER KIT FOR PIC24F INTELLIGENT INTEGRATED ANALOG - Boxed Product (Development Kits) 制造商:Microchip Technology Inc 功能描述:KIT MPLAB STARTER FOR PIC24F ANL 制造商:Microchip Technology Inc 功能描述:PIC24F GC INTELLIGENT ANALOG DEV KIT 制造商:Microchip Technology Inc 功能描述:PIC24F, GC INTELLIGENT ANALOG, DEV KIT 制造商:Microchip Technology Inc 功能描述:Starter Kit for PIC24F Intelligent Integrated Analog Series 制造商:Microchip Technology Inc 功能描述:Development Boards & Kits - PIC / DSPIC 制造商:Microchip Technology Inc 功能描述:PIC24F, GC INTELLIGENT ANALOG, DEV KIT, Silicon Manufacturer:Microchip, Core Arc 制造商:Microchip Technology Inc 功能描述:PIC24F, GC INTELLIGENT ANALOG, DEV KIT, Silicon Manufacturer:Microchip, Core Architecture:PIC, Core Sub-Architecture:PIC24, Silicon Core Number:PIC24FJ128GC010, Silicon Family Name:PIC24FJxxxGCxxx, Kit Contents:Starter Board 制造商:Microchip Technology Inc 功能描述:MPLAB Starter Kit for PIC24F Intelligent Integrated Analog, Starter Kits
DM240021 功能描述:开发板和工具包 - PIC / DSPIC MPLAB STARTER KIT FOR PIC24H RoHS:否 制造商:Microchip Technology 产品:Starter Kits 工具用于评估:chipKIT 核心:Uno32 接口类型: 工作电源电压: