Subscribe to EDN
RSS
Reprints/License
Print
Email

Tables ease microcontroller programming

Abel Raynus, Armatron International, Malden, MA; Edited by Martin Rowe and Fran Granville -- EDN, April 22, 2010

PDF

Tables ease microcontroller programming Table 1When creating microcontroller firmware, you often need to work with data arrays. Tables make easy work of data arrays, such as those for digital-code transformation, correction for sensor linearity, sophisticated calculations, and multiple output organization. Table 1 shows how you can organize data in a table. Outputs A, B, and C have values based on the input value, V.


When using a lookup table, choose the proper microcontroller input and outputs. Assign values for input and outputs data in Table 2. These data can consist of constants in binary, hexadecimal, or decimal format or names. For names, you should assign a constant value to each one. For example:

data1 equ $0a

data2 equ $0b

data3 equ $0c

data3 equ $0d

Tables ease microcontroller programming Table 2Next, put the data from Table 2 in either the beginning or the end of ROM, which makes the data easy to find. For definition of 1-byte data storage, use pseudo operators FCB or DB. For storage of data comprising 2 bytes, use FDB or DW, as in the following example:

ORG ROM

VxFCB 0T,2T,4T,6T

AxFCB data1,data2,data3,data4

BxFCB $aa,$bb,$cc,$dd

Cx FDB $1122,$3344,$5566,$7788

Note that commas separate the data. Don’t place a comma after the last data, or it will be considered as $00.

When working with tables, you should always use indexed addressing mode. It provides access to data using variable addresses. Most microcontrollers have two index registers, X and H. Register X contains the low byte of the conditional address of the operand; H contains the high byte. The algorithm of working with tables is straightforward. After you detect the input value, you should then compare it with the table’s input data. The X index determines this value, starting with X=0 and ending with X=N. In this example, N=4. When you find table data equal to the input value, you use the corresponding X as an index to load the output registers with their values. In the case of 2-byte numbers, you should load the output registers separately, first with a high byte and then with a low one. Figure 1 illustrates this process.

In the listing of assembler code, you can double-check the table content in memory at addresses $F800 through $F813. The listing uses Freescale assembler because most of the appropriate applications employ inexpensive, 8-bit microcontrollers from Freescale’s HC08 Nitron family. You can, however, use this approach with any type of microcontroller and assembly language.
RSS
Reprints/License
Print
Email
Canon Resource Center

Featured Company


Most Recent Resources

Advertisement
Related Content

No related content found.

  • 0 rated items found.
Advertisement

KNOWLEDGE CENTER

Datasheets.com Parts Search

185 million searchable parts
(please enter a part number or hit search to begin)
Featured Job On
Scroll for More Jobs
Advertisement
About EDN   |   Site Map   |   Contact Us   |   Subscription   |   RSS
© 2012 UBM Electronics. All rights reserved.
Use of this Web site is subject to its Terms of Use | Privacy Policy

Please visit these other UBM Canon sites

UBM Canon | Design News | Test & Measurement World | Packaging Digest | EDN | Qmed | Pharmalive | Appliance Magazine | Plastics Today | Powder Bulk Solids | Canon Trade Shows