|
今日用LM3S615做了一个定时是中断程序,是用别人的稍加修改过来的,可是把程序下载的板上观看,定时器中断是执行了,可当定时器执行后,好像定时器没有被清零一样就死在那里了,中断服务函数里的语句和主函数里的语句都不执行了。查了查程序感觉没什么问题,一时半会找不去原因来,现把程序贴上,望各位帮忙看看。
#include "systemInit.h"
#include <timer.h>
// 定义LED
#define LED_PERIPH SYSCTL_PERIPH_GPIOC
#define LED_PORT GPIO_PORTC_BASE
#define LED_PIN GPIO_PIN_5
#define LED_TIM GPIO_PIN_4
#define ledOn() GPIOPinWrite(LED_PORT , LED_PIN , 0x00 << 5)
#define ledOff() GPIOPinWrite(LED_PORT , LED_PIN , 0x01 << 5)
#define ledToggle() GPIOPinWrite(LED_PORT , LED_PIN , ~GPIOPinRead(LED_PORT , LED_PIN))
// 延时
void delay(unsigned long ulVal)
{
while ( --ulVal != 0 );
}
// 主函数(程序入口)
int main(void)
{
jtagWait(); // To prevent JTAG failure,important!
clockInit(); // System Initialization
SysCtlPeriEnable(LED_PERIPH); // Enable LED in GPIO Port
GPIOPinTypeOut(LED_PORT, LED_PIN|LED_TIM); // Setting Output For LED Foot
SysCtlPeriEnable(SYSCTL_PERIPH_TIMER0); // Enable the peripherals used by this example
IntMasterEnable(); // Enable processor interrupts.
TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER); // Configure the two 32-bit periodic timers
TimerLoadSet(TIMER0_BASE, TIMER_A, 3000000UL); // Set the Timer0A load value to 500ms
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // Configure the Timer0A interrupt for timer timeout
TimerEnable(TIMER0_BASE, TIMER_A); // Enable the Timer0A.
IntEnable(INT_TIMER0A); // Enable the Timer0A interrupt on the processor (NVIC).
for (;;)
{
ledOn(); // Lit LED
delay(300 * (TheSysClock / 4000)); // Delay 300ms
ledOff(); // Extinguished LED
delay(300 * (TheSysClock / 4000)); // Delay 300ms
}
}
// 定时器的中断服务函数
void Timer0A_ISR(void)
{
unsigned char ucVal;
unsigned long ulStatus;
ulStatus = TimerIntStatus(TIMER0_BASE, true); // 读取中断状态
TimerIntClear(TIMER0_BASE, ulStatus); // 清除中断状态,重要!
if (ulStatus & TIMER_TIMA_TIMEOUT) // 如果是Timer超时中断
{
ucVal = GPIOPinRead(LED_PORT, LED_TIM); // 反转LED
GPIOPinWrite(LED_PORT, LED_TIM, ~ucVal);
}
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|