Hi Everybody,
I have msp430g2553 launchpad and i integrated it with an extern 4x4 keypad.
My development tool is ccs6
for "rows" i use port1 pin 4-7
for "columns" i use port2 pin 0-3
when i press a button, i'm getting some reposnse but not the correct one, and even more then one reponse(due to the for loop)
Is there an example for keypad 4x4? or someone can help me and tell what is wrong with my code?
Thank you.
Here's my code:
#include <msp430g2553.h> #define MATRIX_ROW 4 const char keyMap[MATRIX_ROW][MATRIX_ROW] = { {'1','2','3','4'}, {'5','6','7','8'}, {'9','0','A','B'}, {'*','D','#','C'}, }; const char rowPins[MATRIX_ROW] = {BIT4, BIT5, BIT6, BIT7}; const char colPins[MATRIX_ROW] = {BIT0, BIT1, BIT2, BIT3}; void main(void) { //Stop WDT WDTCTL = WDTPW + WDTHOLD; P1IE |= BIT4 + BIT5 + BIT6 + BIT7; P1IES |= BIT4 + BIT5 + BIT6 + BIT7; P1IFG &= 0x00; P2IE |= BIT0 + BIT1 + BIT2 + BIT3; P2IES |= BIT0 + BIT1 + BIT2 + BIT3; P2IFG &= 0x00; __bis_SR_register(GIE); } // Port 1 interrupt service routine #pragma vector=PORT1_VECTOR #pragma vector=PORT2_VECTOR __interrupt void PORT_1 (void) { int i; int j; for(i=0; i<MATRIX_ROW;i++) { if(P1IFG & rowPins[i]) { for(j=0;j<MATRIX_ROW;j++) { if(P2IFG & colPins[j]) break; //for breakpoint to see i and j } } } P2IFG &= 0x00; P1IFG &= 0x00; }