Keil Logo

C51: ENUM EXAMPLES

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);
}

Last Reviewed: Monday, May 10, 2004


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.