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.

How to find the time for which a button is pressed in msp430?

Other Parts Discussed in Thread: MSP430G2553

I am using msp430g2553.I want to find the time for which the button is pressed.If the time is less than 7sec the led on pin 1.0 glows else the led on pin 1.6 glows.

The led on neither of the pins glow when i run this code.

#include <msp430.h>

#define RLY1 BIT6;

/* Global Variables */
int i=0;

void main(void) {
WDTCTL = WDTPW + WDTHOLD; // disable watchdog

P1OUT &=~ RLY1;
P1DIR = RLY1;
P1DIR = BIT0;
P1OUT&=~BIT0;
P1DIR&=~0x08; //P1.3 input
P1REN|=0x08; // Enabling Pull up or down
P1OUT|=0x08; //Pull up P1.3

P1IE|=0x08; //Enable external interrupt
P1IES|=0x08; //Falling edge
// P1.6 out to relay (LED)

BCSCTL1 = CALBC1_1MHZ; // Set DCO to calibrated 1 MHz.
DCOCTL = CALDCO_1MHZ;

TACCR0 = 62500 - 1; // A period of 62,500 cycles is 0 to 62,499.
// Enable interrupts for CCR0.
TACTL = TASSEL_2 + ID_3 + MC_1 + TACLR; // SMCLK, div 8, up mode,
// clear timer

_enable_interrupt();

for(;;) { // Do nothing while waiting for interrupts.
}
} // main


/* Interrupt Service Routines */
#pragma vector = TIMER0_A0_VECTOR
__interrupt void CCR0_ISR(void) {
P1IE&=~0x08;
++i;
P1IE|=0x08;
} // CCR0_ISR
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
if(i>0)
{
if(0.5*i>7)
P1OUT|=0x01;
else
P1OUT|=RLY1;
}
P1IES&=~0x08;
TACCTL0=CCIE;
}

 

**Attention** This is a public forum