This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP430G2553: Questions on how to implement a interrupt push button

Part Number: MSP430G2553

Tool/software: Code Composer Studio

The code below sets up a traffic light, starting at green for 10 secs, then to yellow(green and red together) for 5 seconds and lastly red for 5 seconds. I would like to implement a button interrupt into the code to be recognized once every minute and act as a crosswalk indicator. The button once pushed will delay 1 second then go to the yellow light (green and red together) and proceed from there.

Any help is appreciated.

;Clock/Timer

            clr.b &DCOCTL

            mov.b &CALBC1_1MHZ, &BCSCTL1

            or.w  #DIVA_2, &BCSCTL1

            mov.b #DCO0+DCO1, &DCOCTL

            mov.b #LFXT1S_2, &BCSCTL3

            mov.w #TASSEL_1 + MC_0 + TACLR + ID_3 + TAIE, &TA0CTL

            mov.w #TASSEL_1 + MC_0 + TACLR + ID_3 + TAIE, &TA1CTL     ; ACLK, Stopped, CLEAR TAR

            mov.w #CCIE, &TA0CCTL0 ; CCR0 interrupt enabled

            mov.w #9375, &TA0CCR0 ;

            mov.w #CCIE, &TA0CCTL1 ; CCR0 interrupt enabled

            mov.w #3750, &TA0CCR1

            mov.w #CCIE, &TA0CCTL2

            mov.w #5625, &TA0CCR2

;I/O

            clr.b &P1OUT

            mov.b #0xFF, &P1DIR

            bic.b #BIT3, &P1DIR

            bis.b #BIT3, &P1OUT

            bis.b #BIT3, &P1IN

            bis.b #BIT3, &P1REN

            bis.b #BIT6, &P1OUT

            or.w  #MC_1, &TA0CTL

            mov.w #GIE+LPM3, SR            ;goto LPM enable interrupts

jump         jmp        jump

TIMERA0_ISR:

            xor.b #BIT0, &P1OUT

            xor.b #BIT6, &P1OUT

               reti

TIMERA01_ISR:

            add.w &TA0IV, PC

            reti

            jmp yellow

            jmp red

            reti

            reti

            reti

yellow:

            bis.b #BIT0, &P1OUT

            reti

red:

            xor.b #BIT6, &P1OUT

            reti

        

loop: ;Polling Loop

            bit.b #BIT3, &P1IN

            jz WALK

            bic.b #BIT3, &P1OUT

WALK:

            bit.b #BIT3, &P1IN

            jnz    loop

            bis.b #BIT6, &P1OUT

            jmp loop

  • Hi,

    You can refer to MSP code example for help. Below is exmaple code for using GPIO as input interrupt. 

    ; --COPYRIGHT--,BSD_EX
    ;  Copyright (c) 2014, Texas Instruments Incorporated
    ;  All rights reserved.
    ;
    ;  Redistribution and use in source and binary forms, with or without
    ;  modification, are permitted provided that the following conditions
    ;  are met:
    ;
    ;  *  Redistributions of source code must retain the above copyright
    ;     notice, this list of conditions and the following disclaimer.
    ;
    ;  *  Redistributions in binary form must reproduce the above copyright
    ;     notice, this list of conditions and the following disclaimer in the
    ;     documentation and/or other materials provided with the distribution.
    ;
    ;  *  Neither the name of Texas Instruments Incorporated nor the names of
    ;     its contributors may be used to endorse or promote products derived
    ;     from this software without specific prior written permission.
    ;
    ;  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    ;  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    ;  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    ;  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    ;  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    ;  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    ;  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
    ;  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    ;  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    ;  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    ;  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    ;
    ; ******************************************************************************
    ;
    ;                        MSP430 CODE EXAMPLE DISCLAIMER
    ;
    ;  MSP430 code examples are self-contained low-level programs that typically
    ;  demonstrate a single peripheral function or device feature in a highly
    ;  concise manner. For this the code may rely on the device's power-on default
    ;  register values and settings such as the clock configuration and care must
    ;  be taken when combining code from several examples to avoid potential side
    ;  effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
    ;  for an API functional library-approach to peripheral configuration.
    ;
    ; --/COPYRIGHT--
    ;******************************************************************************
    ;  MSP430FR243x Demo - Software Port Interrupt Service on P1.3 from LPM3
    ;
    ;  Description: A Hi/Lo transition on P1.3 will trigger P1ISR the first time.
    ;  On hitting the P1ISR, device exits LPM3 mode and executes section of code in
    ;  main() which includes toggling an LED.
    ;
    ;  ACLK = default REFO ~32768Hz, MCLK = SMCLK = default DCODIV ~1MHz
    ;
    ;               MSP430FR2433
    ;            -----------------
    ;        /|\|                 |
    ;         | |                 |
    ;         --|RST              |
    ;           |                 |
    ;     /|\   |                 |
    ;      --o--|P1.3         P1.0|-->LED
    ;     \|/   |                 |
    ;           |                 |
    ;
    ;   Cen Fang
    ;   Wei Zhao
    ;   Texas Instruments Inc.
    ;   September 2013
    ;   Built with IAR Embedded Workbench v6.20
    ;******************************************************************************
    #include <msp430.h>
    ;-------------------------------------------------------------------------------
                RSEG    CSTACK                  ; Define stack segment
    ;-------------------------------------------------------------------------------
                RSEG    CODE
    ;-------------------------------------------------------------------------------
    RESET       mov.w   #SFE(CSTACK),SP         ; Initialize stackpointer
                mov.w   #WDTPW+WDTHOLD,&WDTCTL  ; Stop WDT
    
    SetupP1     bic.b   #BIT0,&P1OUT            ; Clear P1.0 output
                bis.b   #BIT0,&P1DIR            ; P1.0 output
    
                bis.b   #BIT3,&P1OUT            ; Configure P1.3 as pulled-up
                bis.b   #BIT3,&P1REN            ; P1.3 pull-up register enable
                bis.b   #BIT3,&P1IES            ; P1.3 Lo/Hi edge
                bis.b   #BIT3,&P1IE             ; P1.3 interrupt enabled
    
                bic.w   #LOCKLPM5,PM5CTL0       ; Unlock I/O pins
                
                bic.b   #BIT3,&P1IFG            ; P1.3 IFG cleared
    
    Mainloop    bis.w   #LPM3+GIE,SR            ; Enter LPM3 w/ interrupt
                nop                             ; for debug
                xor.b   #BIT0,&P1OUT            ; P1.0 = toggle
                jmp     Mainloop
    
    ;------------------------------------------------------------------------------
    P1_ISR ;    Port 1 Interrupt
    ;------------------------------------------------------------------------------
                bic.b   #BIT3,&P1IFG            ; Clear P1.3 IFG
                bic.w   #LPM3,0(SP)             ; Exit LPM3
                reti
    ;-------------------------------------------------------------------------------
                COMMON  INTVEC                  ; Interrupt Vectors
    ;-------------------------------------------------------------------------------
                ORG     RESET_VECTOR            ; POR, ext. Reset
                DW      RESET
                ORG     PORT1_VECTOR            ; Port 1 Vector
                DW      P1_ISR
                END
    

    Best Regards,

    Winter Yu

**Attention** This is a public forum