Skip to content Skip to navigation

OpenStax-CNX

You are here: Home » Content » Look Up Tables for MSP430 in C

Navigation

Recently Viewed

This feature requires Javascript to be enabled.
 

Look Up Tables for MSP430 in C

Module by: Trent Kelly. E-mail the author

Summary: Microcontrollers have a limited amount of memory in which variable data can be stored. In some cases, it is necessary to store and access large quantities of data, such as a lookup table, for use within a progam. If this data will not be changed by the program during run time, it can be stored in the read only section of memory.

To locate an array in read only memory rather than in RAM, declare and assign it as a constant.

const int DegFRTD[] = {-500, -40, -39, -38, -37, -36, -35, -34, -33,
-32, -31, -30, -29, -28, -27, -26, -25, -24, -23, -22, -21, -20,
-19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6,
-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132,
133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 
146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158,
159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 
172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184,
185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197,
198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 
211, 212, 999, 999};

const long OhmRTD[] = {0,8427, 8450, 8471, 8493, 8515, 8537, 8559, 8581,
8603, 8625, 8647, 8669, 8691, 8713, 8735, 8757, 8779, 8801, 8822, 8844, 8866,
8888, 8910, 8932, 8954, 8976, 8998, 9019, 9041, 9063, 9085, 9107, 9129, 9151, 
9172, 9194, 9216, 9238, 9260, 9282, 9303, 9325, 9347, 9369, 9391, 9413, 9434, 
9456, 9478, 9500, 9522, 9543, 9565, 9587, 9609, 9630, 9652, 9674, 9696, 9718, 
9739, 9761, 9783, 9805, 9826, 9848, 9870, 9891, 9913, 9935, 9957, 9978, 10000, 
10022, 10043, 10065, 10087, 10109, 10130, 10152, 10174, 10195, 10217, 10239, 
10260, 10282, 10304, 10325, 10347, 10369, 10390, 10412, 10434, 10455, 10477, 
10498, 10520, 10542, 10563, 10585, 10607, 10628, 10650, 10671, 10693, 10715, 
10736, 10758, 10779, 10801, 10822, 10844, 10866, 10887, 10909, 10930, 10952, 
10973, 10995, 11017, 11038, 11060, 11081, 11103, 11124, 11146, 11167, 11189, 
11210, 11232, 11253, 11275, 11296, 11318, 11339, 11361, 11382, 11404, 11425, 
11447, 11468, 11490, 11511, 11533, 11554, 11575, 11597, 11618, 11640, 11661, 
11683, 11704, 11725, 11747, 11768, 11790, 11811, 11833, 11854, 11875, 11897, 
11918, 11940, 11961, 11982, 12004, 12025, 12046, 12068, 12089, 12111, 12132, 
12153, 12175, 12196, 12217, 12239, 12260, 12281, 12303, 12324, 12345, 12367, 
12388, 12409, 12431, 12452, 12473, 12494, 12516, 12537, 12558, 12580, 12601, 
12622, 12643, 12665, 12686, 12707, 12728, 12750, 12771, 12792, 12813, 12835, 
12856, 12877, 12898, 12920, 12941, 12962, 12983, 13005, 13026, 13047, 13068, 
13089, 13111, 13132, 13153, 13174, 13195, 13216, 13238, 13259, 13280, 13301, 
13322, 13343, 13365, 13386, 13407, 13428, 13449, 13470, 13491, 13513, 13534, 
13555, 13576, 13597, 13618, 13639, 13660, 13681, 13702, 13724, 13745, 13766, 
13767, 13808, 13829, 13850, 1000000, 1000000};

Data constants that do not need to be indexed can be stored as a constant, but they can also be defined by a preprocessor directive so that the preprocessor simply substitutes in the number where the name of the constant is used before the code is compiled. The value can be changed in each location it is used by simply changing the preprocessor directive in one place, saving time and reducing errors.

#define pi (3.14159) //preprocessor directive

float circumference;
float diameter;
 

void main (void)
{
circumference = pi*diameter; // The preprocessor translates this into circumference = 3.14159 * diameter;
}

Content actions

Download module as:

Add module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks