Derek Fritz

"#define" is not working with the MC9S12XS128

Discussion created by Derek Fritz on Feb 2, 2010
Latest reply on Feb 19, 2010 by Derek Fritz

I have a question on what I figured to be a rather simple bit of coding that is not working the way I would expect it to... I've assigned labels to some output pins on the MC9S12XS128 (port A, specifically) using #defines, and then tried to

 

#define     COIL_05_CTL     PORTA

#define     COIL_05_PIN     BIT5

 

ubyte     LAST_COIL_CTL;

ubyte     LAST_COIL_PIN;

 

 

case 5:

     LAST_COIL_CTL = COIL_05_CTL;  // Assign coil 5 control to last coil control

     LAST_COIL_PIN = COIL_05_PIN;  // Assign coil 5 output pin to last coil pin

 

LAST_COIL_CTL &= (~LAST_COIL_PIN);  // Turn off pin 5 of PORT A - does not work

 

This last command DOES NOT turn off pin 5 of PORT A; however, the following line of code DOES turn off the pin, as expected:

 

 COIL_05_CTL &= (~COIL_05_PIN);  // Turn off pin 5 of PORT A

 

Any idea as to why the #define can't be assigned to simple ubyte variable and manipulated accordingly?  I also tryed (ubyte) castings, which did not help:

 

case 5:

     LAST_COIL_CTL = (ubyte)COIL_05_CTL;  // Assign coil 5 control to last coil control

     LAST_COIL_PIN = (ubyte)COIL_05_PIN;  // Assign coil 5 output pin to last coil pin

 

 

Thanks in advance.

Outcomes