ARM Technical Support Knowledge Articles

ENUM EXAMPLES

Applies to: C51 C Compiler

Answer

QUESTION

I tried to use the Enumeration type in C51, but it did not work. Can you give me an example that works?

ANSWER

The following enumeration example shows you how to use the enumeration type in C51. You can copy and paste this into a source file, compile it, link it, and run it with dScope to watch it run.

enum link_state {LINK_RESET, LINKING, LINKED, LINK_STATE_MAX};

void link_handler(
  enum link_state ls)
{
   unsigned char  uc_temp1;
   switch(ls)
   {
      /**** LINK_RESET State *******/
      case( LINK_RESET ):
         uc_temp1 = 1;
         break;
      /**** LINKING State**********/
      case( LINKING ):
         uc_temp1 = 2;
         break;

      /**** LINKED State ****************/
      case( LINKED ):
         uc_temp1 = 3;
         break;
   }
}


void main (void)
{
unsigned char i;

for (i = LINK_RESET; i < LINK_STATE_MAX; i++)
  link_handler (i);

while (1);
}

Article last edited on: 2004-05-10 21:26:12

Rate this article

[Bad]
|
|
[Good]
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