LM3S1138 Getting Started 3, Interrupts

Publisher:csZhouLatest update time:2016-11-01 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The two buttons control the LED light on and off. The program is very simple, LED.C is not pasted here, only the main program is listed.

// Include necessary header files
#include "LED.H"
#include
#include
#include
#include > #include
#include
#include
#include


// Define longer identifiers as shorter forms
#define SysCtlPeriEnable SysCtlPeripheralEnable
#define SysCtlPeriDisable SysCtlPeripheralDisable
#define GPIOPinTypeIn GPIOPinTypeGPIOInput
#define GPIOPinTypeOut GPIOPinTypeGPIOOutput
#define GPIOPinTypeOD GPIOPinTypeGPIOOutputOD


//Define KEY
#define KEY_PERIPH SYSCTL_PERIPH_GPIOG
#define KEY_PORT GPIO_PORTG_BASE
#define KEY_PIN GPIO_PIN_5


// Prevent JTAG from failing
void JTAG_Wait(void)
{
    SysCtlPeriEnable(KEY_PERIPH); // Enable the GPIO port where KEY is located
    GPIOPinTypeIn(KEY_PORT, KEY_PIN); // Set the pin where KEY is located to input

    if ( GPIOPinRead(KEY_PORT , KEY_PIN) == 0x00 ) // If KEY is pressed during reset, enter
    {
        for (;;); // Infinite loop to wait for JTAG connection
    }

    SysCtlPeriDisable(KEY_PERIPH); // Disable the GPIO port where KEY is located
}


// GPIOD interrupt initialization
void GPIOD_IntInit(void)
{
    SysCtlPeriEnable(SYSCTL_PERIPH_GPIOD); // Enable GPIOD port
    GPIOPinTypeIn(GPIO_PORTD_BASE, GPIO_PIN_1); // Set PD1 pin to input

    GPIOIntTypeSet(GPIO_PORTD_BASE, //Set the interrupt type of
                   PD1GPIO_PIN_1,
                   GPIO_LOW_LEVEL); //Low level trigger

    GPIOPinIntEnable(GPIO_PORTD_BASE , GPIO_PIN_1); // Enable PD1 pin interrupt
    IntEnable(INT_GPIOD); // Enable GPIOD port interrupt
}


// GPIOG interrupt initialization
void GPIOG_IntInit(void)
{
    SysCtlPeriEnable(SYSCTL_PERIPH_GPIOG); // Enable GPIOG port
    GPIOPinTypeIn(GPIO_PORTG_BASE, GPIO_PIN_5); // Set PG5 pin as input

    GPIOIntTypeSet(GPIO_PORTG_BASE, //Set PG5 interrupt type
                   GPIO_PIN_5,
                   GPIO_LOW_LEVEL); //Low level trigger

    GPIOPinIntEnable(GPIO_PORTG_BASE , GPIO_PIN_5); // Enable PG5 pin interrupt
    IntEnable(INT_GPIOG); // Enable GPIOG port interrupt
}


// System initialization
void SystemInit(void)
{
    SysCtlLDOSet(SYSCTL_LDO_2_50V); // Set LDO output voltage

    SysCtlClockSet(SYSCTL_USE_OSC | // System clock setting, using the main oscillator
                   SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_6MHZ |
                   SYSCTL_SYSDIV_1);

/*
    SysCtlLDOSet(SYSCTL_LDO_2_75V); // Before configuring PLL, set the LDO voltage to 2.75V

    SysCtlClockSet(SYSCTL_USE_PLL | // System clock setting, using PLL
                   SYSCTL_OSC_MAIN | // Main oscillator
                   SYSCTL_XTAL_6MHZ | // External 6MHz crystal oscillator
                   SYSCTL_SYSDIV_10); // The frequency division result is 20MHz
*/

    LED_Init(LED1); // Initialize LED1 and LED2
    LED_On(LED1); // Turn on LED1

    GPIOD_IntInit(); // GPIOD interrupt initialization
    GPIOG_IntInit(); // GPIOG interrupt initialization

    IntMasterEnable(); // Enable processor interrupts (turn on global interrupts)
}


// Main function (program entry)
int main(void)
{
    JTAG_Wait(); // Prevent JTAG failure, important!

    SystemInit(); // System initialization

    for (;;)
    {
    }
}


// GPIOD interrupt service function
void GPIO_Port_D_ISR(void)
{
    unsigned long ulStatus;

    ulStatus = GPIOPinIntStatus(GPIO_PORTD_BASE , true); // Read interrupt status
    GPIOPinIntClear(GPIO_PORTD_BASE , ulStatus); // Clear interrupt status, important (must be cleared by software)

    if ( ulStatus & GPIO_PIN_1 ) // If the interrupt status of PD1 is valid
    {
        LED_On(LED1); // Turn on LED1
    }

    // If there are interrupts from other pins of the GPIOD port to be processed, please add multiple if statements in parallel
}


//GPIOG interrupt service function
void GPIO_Port_G_ISR(void)
{
    unsigned long ulStatus;

    ulStatus = GPIOPinIntStatus(GPIO_PORTG_BASE, true); // Read interrupt status
    GPIOPinIntClear(GPIO_PORTG_BASE, ulStatus); // Clear interrupt status, important

    if ( ulStatus & GPIO_PIN_5 ) // If the interrupt status of PG5 is valid
    {
        LED_Off(LED1); // Turn off LED1
    }

    // If there are interrupts from other pins of the GPIOG port to be processed, please parallelize multiple if statements
}

Reference address:LM3S1138 Getting Started 3, Interrupts

Previous article:LM3S1138 Getting Started 4, Interrupt Priority
Next article:LM3S1138 Getting Started 2, Marquee

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号