Part Number: MSP430G2553
Tool/software: Code Composer Studio
Hi. I made a keypad operation with MSP430G2553 . But there is a problem that I have mentioned on the video. If I press the number 5 button (or 7 or 9 or 3 ....), it should be lit as the LEDs (0101), but the other LEDs can be activated in the same column several times. I think When I press the key, an arc occurs.so,key value changes.how can i solve this problem?.I'm sorry for my bad english
video link is here
here is the my code
#include <msp430.h>
void delay(void)
{
unsigned int i=2500;
while(i--);
}
unsigned int tus=50;
void Refresh_Keypad (void)
{
//***1.satır aktif iken******
P1OUT|=BIT1;
delay();
if(P1IN&BIT5)
{
tus=0;
}
else if(P1IN&BIT7)
{
tus=1;
}
else if(P2IN&BIT0)
{
tus=2;
}
else if(P2IN&BIT1)
{
tus=3;
}
//****ikinci satır aktif iken*******
P1OUT &=~BIT1;
P1OUT|=BIT2;
delay();
if(P1IN&BIT5)
{
tus=4;
}
else if(P1IN&BIT7)
{
tus=5;
}
else if(P2IN&BIT0)
{
tus=6;
}
else if(P2IN&BIT1)
{
tus=7;
}
//****üçüncü satır aktif iken*******
P1OUT &=~BIT2;
P1OUT |=BIT3;
delay();
if(P1IN&BIT5)
{
tus=8;
}
else if(P1IN&BIT7)
{
tus=9;
}
else if(P2IN&BIT0)
{
tus=10;
}
else if(P2IN&BIT1)
{
tus=11;
}
//****dorduncu satır aktif iken*******
P1OUT &=~BIT3;
P1OUT |=BIT4;
delay();
if(P1IN&BIT5)
{
tus=12;
}
else if(P1IN&BIT7)
{
tus=13;
}
else if(P2IN&BIT0)
{
tus=14;
}
else if(P2IN&BIT1)
{
tus=15;
}
P1OUT &=~BIT4;
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
DCOCTL=CALDCO_1MHZ;
BCSCTL1=CALBC1_1MHZ;
P1OUT &=~(BIT1+BIT2+BIT3+BIT4);
P1DIR |=(BIT1+BIT2+BIT3+BIT4) ;
P1DIR &=~(BIT5+BIT7) ;
P2DIR =~(BIT0+BIT1) ;
P2OUT =~(BIT2+BIT3+BIT4+BIT5) ;
P2DIR|=BIT2+BIT3+BIT4+BIT5;
P2OUT &=~(BIT2+BIT3+BIT4+BIT5) ;
for(;;)
{
Refresh_Keypad();
if(tus!=50)
{
tus=4*tus; //RLA
#include <msp430.h>
void delay(void)
{
unsigned int i=2500;
while(i--);
}
unsigned int tus=50;
void Refresh_Keypad (void)
{
//***1.sat�r aktif iken******
P1OUT|=BIT1;
delay();
if(P1IN&BIT5)
{
tus=0;
}
else if(P1IN&BIT7)
{
tus=1;
}
else if(P2IN&BIT0)
{
tus=2;
}
else if(P2IN&BIT1)
{
tus=3;
}
//****ikinci sat�r aktif iken*******
P1OUT &=~BIT1;
P1OUT|=BIT2;
delay();
if(P1IN&BIT5)
{
tus=4;
}
else if(P1IN&BIT7)
{
tus=5;
}
else if(P2IN&BIT0)
{
tus=6;
}
else if(P2IN&BIT1)
{
tus=7;
}
//****���nc� sat�r aktif iken*******
P1OUT &=~BIT2;
P1OUT |=BIT3;
delay();
if(P1IN&BIT5)
{
tus=8;
}
else if(P1IN&BIT7)
{
tus=9;
}
else if(P2IN&BIT0)
{
tus=10;
}
else if(P2IN&BIT1)
{
tus=11;
}
//****dorduncu sat�r aktif iken*******
P1OUT &=~BIT3;
P1OUT |=BIT4;
delay();
if(P1IN&BIT5)
{
tus=12;
}
else if(P1IN&BIT7)
{
tus=13;
}
else if(P2IN&BIT0)
{
tus=14;
}
else if(P2IN&BIT1)
{
tus=15;
}
P1OUT &=~BIT4;
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
DCOCTL=CALDCO_1MHZ;
BCSCTL1=CALBC1_1MHZ;
P1OUT &=~(BIT1+BIT2+BIT3+BIT4);
P1DIR |=(BIT1+BIT2+BIT3+BIT4) ;
P1DIR &=~(BIT5+BIT7) ;
P2DIR =~(BIT0+BIT1) ;
P2OUT =~(BIT2+BIT3+BIT4+BIT5) ;
P2DIR|=BIT2+BIT3+BIT4+BIT5;
P2OUT &=~(BIT2+BIT3+BIT4+BIT5) ;
for(;;)
{
Refresh_Keypad();
if(tus!=50)
{
tus=4*tus;//11+11=110;
// tus=tus+tus;//110+110=1100;
//tus=tus+tus;//1100+1100=11000;
//tus=tus+tus;//11000+11000=11 0000;
P2OUT=0x00;
P2OUT|=tus;
tus=50;
}
}
}
P2OUT=0x00;
P2OUT|=tus;
tus=50;
}
}
}