This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/LAUNCHXL-F28377S: Declare a correct variable in F28377S

Part Number: LAUNCHXL-F28377S

Tool/software: Code Composer Studio

Hello,

 Colud you please tell me how to declare a correct variable. I want to declare this delay DELAY_US(1000*500) as variable t1 which is given in the end of program.

// Included Files
//
#include "F28x_Project.h"

//
// Defines
//

#define BLINKY_LED_GPIO 12

interrupt void xint1_isr(void);


void main(void)
{
//
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the F2837xS_SysCtrl.c file.
//
InitSysCtrl();

//
// Step 2. Initialize GPIO:
// This example function is found in the F2837xS_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
//
InitGpio();
GPIO_SetupPinMux(BLINKY_LED_GPIO, GPIO_MUX_CPU1, 0);
GPIO_SetupPinOptions(BLINKY_LED_GPIO, GPIO_OUTPUT, GPIO_PUSHPULL);

//
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
//
DINT;

//
// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the F2837xS_PieCtrl.c file.
//
InitPieCtrl();

//
// Disable CPU interrupts and clear all CPU interrupt flags:
//
IER = 0x0000;
IFR = 0x0000;

//
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in F2837xS_DefaultIsr.c.
// This function is found in F2837xS_PieVect.c.
//
InitPieVectTable();

//
// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
//
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.XINT1_INT = &xint1_isr;
EDIS; // This is needed to disable write to EALLOW protected registers

//


//
// Enable XINT1 and XINT2 in the PIE: Group 1 interrupt 4 & 5
// Enable INT1 which is connected to WAKEINT:
//
PieCtrlRegs.PIECTRL.bit.ENPIE = 1; // Enable the PIE block
PieCtrlRegs.PIEIER1.bit.INTx4 = 1; // Enable PIE Group 1 INT4
PieCtrlRegs.PIEIER1.bit.INTx5 = 1; // Enable PIE Group 1 INT5
IER |= M_INT1; // Enable CPU INT1
EINT; // Enable Global Interrupts

// GPIO14 is inputs
//
EALLOW;
GpioCtrlRegs.GPAMUX1.bit.GPIO14 = 0; // GPIO
GpioCtrlRegs.GPADIR.bit.GPIO14 = 0; // input
GpioCtrlRegs.GPAQSEL1.bit.GPIO14 = 0; // XINT1 Synch to SYSCLKOUT only

EDIS;

//
// GPIO14 is XINT1
//
GPIO_SetupXINT1Gpio(14);

//
// Configure XINT1
//
XintRegs.XINT1CR.bit.POLARITY = 1; // Raising edge interrupt 1
//Falling edge interrupt 0

//
// Enable XINT1
//
XintRegs.XINT1CR.bit.ENABLE = 1; // Enable XINT1

//
//
// Enable global Interrupts and higher priority real-time debug events:
//
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM

//
// Step 6. IDLE loop. Just sit and loop forever (optional):
//
for(;;)
{


}
}

//
// My intrr
//
// xint1_isr - External Interrupt 1 ISR
//

interrupt void xint1_isr(void)

{

//
// Turn on LED
//
GPIO_WritePin(BLINKY_LED_GPIO, 0);

//
// Delay for a bit.
//
DELAY_US(1000*500);

//
// Turn off LED
//
GPIO_WritePin(BLINKY_LED_GPIO, 1);

//
// Delay for a bit.
//
DELAY_US(1000*500);

// Turn on LED
//
GPIO_WritePin(BLINKY_LED_GPIO, 0);

//
// Delay for a bit.
//
DELAY_US(1000*500);

//
// Turn off LED
//
GPIO_WritePin(BLINKY_LED_GPIO, 1);

//
// Delay for a bit.
//
DELAY_US(1000*500);

//

// Acknowledge this interrupt to get more from group 1
//
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

}
//
// End of file
//

  • This link does a decent job of explaining how to use macros in C

    Below is an example of using it.  I used a small number but you can see the basic idea.

    #include <msp430.h>
    #define DELAY_US (10*5)
    
    
    
    int main(void) {
        WDTCTL = WDTPW | WDTHOLD;               // Stop watchdog timer
        PM5CTL0 &= ~LOCKLPM5;                   // Disable the GPIO power-on default high-impedance mode
                                                // to activate previously configured port settings
        P1DIR |= 0x01;                          // Set P1.0 to output direction
    
        for(;;) {
            volatile unsigned int i;            // volatile to prevent optimization
    
            P1OUT ^= 0x01;                      // Toggle P1.0 using exclusive-OR
    
            i = DELAY_US;                          // SW Delay
            do i--;
            while(i != 0);
        }
    
        return 0;
    }