// 这个程序利用TIMER A0生成1KHz的方波,从引脚P1.3输出,送到引脚P7.4,
// 再利用TIMER B0测量周期。为测试方便,引脚P1.0输出32KHz的ACLK,
// 引脚P2.2输出12MHz的SMCLK.
// ACLK = LFXT1 = 32kHz; SMCLK = MCLK = 12MHz
//
// MSP430F5529
// -------------------------
// /|| XT1IN|-
// | | | 32kHz
// --|RST XT1OUT|-
// | |
// | P7.4/TB0.2|<-- CCI2A <-|
// | P1.3/TA0.2|--> CCR2 -->|
// | |
// | | MCLK = 12MHz DCO
// | P2.2|--> SMCLK = 12MHz DCO
// | P1.0|--> ACLK = 32kHz LFXT1
// --------------------------
//******************************************************************************
#include "driverlib.h"
uint16_t REdge1, REdge2, Period, InterCount = 0;
void main(void)
{
// Stop WDT
WDT_A_hold(WDT_A_BASE);
// Configure XT1
GPIO_setAsPeripheralModuleFunctionInputPin(
GPIO_PORT_P5,
GPIO_PIN4 + GPIO_PIN5
);
UCS_turnOnLFXT1 (UCS_XT1_DRIVE_3,
UCS_XCAP_3
);
// Increase Vcore setting to level1 to support fsystem=12MHz
// NOTE: Change core voltage one level at a time..
PMM_setVCore (PMM_CORE_LEVEL_1);
// Initialize DCO to 12MHz
UCS_initFLLSettle(12000,
374);
// Setup Port Pins
//P1.0 --> ACLK
GPIO_setAsPeripheralModuleFunctionOutputPin(
GPIO_PORT_P1,
GPIO_PIN0
);
//P2.2 --> SMCLK
GPIO_setAsPeripheralModuleFunctionOutputPin(
GPIO_PORT_P2,
GPIO_PIN2
);
// Configure ports TB0.2 input and TA0.2 output
// TB0.2 input
// TB0.2 option select
// TA0.2 output
// TA0.2 option select
GPIO_setAsPeripheralModuleFunctionOutputPin(
GPIO_PORT_P1,
GPIO_PIN3
);
GPIO_setAsPeripheralModuleFunctionInputPin(
GPIO_PORT_P7,
GPIO_PIN4
);
// Configure TA0.2 compare output, 1kHz freq, 50% dutycycle
Timer_A_initCompareModeParam initCompParam = {0};
initCompParam.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_2;
initCompParam.compareInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_DISABLE;
initCompParam.compareOutputMode = TIMER_A_OUTPUTMODE_TOGGLE;
initCompParam.compareValue = 16;
Timer_A_initCompareMode(TIMER_A0_BASE, &initCompParam);
Timer_A_initUpModeParam initUpParam = {0};
initUpParam.clockSource = TIMER_A_CLOCKSOURCE_ACLK;
initUpParam.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;
initUpParam.timerPeriod = 16;
initUpParam.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE;
initUpParam.captureCompareInterruptEnable_CCR0_CCIE =
TIMER_A_CAPTURECOMPARE_INTERRUPT_DISABLE;
initUpParam.timerClear = TIMER_A_DO_CLEAR;
initUpParam.startTimer = false;
Timer_A_initUpMode(TIMER_A0_BASE, &initUpParam);
Timer_A_startCounter(TIMER_A0_BASE,
TIMER_A_UP_MODE
);
Timer_B_initContinuousModeParam initContParam = {0};
initContParam.clockSource = TIMER_B_CLOCKSOURCE_SMCLK;
initContParam.clockSourceDivider = TIMER_B_CLOCKSOURCE_DIVIDER_1;
initContParam.timerInterruptEnable_TBIE = TIMER_B_TBIE_INTERRUPT_DISABLE;
initContParam.timerClear = TIMER_B_DO_CLEAR;
Timer_B_initContinuousMode(TIMER_B0_BASE, &initContParam);
Timer_B_startCounter(TIMER_B0_BASE,
TIMER_B_CONTINUOUS_MODE
);
Timer_B_clearCaptureCompareInterrupt(TIMER_B0_BASE,
TIMER_B_CAPTURECOMPARE_REGISTER_2);
Timer_B_initCaptureModeParam initCapParam = {0};
initCapParam.captureRegister = TIMER_B_CAPTURECOMPARE_REGISTER_2;
initCapParam.captureMode = TIMER_B_CAPTUREMODE_RISING_EDGE;
initCapParam.captureInputSelect = TIMER_B_CAPTURE_INPUTSELECT_CCIxA;
initCapParam.synchronizeCaptureSource = TIMER_B_CAPTURE_SYNCHRONOUS;
initCapParam.captureInterruptEnable = TIMER_B_CAPTURECOMPARE_INTERRUPT_ENABLE;
initCapParam.captureOutputMode = TIMER_B_OUTPUTMODE_OUTBITVALUE;
Timer_B_initCaptureMode(TIMER_B0_BASE, &initCapParam);
while(1)
{
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0
__no_operation(); // For debugger
}
}
// Timer0_B1 Interrupt Vector
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMER0_B1_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(TIMER0_B1_VECTOR)))
#endif
void TIMER0_B1_ISR (void)
{
switch(TB0IV)
{
case 0x04://捕捉比较中断2
if(InterCount == 0)
{
REdge1 = Timer_B_getCaptureCompareCount(TIMER_B0_BASE,
TIMER_B_CAPTURECOMPARE_REGISTER_2);
InterCount ++;
}
else
{
REdge2 = Timer_B_getCaptureCompareCount(TIMER_B0_BASE,
TIMER_B_CAPTURECOMPARE_REGISTER_2);
InterCount = 0;
Period = (REdge2 - REdge1);
}
break;
default:
break;
}
__bic_SR_register_on_exit(LPM0_bits); // Exit LPM0
}
上一篇:MSP430F5529LP按键点亮LED灯
下一篇:MSP430f5529LP通过串口数据控制LED亮灭
推荐阅读最新更新时间:2024-11-07 22:55
设计资源 培训 开发板 精华推荐
- LT1935-WITT、1A、5V、SOT-23 升压转换器参考设计可在狭小空间内提供高功率
- MC33074ADR2G 交流耦合反相放大器的典型应用
- #第四届立创大赛#USB-C_PD3.0充电器(40W)
- 使用 Microchip Technology 的 MIC2772-T2T3YML 的参考设计
- 仿gasket结构40%矮轴机械键盘
- 750W 可调 开关电源 / 锂电池充电器/铅酸电池充电器
- LTC1436CGN-PLL 演示板、双路输出稳压器、5.5V 至 28V 输入、5V @ 3A 和 12V @ 0.1A
- 【已验证】莱曼耳放(纯放大板)
- MAP9002,使用 MAP9002 高压交流 LED 驱动器的典型应用电路
- ADR420 超精密、低噪声、5.00 Vout XFET 电压基准作为可编程电流源的典型应用