I had searched in the Discussion Forum for the whole moring but I couldn't find the right way to solve the problem I met,so I send this message hoping you guys can help me!Thanks in advance:-)My problem is as follows: 1.I want to define a macro,which is similar like function.It will be used in my communction interrupt service routine(so you can see that why I don't choose to call a function to realize it) 2.here's the definition of this macro: #define Macro_TestRxEnd(sbit Header_flag,uchar Header,uchar Tailer) \ { \ Return_flag = 0; \ if (!Header_flag) \ { \ if (Rxbuf == Header) \ { \ Header_flag = 1; \ ptRxBuf++; \ } \ else \ { ptRxBuf = xBuf; } \ else \ { \ if (Rxbuf == Tailer) \ { Return_flag = 1; } \ } 3.then the compile result is : Error C304: Bad Macro Parameter List so can anyone help me find out the right way to define such a long macro? I'm waiting for your good ideas earnestly!
"...all messages have the same format, I presume: 1. A header; 2. a body; 3. a tail. I would structure the ISR on this basis..." Something like this:
void isr( void ) { static bit in_message = 0; // Set to 1 after a header has been detected; // Cleared to 0 when a trailer is detected; // Thus it indicates when we are within the body // of a message static unsigned char msg_type; // Records the last-received header; // So, when in_message is set, this indicates the // type of message currently in progress. if( in_message ) { // We're within the body of a message; // ie, a Header has previously been detected. // Check if this is now the end of the message if( Rxbuf == Tailer ) { // It's the end of the message in_message = 0; } else { // It's not the end of the message; // handle a message-body character // (possibly depending on msg_type?) } } else { // Not currently within the body of a message; // Check if this is a header switch( Rxbuf ) { case A_Header: // It's the start of an "A" frame: in_message = 1; msg_type = Rxbuf; break; case B_Header: // It's the start of a "B" frame: in_message = 1; msg_type = Rxbuf; break; case C_Header: // It's the start of an "C" frame: in_message = 1; msg_type = Rxbuf; break; default: // Not the start of a frame - Do nothing! break; } } }
A.W. Neil,thank you the same:-)I'll read your ideas carefully and send back next Monday,see you!Looking forward to more ideas(maybe not only limited to the original message) ^-^