在startup.c中已注册Timer0AIntHandler中断,但调试时进不了中断
#include "C:/StellarisWare/inc/hw_ints.h"
#include "C:/StellarisWare/inc/hw_memmap.h"
#include "C:/StellarisWare/inc/hw_types.h"
// #include "C:/StellarisWare/driverlib/debug.h"
#include "C:/StellarisWare/driverlib/interrupt.h"
#include "C:/StellarisWare/driverlib/sysctl.h"
#include "C:/StellarisWare/driverlib/timer.h"
#include "C:/StellarisWare/grlib/grlib.h"
#include "C:/Program Files/IAR SystemsEmbedded Workbench 6.0 Kickstart/arm/examples/TexasInstruments/Stellaris/boards/dk-lm3s9b96/drivers/kitronix320x240x16_ssd2119_8bit.h"
#include "C:/Program Files/IAR SystemsEmbedded Workbench 6.0 Kickstart/arm/examples/TexasInstruments/Stellaris/boards/dk-lm3s9b96/drivers/set_pinout.h"
#include "C:/Program Files/IAR SystemsEmbedded Workbench 6.0 Kickstart/arm/examples/TexasInstruments/Stellaris/driverlib/gpio.h"
#include "C:/StellarisWare/driverlib/ssi.h"
#include "C:/StellarisWare/inc/hw_ssi.h"
#include "C:/StellarisWare/driverlib/can.h"
#include "C:/StellarisWare/inc/hw_can.h"
#include "C:/StellarisWare/driverlib/udma.h"
#include "C:/StellarisWare/inc/hw_gpio.h"
#include "C:/StellarisWare/driverlib/gpio.h"
// 定时器的中断服务函数
void Timer0AIntHandler(void)
{
unsigned char ucVal;
unsigned long ulStatus;
ulStatus = TimerIntStatus(TIMER0_BASE, true); // 读取中断状态
TimerIntClear(TIMER0_BASE, ulStatus); // 清除中断状态,重要!
if (ulStatus & TIMER_TIMA_TIMEOUT) // 如果是Timer超时中断
{
ucVal = GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_4 ); // 反转LED
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_4, ~ucVal);
}
}
main(void)
{
//jtagWait();
//
//
//设置系统时钟为50Mhz
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
SysCtlClockGet();
PinoutSet();
SysCtlPeripheralReset(SYSCTL_PERIPH_TIMER0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); // 使能Timer模块
TimerConfigure(TIMER0_BASE, TIMER_CFG_16_BIT_PAIR | // 配置Timer为16位周期定时器
TIMER_CFG_A_PERIODIC);
GPIOPinTypeTimer(TIMER0_BASE,TIMER_A);//GPIO_PIN_4,GPIO_DIR_MODE_OUT);
GPIODirModeSet(GPIO_PORTD_BASE, GPIO_PIN_4, GPIO_DIR_MODE_OUT);
GPIOPadConfigSet(GPIO_PORTD_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_4, 0xff);
TimerLoadSet(TIMER0_BASE, TIMER_A, 300000); // 设置Timer初值,定时500ms
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // 使能Timer超时中断
IntEnable(INT_TIMER0A); // 使能Timer中断
IntMasterEnable(); // 使能处理器中断
TimerEnable(TIMER0_BASE, TIMER_A); // 使能Timer计数
while(1)
{}
}
此帖出自
小平头技术问答
void
GPIOPinTypeTimer(unsigned long ulPort,
unsigned char ucPins)
参数:
ulPort是GPIO端口的基址。
ucPins是管脚的位组合(bit-packed)表示。
描述:
CCP管脚必须正确配置,以便定时器外设能够正常工作。这个函数为这些管脚提供了典型配置;其它配置也能正常工作,这取决于板的设置(例如使用了片内上拉)。
管脚用一个位组合(bit-packed)的字节来指定,在这个字节中,置位的位用来识别被访问的管脚,字节的位0代表GPIO端口管脚0、位1代表GPIO端口管脚1等等。
注:这个函数不能将任意管脚都变成一个定时器管脚;它只配置一个定时器管脚来进行正确操作
该如何配置?
一周热门 更多>