|
| ( 01 Jul 2010 ) |
| Abel Raynus, Armatron International, Malden, Massachusetts |
|
When 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
Next, 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.
Caption
|
| |
|
|
|
|
| |
|
|
Average Rate:
No rating yet |
| |
| |
|
|
|
|
| |
|
|
| |
|
|
| 1/2/2012 |
|
| 1/2/2012 |
|
| 1/2/2012 |
|
| |
|
|
|
|
|
|
|
| |
|
| |
|
| 1/2/2012 |
|
| 31/1/2012 |
|
| 18/1/2012 |
|
| |
|
|
|
|
|