Let's Make Robots!

Multiple Buttons in MSP430G2553 with asm

Hi 

I want to some basic projects with msp430g2553. I bought msp430 launchpad.

and I write some codes.

This is my code.

#include "msp430G2553.h"
;-------------------------------------------------------------------------------
ORG 0F800h ; Program Reset
;-------------------------------------------------------------------------------
RESET mov.w #0280h,SP ; Initialize stackpointer
StopWDT mov.w #WDTPW+WDTHOLD,&WDTCTL ; WDT Durdur
SetupP1 mov.b #001h,&P1DIR 
mov.b #008h,&P1OUT ; P1.3 set, else reset
bis.b #008h,&P1REN ; P1.3 pullup
bis.b #008h,&P1IE ; P1.3 Interrupt enabled
bis.b #008h,&P1IES ; P1.3 hi/low edge
bic.b #008h,&P1IFG ; P1.3 IFG Cleared
bis.b #010h,&P2IE ; P1.3 Interrupt enabled
bis.b #010h,&P2IES ; P1.3 hi/low edge
bic.b #010h,&P2IFG ; P1.3 IFG Cleared
;
Mainloop bis.w #LPM4+GIE,SR ;
nop 
;
;-------------------------------------------------------------------------------
P1_ISR; 
;-------------------------------------------------------------------------------
xor.b #001h,&P1OUT 
bic.b #008h,&P1IFG ;
reti 
;-------------------------------------------------------------------------------
P2_ISR; 
;-------------------------------------------------------------------------------
xor.b #001h,&P1OUT 
bic.b #010h,&P2IFG 
reti ;
;
;-------------------------------------------------------------------------------
; Interrupt Vectors.
;-------------------------------------------------------------------------------
ORG 0FFFEh ; MSP430 RESET Vector
DW RESET ;
ORG 0FFE4h ; P1.x Vector
DW P1_ISR 
ORG 0FFE6h ; P1.x Vector
DW P2_ISR ;

END

 

When I am using one button I have no problem. But I wont to more buttons. Example in my code. When I use P1.3 button. P1.0 active or I pressed P1.4 button P1.0 active.

But I am doing P1.3 button but P1.4 button isnt working. 

 

Thanks u

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I starting with C. I write code. But I have problem again. 

 

include "io430.h"

#include "in430.h"

 

void main( void )

{

   WDTCTL = WDTPW + WDTHOLD;

 

   DCOCTL=CALDCO_1MHZ;

   BCSCTL1=CALBC1_1MHZ;

 

   P1DIR = 0x00;

   P1REN = 0xFF;

   P1OUT = 0xFF;

   P2OUT = 0x00;

   P2DIR = 0xFF;

 

   while(1)

   {

      P2OUT = (P1IN & 0xFF);

   }

}

 

 

This is my code.But error is port 2s are 1 when no button press. But I press button 2.3 logic state is 0. But ı want to 0 is normal state. 1 is button press. This must be same as other pins.

P1.0  to P2.0

P1.1 to P2.1

P1.2 to P2.2

P1.3 to P2.3 

"P2OUT = (P1IN & 0xFF);" will always turn on all the port 2 pins, because P1IN & 0xFF = 0xFF no matter what the value or P1IN is.

Try just using "P2OUT = P1IN;" instead.

If you are using the code above, output P1.0 is flipped whenever there is an interrupt on P1.x or P2.x (port 1 or port 2). However, only the inputs that have been properly configured will trigger the interrupt.
The code that configures all the input settings for P1.3 is this part:

bis.b #008h,&P1REN ; P1.3 pullup
bis.b #008h,&P1IE ; P1.3 Interrupt enabled
bis.b #008h,&P1IES ; P1.3 hi/low edge
bic.b #008h,&P1IFG ; P1.3 IFG Cleared

You need to update that code to also configure the interrupt settings for P1.4 or any other inputs you want to use as buttons. To make the lines of code above apply to P1.3 and P1.4 you should be able to just change all the #008h bitmasks to #018h.
This works because:

#008h = #00001000b (only bit 3 is set, where bit 3 controls P1.3)
#018h = #00011000b (bits 3 and 4 are set, where bit 4 controls P1.4)

You also need to update your P1_ISR subroutine on this line:

bic.b #008h,&P1IFG ;

The P1 interrupt flag register (P1IFG) must have the bit that was just set during the interrupt cleared before it can be triggered again.

If you are new to the MSP430 or Assembly programming I would suggest trying to write your code without using interrupts at first, until you get comfortable with writing this sort of code.

Any reason for not doing this in C? I'm familiar with the msp430, but I don't really do much in ASM.