Domanda

How can I enable and disable (clear and set GIE SR bit) in C using the mspgcc?

È stato utile?

Soluzione

/*interrupt.c
ganeshredcobra@gmail.com
GPL
*/
#include <msp430g2553.h>
#define LED1 BIT0
#define LED2 BIT6
#define BUTTON BIT3
volatile unsigned int i;//to prevent optimization
void main(void)
{
WDTCTL=WDTPW+WDTHOLD;
P1DIR |= (LED1+LED2);//
P1OUT &= ~(LED1+LED2);
P1IE |= BUTTON;
P1IFG &= ~BUTTON;

//__enable_interrupt();//enable all interrupts
_BIS_SR(LPM4_bits+GIE);
for(;;)
{}
}

//port1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
P1OUT ^= (LED1+LED2);
P1IFG &= ~BUTTON;
P1IES ^= BUTTON;
}

This is an example of interrupt http://importgeek.wordpress.com/tag/msp430-launchpad/

Altri suggerimenti

You can either use the __eint() / __dint() intrinsics:

#include <intrinsics.h>
...
    __eint();
    /* Interrupts enabled */
    __dint();
    /* Interrupts disabled */

Or you can use the __bis_status_register() / __bic_status_register() intrinsics:

#include <msp430.h>
#include <intrinsics.h>
...
    __bis_status_register(GIE);
    /* Interrupts enabled */
    __bic_status_register(GIE);
    /* Interrupts disabled */

Or one of the many other compatibility definitions in intrinsics.h. Note that there are also some special versions such as __bis_status_register_on_exit() / __bic_status_register_on_exit() which will change the state of the flag on exit from an ISR.

Through experimentation I found it can be enabled with _BIS_SR(GIE); and disabled with _BIC_SR(GIE); without including anything but the standard msp430g2553.h file.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top