| ||||||||
Technical Support Support Resources Product Information | C51: ENUM EXAMPLESQUESTIONI tried to use the Enumeration type in C51, but it did not work. Can you give me an example that works? ANSWERThe 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 | |||||||
| ||||||||