Programing on Launchpad MSP432
Interrupt button
Prerequisite:
Interrupt button
Prerequisite:
- Hardware: Launchpad MSP432P401
- IDE software: IAR/CCS/KEIL
- Tool: Simplelink SDK MSP432 v3.20.00.06
Description: Simple program using two buttons connected to P1.0 and P1.4 to turn on or turn off LED on P1.0
Step1. Open example of Simplelink SDK without RTOS
Step2. modify the code as below
Step3. Compile and debug the program
Step3. Compile and debug the program
/* DriverLib Includes */
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>
/* Standard Includes */
#include <stdint.h>
#include <stdbool.h>
volatile uint32_t SW1, SW2; //semaphores
void VectorButtons_Init(void){
__disable_interrupt;
//DisableInterrupts(); // set the I bit during initialization
SW1 = 0; SW2 = 0; // clear semaphores
P1->SEL0 &= ~0x12;
P1->SEL1 &= ~0x12;
P1->DIR &= ~0x12; //MAKE P1.1, P1.4
P1->REN |= 0x12; // enable pull resistor
P1->OUT |= 0x12; // p1.1, P1.4 pull up
P1->IES &= ~0x12; // RISING edge event
P1->IFG &= ~0x12; // Clear the flag
P1->IE |= 0x12; // arm interupt on P1.4, P1.1
NVIC->IP[8] = (NVIC->IP[8]&0x00FFFFFF)|0x40000000; // priority 2
NVIC->ISER[1] = 0x00000008; // enable interupt 35 in NVIC
//EnableInterrupts();}
__enable_interrupt;}
#define P1IFG_1 (*((volatile uint8_t *)(0x42000000 + 32*0x4C1C + 4*1)))
#define P1IFG_4 (*((volatile uint8_t *)(0x42000000 + 32*0x4C1C + 4*4)))
#define LEDOUT (*((volatile uint8_t *)(0x42000000 + 32*0x4C02 + 4*0)))
//bit-banding removes the bug
void PORT1_IRQHandler(void){
if(P1IFG_1){
P1IFG_1 = 0; //acknowledge
SW1 = 1;
}
if(P1IFG_4){
P1IFG_4 = 0; //acknowledge
SW2 = 1;
}
}
int main(void)
{
/* Stop Watchdog */
MAP_WDT_A_holdTimer();
VectorButtons_Init();
//config LED 1 P1.0
P1->SEL0 &= ~0x01;
P1->SEL1 &= ~0x01;
P1->DIR |= 0x01; // MAKE P1.0 Output
P1->DS |= 0x01; // Make P1.0 20mA maximum
while(1)
{
if(SW1)
{
SW1 = 0;
LEDOUT = 1;
}
if(SW2)
{
SW2 = 0;
LEDOUT = 0;
}
}
}
Good luck!
Comments
Post a Comment