You are on page 1of 4

#include<msp430g2553.

h>
const char keyMap[4][3]= {
[1,2,3],
[4,5,6],
[7,8,9],
[*,0,#]
};
const char
rowPins[4]={BIT4,BIT5,BIT6,BIT7};
const char
colPins[3]={BIT0,BIT1,BIT2};
void main(void)
{
WDTCTL=WDTPW+WDTHOLD;
BCSCTL=CALBC1_1MHZ;
DCOCTL=CALBC0_1MHZ;

P1DIR=BIT4+BIT5+BIT6+BIT7;
P1OUT &=~( BIT4+BIT5+BIT6+BIT7);
P2REN |=BIT0+BIT1+BIT2;
P1SEL=BIT1+BIT2;
P1SEL2=BIT1+BIT2;
UCA0CTL1 |=UCSSEL_2;
UCA0BR0 =104;
UCA0BR1=0;
UCA0MCTL=UCBRS0;
UCA0CTL1 &=~UCSWRT;
CCTL0=CC1E;
CCR0=30000;
TACTL=TASSEL_2+MC_1;
__BIS_SR(LPM0_bits+GIE);
}

#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A(void)
{
Char i,j;
for(i=0;i<4;i++)
{
P1OUT &=~rowPins[i];
for(j=0;j<3;j++)
{
If(!(P2IN & colPins[j]))
{
UCA0TXBUF=keyMap[i][j];
While(!(P2IN &colPins[j]));
}

}
P1OUT |=rowPins[i];
}
}