Topic : Enum error checking Bug.

Forum : 8051

Original Post
Post Information Post
February 11, 2008 - 3:27am
Guest

Hi

I have found what I think is a bug in the error checking of the RC51.

I made a mistake typing in a switch statement and left out the case on a few of the lines. (see below)

#include

typedef enum tBaud {B1200,B2400,B4800,B5760,B5787,B9600,B10472,B19200,B28800,B38400,B57600,B115200}T_BAUD;
typedef enum _tParity {P_NONE,P_EVEN,P_ODD}T_PARITY;

#define _1200_BAUD_RELOAD 0xFBEF
#define _2400_BAUD_RELOAD 0xFDF7
#define _4800_BAUD_RELOAD 0xFEFC
#define _5760_BAUD_RELOAD 0xFF27
#define _5787_BAUD_RELOAD 0xFF28
#define _9600_BAUD_RELOAD 0xFF7E
#define _10472_BAUD_RELOAD 0xFF89
#define _19200_BAUD_RELOAD 0xFFBF
#define _28800_BAUD_RELOAD 0xFFD5
#define _38400_BAUD_RELOAD 0xFFDF
#define _57600_BAUD_RELOAD 0xFFEA
#define _115200_BAUD_RELOAD 0xFFF5

void Set_Baud_and_Parity(T_BAUD Baud,T_PARITY Parity)
{

switch (Baud)
{

B1200: // Opps should be a case here
RCAP2H = _1200_BAUD_RELOAD >>8;
RCAP2L = _1200_BAUD_RELOAD;
break;

B2400: // Opps should be a case here
RCAP2H = _2400_BAUD_RELOAD >>8;
RCAP2L = _2400_BAUD_RELOAD;
break;

B4800: // Opps should be a case here
RCAP2H = _4800_BAUD_RELOAD >>8;
RCAP2L = _4800_BAUD_RELOAD;
break;

B5760: // Opps should be a case here
RCAP2H = _5760_BAUD_RELOAD >>8;
RCAP2L = _5760_BAUD_RELOAD;
break;

case B5787:
RCAP2H = _5787_BAUD_RELOAD >>8;
RCAP2L = _5787_BAUD_RELOAD;
break;

case B9600:
RCAP2H = _9600_BAUD_RELOAD >>8;
RCAP2L = _9600_BAUD_RELOAD;
break;

case B10472:
RCAP2H = _10472_BAUD_RELOAD >>8;
RCAP2L = _10472_BAUD_RELOAD;
break;

case B19200:
RCAP2H = _19200_BAUD_RELOAD >>8;
RCAP2L = _19200_BAUD_RELOAD;
break;

case B28800:
RCAP2H = _28800_BAUD_RELOAD >>8;
RCAP2L = _28800_BAUD_RELOAD;
break;

case B38400:
RCAP2H = _38400_BAUD_RELOAD >>8;
RCAP2L = _38400_BAUD_RELOAD;
break;


case B57600:
RCAP2H = _57600_BAUD_RELOAD >>8;
RCAP2L = _57600_BAUD_RELOAD;
break;

case B115200:
RCAP2H = _115200_BAUD_RELOAD >>8;
RCAP2L = _115200_BAUD_RELOAD;
break;


default:
RCAP2H = _9600_BAUD_RELOAD >>8; // 9600 by default
RCAP2L = _9600_BAUD_RELOAD;
}

TL2 = RCAP2L;
TH2 = RCAP2H;

if (Parity)
{
SCON = 0xD0; //9 bit mode for parity, enable reception *)
}
else
{
SCON = 0x50; //8 bit for parity none, enable reception *)
}
}

void Main(void)
{

Set_Baud_and_Parity(B1200,P_NONE);

}

This code complied with out any errors or warnings.

But if I had used constant values instead of an enum

Eg

0x00:
RCAP2H = _1200_BAUD_RELOAD >>8;
RCAP2L = _1200_BAUD_RELOAD;
break;

The complier would give an error.

Replies
Post Information Post
+1
0
-1
February 11, 2008 - 9:05am
Guest

It was not an error, nor a bug...
When the "case" is missing, the identifier is considered as a valid label. Labels and enum members are not in the same types of identifiers, and a single identifier can be reused for different types. That's fully legal...

Francis