版本信息如下:
Code Composer Studio
Version: 4.2.1.00004
源程序如下:
#pragma vector=PORT2_VECTOR
__interrupt void Port2ISR()
{
// volatile unsigned char temp;
P2IFG &= ~BIT1;
// temp = P2IN & BIT2;
if(P2IN & BIT2 == BIT2)
{
key_encode_value = 0x1a;
}
else
{
key_encode_value = 0x1b;
}
}
编译结果如下
0xE1A6: 12B0 E1DC CALL #abort
243 P2IFG &= ~BIT1;
Port2ISR:
0xE1AA: C3E2 002B BIC.B #2,&Port_1_2_P2IFG
245 if(P2IN & BIT2 == BIT2)
0xE1AE: B3D2 0028 BIT.B #1,&Port_1_2_P2IN
0xE1B2: 2004 JNE (C$L12)
251 key_encode_value = 0x1b;
0xE1B4: 40F2 001B 0208 MOV.B #0x001b,&key_encode_value
0xE1BA: 1300 RETI
247 key_encode_value = 0x1a;
C$L12:
0xE1BC: 40F2 001A 0208 MOV.B #0x001a,&key_encode_value
253 }
0xE1C2: 1300 RETI
加了一个临时变量缓存一下结果就对了,程序如下:
#pragma vector=PORT2_VECTOR
__interrupt void Port2ISR()
{
volatile unsigned char temp;
P2IFG &= ~BIT1;
temp = P2IN & BIT2;
if(temp == BIT2)
{
key_encode_value = 0x1a;
}
else
{
key_encode_value = 0x1b;
}
}
编译结果:
Port2ISR:
0xE110: 120F PUSH R15
0xE112: 8321 DECD.W SP
243 P2IFG &= ~BIT1;
0xE114: C3E2 002B BIC.B #2,&Port_1_2_P2IFG
244 temp = P2IN & BIT2;
0xE118: 422F MOV.W #4,R15
0xE11A: F25F 0028 AND.B &Port_1_2_P2IN,R15
0xE11E: 4FC1 0000 MOV.B R15,0x0000(SP)
245 if(temp == BIT2)
0xE122: 92E1 0000 CMP.B #4,0x0000(SP)
0xE126: 2404 JEQ (C$L12)
251 key_encode_value = 0x1b;
0xE128: 40F2 001B 0208 MOV.B #0x001b,&key_encode_value
0xE12E: 3C03 JMP (C$L13)
247 key_encode_value = 0x1a;
C$L12:
0xE130: 40F2 001A 0208 MOV.B #0x001a,&key_encode_value
253 }
C$L13:
0xE136: 5321 INCD.W SP
0xE138: 413F POP.W R15
0xE13A: 1300 RETI