/****************************************************************
*
* www.payitforward.edu.vn
*
* Author: Jacob Pham
*
****************************************************************/
#include <msp430g2553.h>
/****************************************************************
* MAIN PROGRAM
****************************************************************/
void main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1SEL = 0x00; //Disable external crystal
P1SEL2 = 0x00;
//Config PIN
/****************************** Output ****************************/
P1DIR = BIT6; //P1.6 is output
P1OUT = BIT6;
/****************************** Input ****************************/
P1DIR &= ~(BIT3); //P1.0 & P1.3 are input
P1REN |= BIT3; //Enable internal resistor on P1.0 & P1.3
P1OUT |= BIT3; //Pull-up resistor
/************************Config button****************************/
P1IES |= BIT3; //Pos-edge interrupt
/* Bit = 0: Interrupt on a fall edge of an input signal
* Bit = 1: Interrupt on a rise edge of an input signal
*/
P1IE |= BIT3; //Enable GPIO interrupt on P1.0 & P1.3
P1IFG &= ~(BIT3); //Clear interrupt flag
_enable_interrupts(); //Enable Global interrupt
while(1)
{
//do nothing
}
}
#pragma vector = PORT1_VECTOR
__interrupt void port1_isr(void) // can change name interrupt program
{
if (P1IFG & BIT3) //Button 1 is pressed
{
__delay_cycles(50000); //delay 50ms
if ((P1IN & BIT3) == 0) //Button is really pressed
{
P1OUT ^= BIT6;
}
P1IFG &= ~BIT3; //Clear interrupt flag
}
}