#include <msp430.h>
#define COL1 (P1OUT &= BIT2)
#define COL2 (P1OUT &= BIT3)
#define ROW1 (P1IN &= BIT4)
#define ROW2 (P1IN &= BIT5)
volatile unsigned int i, j, k, count;
void delay(j){
for(i = 0; i <= j; i++)
k = 1000;
do{
k--;
}while(k != 0);
}
int keypad(){
COL1;
if(ROW1){delay(1000); while(ROW1); return 1;}
if(ROW2){delay(1000); while(ROW2); return 2;}
COL2;
if(ROW1){delay(1000); while(ROW1); return 3;}
if(ROW2){delay(1000); while(ROW2); return 4;}
}
int main(void){
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR = BIT0 + BIT2 + BIT3 + BIT6;
P1REN = BIT2 + BIT3 + BIT4 + BIT5;
while(1){
count = keypad();
if(count == 1){P1OUT = BIT0;}
if(count == 2){P1OUT = BIT6;}
if(count == 3){P1OUT = BIT0 + BIT6;}
if(count == 4){P1OUT = BIT0; delay(1000); P1OUT = BIT6; delay(1000);}
}
return 0;
}