ARM Technical Support Knowledge Articles


Applies to: C51 C Compiler


Information in this article applies to:


I have written the following example lookup table:

#define OSC 1333333

unsigned long testar [] = { OSC / 3, OSC / 4, OSC / 5, OSC / 6 };

and I wish to double-check that the look-up table values are the same as the values I have calculated manually. Is there an easy way to do this?


Yes. If you move the table declaration into a seperate source file then you can add some test code which, when built automatically, checks the values in the look-up table. This can be run in the debugger where it will display any values that are incorrect according to your manual calculations.

For large look-up tables this can easily be extended to use an array of manually calculated values.

You may #define a DEBUG macro that controls whether or not the test code is compiled. For example:

#define DEBUG 1  /*** Undef this for REAL code ***/

#define OSC 1333333

unsigned long testar [] = { OSC / 3, OSC / 4, OSC / 5, OSC / 6 };

#include <stdio.h>
#include <reg52.h>

#define assert(expr)   if (expr)                                                 
                         printf("Assert failed: " #expr " (file %s line %d)
                         __FILE__, (int) __LINE__ );                             

void main (void)
  SCON  = 0x50;
  TMOD |= 0x20;
  TH1   = 221;
  TR1   = 1;
  TI    = 1;

  assert(testar[0] == 444444);
  assert(testar[1] == 335333);
  assert(testar[2] == 266666);
  assert(testar[3] == 222222);

  while (1);



Article last edited on: 2006-10-24 12:43:13

Rate this article

Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential