本人在编写用定时器控制单片机中断20次的实验中,发现无法进入第二次中断,进入第一次中断后就一直在while循环,也清除了标志位,麻烦大神帮看一下
//*****************************************************************************
//
// timers.c - Timers example.
//
// Copyright (c) 2013 Texas Instruments Incorporated. All rights reserved.
// Software License Agreement
//
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
//
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 2.0.1.11577 of the DK-TM4C129X Firmware Package.
//
//*****************************************************************************
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "driverlib/rom_map.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/interrupt.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/timer.h"
#include "grlib/grlib.h"
#include "drivers/frame.h"
#include "drivers/kentec320x240x16_ssd2119.h"
#include "drivers/pinout.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/uart.h"
#include "inc/hw_uart.h"
#include "utils/uartstdio.h"
#include <stdarg.h>
//*****************************************************************************
//
//! \addtogroup example_list
//! <h1>Timer (timers)</h1>
//!
//! This example application demonstrates the use of the timers to generate
//! periodic interrupts. One timer is set up to interrupt once per second and
//! the other to interrupt twice per second; each interrupt handler will toggle
//! its own indicator on the display.
//
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
//*****************************************************************************
//
// The interrupt handler for the first timer interrupt.
//
//*****************************************************************************
#define NUMBER_OF_INTS 20
static volatile uint32_t g_ui32Counter = 0;
//*****************************************************************************
//
// This example application demonstrates the use of the timers to generate
// periodic interrupts.
//
//*****************************************************************************
void
InitConsole(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
GPIOPinTypeUART(GPIO_PORTA_BASE,GPIO_PIN_0|GPIO_PIN_1);
UARTStdioConfig(0,115200,16000000);
}
int main(void)
{
uint32_t ui32PrevCount = 0;
SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_OSC|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
InitConsole();
UARTprintf("16 - Bit Timer Interrupt - >");
UARTprintf("\n Timer = Timer0B");
UARTprintf("\n Mode = Periodic");
UARTprintf("\n Number of interrupts = %d",NUMBER_OF_INTS);
UARTprintf("\n Rate = 1ms\n\n");
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
ROM_SysCtlDelay(1);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_PERIODIC);
TimerLoadSet(TIMER0_BASE, TIMER_B, SysCtlClockGet()/50);
IntEnable(INT_TIMER0B);
TimerIntEnable(TIMER0_BASE, TIMER_TIMB_TIMEOUT);
IntMasterEnable();
TimerIntRegister(TIMER0_BASE, TIMER_B, Timer0IntHandler);
g_ui32Counter = 0;
TimerEnable(TIMER0_BASE, TIMER_B);
while(1){
if(ui32PrevCount != g_ui32Counter)
{
UARTprintf("Number of interrupts : %d\r",g_ui32Counter);
ui32PrevCount = g_ui32Counter;
ROM_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0);
}
}
}
void Timer0IntHandler(void)
{
//
// Clear the timer interrupt.
//
TimerIntClear(TIMER0_BASE, TIMER_TIMB_TIMEOUT);
g_ui32Counter++;
/*if(g_ui32Counter == NUMBER_OF_INTS)
{
// Read the current state of the GPIO pin and
// write back the opposite state
IntDisable(INT_TIMER0B);
TimerIntDisable(TIMER0_BASE, TIMER_TIMB_TIMEOUT);
TimerIntClear(TIMER0_BASE, TIMER_TIMB_TIMEOUT);
}*/
ROM_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0);
}

