Ti가 매우 친절한 이유는 개발 환경에 대한 대부분을 오픈 시켜서 빠르게 스터디가 가능해요.
그 중 당연 으뜸은 예제프로그램이죠.. ^^;;;
해당 코드는 예제프로그램을 보고 진행하였습니다.
#include "driverlib.h"
#include "device.h"
uint16_t cpuTimer0IntCount;
__interrupt void cpuTimer0ISR(void);
void initCPUTimers(void);
void configCPUTimer(uint32_t, float, float);
void main(void)
{
Device_init();
Device_initGPIO();
Interrupt_initModule();
Interrupt_initVectorTable();
Interrupt_register(INT_TIMER0, &cpuTimer0ISR); // ISR
initCPUTimers();
configCPUTimer(CPUTIMER0_BASE, DEVICE_SYSCLK_FREQ, 100000); // Interrupt every 100 ms
CPUTimer_enableInterrupt(CPUTIMER0_BASE);
Interrupt_enable(INT_TIMER0);
CPUTimer_startTimer(CPUTIMER0_BASE);
EINT; // Enable Global Interrupt
ERTM; // Enable Realtime Interrupt
while(1)
{
}
}
void initCPUTimers(void)
{
//
// Initialize timer period to maximum
//
CPUTimer_setPeriod(CPUTIMER0_BASE, 0xFFFFFFFF);
//
// Initialize pre-scale counter to divide by 1 (SYSCLKOUT)
//
CPUTimer_setPreScaler(CPUTIMER0_BASE, 0);
//
// Make sure timer is stopped
//
CPUTimer_stopTimer(CPUTIMER0_BASE);
//
// Reload all counter register with period value
//
CPUTimer_reloadTimerCounter(CPUTIMER0_BASE);
//
// Reset interrupt counter
//
cpuTimer0IntCount = 0;
}
//
// configCPUTimer - This function initializes the selected timer to the
// period specified by the "freq" and "period" parameters. The "freq" is
// entered as Hz and the period in uSeconds. The timer is held in the stopped
// state after configuration.
//
void configCPUTimer(uint32_t cpuTimer, float freq, float period)
{
uint32_t temp;
//
// Initialize timer period:
//
temp = (uint32_t)((freq / 1000000) * period);
CPUTimer_setPeriod(cpuTimer, temp);
//
// Set pre-scale counter to divide by 1 (SYSCLKOUT):
//
CPUTimer_setPreScaler(cpuTimer, 0);
//
// Initializes timer control register. The timer is stopped, reloaded,
// free run disabled, and interrupt enabled.
// Additionally, the free and soft bits are set
//
CPUTimer_stopTimer(cpuTimer);
CPUTimer_reloadTimerCounter(cpuTimer);
CPUTimer_setEmulationMode(cpuTimer, CPUTIMER_EMULATIONMODE_STOPAFTERNEXTDECREMENT);
CPUTimer_enableInterrupt(cpuTimer);
//
// Resets interrupt counters for the three cpuTimers
//
if (cpuTimer == CPUTIMER0_BASE)
{
cpuTimer0IntCount = 0;
}
}
__interrupt void cpuTimer0ISR(void)
{
cpuTimer0IntCount++;
GPIO_togglePin(23U);
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP1);
}
Device SYSCLK Frequency는 20MHz이고 100ms LED ON/OFF 예제입니다.
반응형
'b. 임베디드 > TMS320F28004C' 카테고리의 다른 글
[LaunchXL-F280049C] SCIA 통신 (UART) (0) | 2021.12.10 |
---|---|
[LaunchXL-F280049C] Push Button 스위치 동작 코드 (0) | 2021.12.08 |
[LaunchXL-F280049C] 개발 환경 (0) | 2021.12.07 |