#include <msp430g2553.h>
void main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1SEL = 0x00; //Disable external crystal
P1SEL2 = 0x00;
P1DIR = 0xFF; //P1 is output
P1OUT=0x00;
P2DIR &= ~(BIT0); //P2.0 are input
P2REN |= BIT0; //Enable internal resistor on P2.0
P2OUT |= BIT0; //Pull-up resistor
P2IES |= BIT0; //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
*/
P2IE |= BIT0; //Enable GPIO interrupt on P2.0
P2IFG &= ~(BIT0); //Clear interrupt flag
_enable_interrupts(); //Enable Global interrupt
int i,j,k;
k=1;
while(1)
{
switch (k)
{
case '1':
//nhap nhay
P1OUT=0x00;
while(1){
P1OUT=~P1OUT;
__delay_cycles(100000);}}
break;
case '2':
P1OUT=0x0F;
// 4 tat 4 sang
while(1){
{
P1OUT=~P1OUT;
__delay_cycles(100000);}}
break;
//tat tư trai sang phai va nguoc lai
case '3':
while(1){
{
P1OUT=0x00;
for(i=0;i<8;i++){
P1OUT=(P1OUT<<1)|0x01;
__delay_cycles(100000);}
for(i=0;i<8;i++){
P1OUT=(P1OUT<<1)&0xFF;
__delay_cycles(100000);
}
}}
break;
default: k=1;
}
}
}
#pragma vector = PORT2_VECTOR
__interrupt void port2_isr(void) // can change name interrupt program
{
if ((P2IN & BIT0)==0) //Button 1 is pressed
{
__delay_cycles(50000); //delay 50ms
if ((P2IN & BIT0) == 0) //Button is really pressed
{break; // thoát for
k++; // tăng k lên 1
}
P2IFG &= ~BIT0; //Clear interrupt flag
}
}