Part Number: MSP430FG4618
Tool/software: Code Composer Studio
I got an incorrect compiling of C code in very simple code sample.
As we can see in the picture. The C language code in line 25 is not compiled. In disassembly there appears just line 27.
This is the CCS project (Managed CCS before) for MSP430FG4618. All settings are default. It is lunched on standard MSP-EXP430FG4618 board. A CCS version is 9.2 with all updates.
After some unsuccessful investigationusing volatile on variables, playing with settings for optimization. It was obtained - when a comment on line 24 is removed. We will get a correct result:
I attached both C files for testing.
#include <msp430xG46x.h>
#define BUTT1 0X01 // p1.0
#define BUTT2 0X02 // p1.1
#define LED1 0X04 // P2.2
#define LED2 0x02 // P2.1
#define BMASK BUTT1 + BUTT2 // Button mask
#define B_DEL_VAL 10 // Adjust it during work
void main(void)
{
volatile unsigned char Butt_S1=BUTT1 + BUTT2;
volatile unsigned char B_Del_Cnt=B_DEL_VAL;
volatile unsigned char X; // temporary result
WDTCTL = WDTPW+WDTHOLD; // stops the WDT
P2DIR = LED1 + LED2; // switch to output
P2OUT |= LED1 + LED2; // switch on
while(1)
{
X=P1IN & BMASK;
if(X == Butt_S1)
{ // The buttons aren�t changed
B_Del_Cnt--;
if(B_Del_Cnt==0)
{ // Debouncing delay is finished
// Button processing
if((Butt_S1 & BUTT1) == 0)
{
P2OUT |= LED2;
}
if((Butt_S1 & BUTT2) == 0)
{
P2OUT &= ~LED2;
}
B_Del_Cnt=B_DEL_VAL; // Prepare the next cycle
}
}
else
{ // NEWSTAT
Butt_S1=X; // Restart debouncing
B_Del_Cnt=B_DEL_VAL;
}
// NEXT
// There will be other tasks in main cycle
};
}
#include <msp430xG46x.h>
#define BUTT1 0X01 // p1.0
#define BUTT2 0X02 // p1.1
#define LED1 0X04 // P2.2
#define LED2 0x02 // P2.1
#define BMASK BUTT1 + BUTT2 // Button mask
#define B_DEL_VAL 10 // Adjust it during work
void main(void)
{
volatile unsigned char Butt_S1=BUTT1 + BUTT2;
volatile unsigned char B_Del_Cnt=B_DEL_VAL;
volatile unsigned char X; // temporary result
WDTCTL = WDTPW+WDTHOLD; // stops the WDT
P2DIR = LED1 + LED2; // switch to output
P2OUT |= LED1 + LED2; // switch on
while(1)
{
X=P1IN & BMASK;
if(X == Butt_S1)
{ // The buttons aren�t changed
B_Del_Cnt--;
if(B_Del_Cnt==0)
{ // Debouncing delay is finished
if((Butt_S1 & BUTT1) == 0)
{
P2OUT |= LED2;
}
if((Butt_S1 & BUTT2) == 0)
{
P2OUT &= ~LED2;
}
B_Del_Cnt=B_DEL_VAL; // Prepare the next cycle
}
}
else
{ // NEWSTAT
Butt_S1=X; // Restart debouncing
B_Del_Cnt=B_DEL_VAL;
}
// NEXT
// There will be other tasks in main cycle
};
}
Regards,
Juris

