richardlaishram
Member level 4
- Joined
- Jan 6, 2013
- Messages
- 77
- Helped
- 6
- Reputation
- 12
- Reaction score
- 6
- Trophy points
- 1,298
- Location
- Planet Earth
- Activity points
- 1,804
Hi, I've gone through a similar thread Link and I've checked the links provided in that also, but the example stated is in Assembly.
I've designed a 2x2 Keypad (same logic as in 4x4 keypad) just for trial before going for the actual 4x4 keypad. I'm using a msp430g2231 microcontroller and I'm connecting the keypad pins to the Launchpad IO pins. Posted below is the code which I've written in CCS v5.5. Please suggest me where I can go wrong in this code.
Please bear with me, I'm using msp430 chips for the first time.
I've designed a 2x2 Keypad (same logic as in 4x4 keypad) just for trial before going for the actual 4x4 keypad. I'm using a msp430g2231 microcontroller and I'm connecting the keypad pins to the Launchpad IO pins. Posted below is the code which I've written in CCS v5.5. Please suggest me where I can go wrong in this code.
Code:
#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;
}
Please bear with me, I'm using msp430 chips for the first time.