Sure. Here it is. I just want tot mention that the debounce effect(the led is on and after 2 ticks is off again) doesn't happen all the time but in 1 out of 6-7 cases. //Enable Timer rtc with Pushbutton ISR #include int counter_timer = 0; int counter_port = 0; int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P1DIR |= BIT0; P1OUT &= ~BIT0; P4DIR |= BIT0; // Set P4.0 to output direction \\pin 4.0 e Ledu verde P2DIR &= ~BIT6; //Set P2.6 to input direction P4OUT &= ~BIT0; // set P4.0 to 0 (LED OFF) P2REN |= 0x40; // Resistor for P2.6 // 0x40 = 01000000 in binar, adica bitul6 P2OUT |= 0x40; // Resistor pulls up P2IES |= 0x40; // High to low transition for P1.2 P2IE |= BIT6; // P2.6 interrupt enabled P2IFG &= ~BIT6; // P2.6 IFG cleared // Configure clock as SMCLK = 1MHz __bis_SR_register(SCG0); // disable FLL CSCTL3 |= SELREF__REFOCLK; // Set REFO as FLL reference source CSCTL0 = 0; // clear DCO and MOD registers CSCTL1 &= ~(DCORSEL_7); // Clear DCO frequency select bits first CSCTL1 |= DCORSEL_2; // Set DCO = 4MHz CSCTL2 = FLLD_1 + 60; // DCODIV = 2MHz __delay_cycles(3); __bic_SR_register(SCG0); // enable FLL while(CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1)); // Poll until FLL is locked CSCTL4 |= SELMS__DCOCLKDIV | SELA__REFOCLK; // set default REFO(~32768Hz) as ACLK source, ACLK = 32768Hz // default DCODIV as MCLK and SMCLK source CSCTL5 |= DIVM__1 | DIVS__2; // SMCLK = 1MHz, MCLK = 2MHz // Initialize RTC RTCMOD = 400; RTCCTL = RTCSS__SMCLK | RTCSR | RTCPS__1000 ; //sursa clock-ului e SMCLK=1MHz | reload shadow register |SMCLK se divide cu 1000|interrupt enable P2IE |= BIT6; // P2.6 interrupt enabled PM5CTL0 &= ~LOCKLPM5; __no_operation(); __bis_SR_register(GIE); while(1) { if(counter_port == 1) //if the button is pressed once { RTCCTL |= RTCIE; // RTC timer interrupt enable P2IE &= ~BIT6; // disable P2.6 interrupt if(counter_timer == 2) // after 2 RTC timer ticks pass { P1OUT ^= BIT0; // red led on counter_timer = 0; //reset timer counter counter_port = 0; //reset button counter RTCCTL &= ~RTCIE; //RTC timer interrupt disable P2IFG &= ~BIT6; // Clear possible stale P2.6 status <--- P2IE |= BIT6; // P2.6 interrupt enabled } } } } // *************************INTERRUPT ROUTINES************************************************************************ // Timer A0 interrupt service routine #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector = RTC_VECTOR __interrupt void RTC_ISR(void) #elif defined(__GNUC__) void __attribute__ ((interrupt(RTC_VECTOR))) RTC_ISR (void) #else #error Compiler not supported! #endif { counter_timer++; RTCIV = RTCIV_RTCIF ; } // Port 2 interrupt service routine #pragma vector = PORT2_VECTOR __interrupt void PORT2_ISR(void) { counter_port++; P2IFG &= ~0x40; // Clear interrupt flag for P2.6 }
↧