labPreg

mail@pastecode.io avatar
unknown
plain_text
3 years ago
2.1 kB
1
Indexable
Never
#include <msp430.h>

int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;               // Stop watchdog timer

    // configuram pin 2.3 ca intrare digitala
    //P2DIR = 000 x000;

    P2DIR = 0x00; // setam directia intrare
    P2OUT = 0x08; //setam rezistorul de pull-up
    P2REN = 0x08; // setam rezistorul de pull-up
    P2IES = 0x08; //configuram ca intreruperea sa fie generata la trecerea din 1 in 0;
    P2IE = 0x08; //configuram ca pinul p2.3 sa genereze intreruperi


    // Configure GPIO
    //P2OUT &= ~BIT0;                         // Clear P1.0 output latch for a defined power-on state
    //P2DIR |= BIT0;                          // Set P1.0 to output direction

    P2OUT |= BIT3;                          // Configure P1.3 as pulled-up
    P2REN |= BIT3;                          // P1.3 pull-up register enable
    P2IES |= BIT3;                          // P1.3 Hi/Low edge
    P2IE |= BIT3;                           // P1.3 interrupt enabled

    P6DIR = 0x40; // 0100 0000 sau P6DIR |= BIT6;
    P6OUT = 0x00; // setam starea initiala a lui p6.6 in o logic

    // Disable the GPIO power-on default high-impedance mode
    // to activate previously configured port settings
    PM5CTL0 &= ~LOCKLPM5;

    P2IFG &= ~BIT3;                         // facem ca posibila intrerupere de la pinul p2.3 sa fie citita initial

    while(1)
    {
        __bis_SR_register(LPM3_bits | GIE); // Enter LPM3 w/interrupt
        __no_operation();                   // For debug
       // P1OUT ^= BIT0;                      // P1.0 = toggle
    }
}

// Port 2 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=PORT2_VECTOR
__interrupt void Port_2(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(PORT2_VECTOR))) Port_2 (void)
#else
#error Compiler not supported!
#endif
{
    P2IFG &= ~BIT3;                         // Clear P1.3 IFG curatam intreruperea
    P6OUT ^= BIT6; //sau P6OU ^= 0x40;
    __bic_SR_register_on_exit(LPM3_bits);   // Exit LPM3
}