TIVA C Launchpad (EK-LM4F120XL LaunchPad)让LED闪起来!
[复制链接]
TIVA C Launchpad (EK-LM4F120XL LaunchPad)让LED闪起来!
根据LB4教程,使用定时器中断,使GPIOF口连接的LED闪起来!
添加相关头文件
#include "driverlib/interrupt.h"
#include "driverlib/timer.h"
#include "driverlib/systick.h"
主程序
1、配置系统时钟
2、使能LED连接端口,配置输出
3、配置定时器0,1,W0,都为周期触发!
4、使能全局中断
5、使能定时器中断
int
main(void)
{
long Period;
//
// The FPU should be enabled because some compilers will use floating-
// point registers, even for non-floating-point code. If the FPU is not
// enabled this will cause a fault. This also ensures that floating-
// point operations could be added to this application and would work
// correctly and use the hardware floating-point unit. Finally, lazy
// stacking is enabled for interrupt handlers. This allows floating-
// point instructions to be used within interrupt handlers, but at the
// expense of extra stack usage.
//
FPUEnable();
FPULazyStackingEnable();
//
// Set the clocking to run directly from the crystal.
//配置系统时钟 16M
ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
//
// Enable the peripherals used by this example.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
Period=(ROM_SysCtlClockGet()/10)/2;
ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, Period-1);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);
ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, ROM_SysCtlClockGet() / 1);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER0);// 使能宽64位定时器0外设
ROM_TimerConfigure(WTIMER0_BASE,TIMER_CFG_PERIODIC);//配置64位宽的定时器0
ROM_TimerLoadSet64(WTIMER0_BASE,ROM_SysCtlClockGet()/1);
//
// Enable processor interrupts.
//
ROM_IntMasterEnable();
// Setup the interrupts for the timer timeouts.
//
ROM_IntEnable(INT_TIMER0A);
ROM_IntEnable(INT_TIMER1A);
ROM_IntEnable(INT_WTIMER0A);//使能64位宽的定时器0中断
ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
ROM_TimerIntEnable(WTIMER0_BASE,TIMER_TIMA_TIMEOUT);
//
// Enable the timers.
//
ROM_TimerEnable(TIMER0_BASE, TIMER_A);
ROM_TimerEnable(TIMER1_BASE, TIMER_A);
ROM_TimerEnable(WTIMER0_BASE,TIMER_A);//使能64位宽的定时器0
//
// Loop forever while the timers run.
//
while(1)
{
}
}
|