主题中讨论的其他器件:TM4C1294NCPDT
大家好、
我不是 MCU 的新用户、我尝试每毫秒运行一次计时器、但我找不到设置或计算结果。 我在获取代码之前就附加了我现在用于测试的代码。
有什么关于如何将计时器设置为每毫秒运行的想法?
谢谢大家。 )
#include
#include
#include "inc/tm4c1294ncpdt.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
uint32_t ui32Period、pom = 0;
uint32_t ui32SysClkFreq;
int main (空)
{
ui32SysClkFreq = SysCtlClockFreqSet ((SYSCTL_XTAL_25MHz | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480)、120000000);
SysCtlPeripheralEnable (SYSCTL_Periph_GPION);
SysCtlPeripheralEnable (SYSCTL_Periph_TIMER0);
GPIOPinTypeGPIOOutput (GPIO_PORTN_BASE、GPIO_PIN_1);
TimerConfigure (TIMER0_BASE、TIMER_CFG_PERIODICASE);
ui32Period =(ui32SysClkFreq / 50);
TimerLoadSet (TIMER0_BASE、TIMER_A、ui32Period);
IntEnable (INT_TIMER0A);
TimerIntEnable (TIMER0_BASE、TIMER_TINA_TIMEOUT);
IntMasterEnable();
TimerEnable (TIMER0_BASE、TIMER_A);
while (1)
{
如果(pom = 1000){//if 1000ms = 1秒
IF (GPIOPinRead (GPIO_PORTN_BASE、GPIO_PIN_1))
{
GPIOPinWrite (GPIO_PORTN_BASE、GPIO_PIN_1、0);
POM = 0;
}
其他
{
GPIOPinWrite (GPIO_PORTN_BASE、GPIO_PIN_1、2);
POM = 0;
}
}
}
}
空 Timer0IntHandler (空)
{
TimerIntClear (TIMER0_BASE、TIMER_TINA_TIMEOUT);
POM++;
}