The argument I have always heard for using enumerations to define constants in C is that it allows the tool chain to pass the symbols to one's debug environment. According to earlier discussions I have seen on this forum, that is not true of any of the C51 tools. The following example uses a typedef and an enumeration to simplify representation of some data:
#include <c8051f040.h> /* SFR declarations */ #include <stdio.h> /* printf function */ typedef enum { IL, OH, WI, IN } STATE; STATE mySt; void printState(STATE outState); /* Function prototype */ void main(void) { SFRPAGE = 0; WDTCN = 0xDE; WDTCN = 0xAD; for(;;) { for(mySt=IL; mySt<=IN; mySt++) printState(mySt); } } /* END main() */ void printState(STATE outState) { char *stateName = { "Illinois", "Ohio", "Wisconsin", "Indiana" }; printf("%s\n", stateName[outState]); return; } /* END printState */
for(mySt=IL; mySt<=IN; mySt++) | ?C0001: CLR A | MOV mySt,A | ?C0003: MOV A,mySt | SETB C | SUBB A,#03H | JNC ?C0001
IL . . . . . . . . E_CONST ----- U_CHAR ----- 1 OH . . . . . . . . E_CONST ----- U_CHAR ----- 1 WI . . . . . . . . E_CONST ----- U_CHAR ----- 1 IN . . . . . . . . E_CONST ----- U_CHAR ----- 1
#define IL 0 #define OH 1 #define WI 2 #define IN 3
============================================================ Gary Lynch | To send mail, change no$pam in lynchg@no$pam.com | my domain name to stacoenergy