3.按键
GPIO读取函数为
DL_GPIO_readPins(PORTA_PORT,PORTA_KEY1_PIN);
注意这个函数的返回值为GPIO的地址,如DL_GPIO_PIN_18对应0x00040000,DL_GPIO_PIN_19对应0x00080000等。
故对引脚电平的读取应为
/*----------------------------读取方式1------------------------------*/
/* 高电平的判断方式 */
if (DL_GPIO_readPins(KEY2_PORT, KEY2_PIN2_PIN) > 0) // 若引脚为高电平
{
/* 用户代码 */
}
/*----------------------------读取方式2------------------------------*/
/* 低电平的判断方式 */
if (DL_GPIO_readPins(KEY2_PORT, KEY2_PIN2_PIN) == 0) // 若引脚为低电平
{
/* 用户代码 */
}
/*----------------------------读取方式3------------------------------*/
/* 高、低电平的判断方式 */
if (DL_GPIO_readPins(KEY2_PORT, KEY2_PIN2_PIN)) // 若引脚为高电平
{
/* 用户代码 */
}
else // 不是高电平,那就是低电平
{
/* 用户代码 */
}
/*-------------------------------------------------------------------*/
4.定时器
!!!注:这里的中断使能触发事件一定要选择,否则不会进入中断
中断服务例程的命名:
/* Defines for TIMER_1S */
#define TIMER_1S_INST (TIMA1)
#define TIMER_1S_INST_IRQHandler TIMA1_IRQHandler
#define TIMER_1S_INST_INT_IRQN (TIMA1_INT_IRQn)
#define TIMER_1S_INST_LOAD_VALUE (49999U)
/* Defines for TIMER_1MS */
#define TIMER_1MS_INST (TIMA0)
#define TIMER_1MS_INST_IRQHandler TIMA0_IRQHandler
#define TIMER_1MS_INST_INT_IRQN (TIMA0_INT_IRQn)
#define TIMER_1MS_INST_LOAD_VALUE (99U)
例如:
void TIMER_1S_INST_IRQHandler(void)
void TIMER_1MS_INST_IRQHandler(void)
匹配中断:
typedef enum {
/*! Timer interrupt index for zero interrupt */
DL_TIMER_IIDX_ZERO = GPTIMER_CPU_INT_IIDX_STAT_Z,
/*! Timer interrupt index for load interrupt */
DL_TIMER_IIDX_LOAD = GPTIMER_CPU_INT_IIDX_STAT_L,
/*! Timer interrupt index for compare 0 down interrupt */
DL_TIMER_IIDX_CC0_DN = GPTIMER_CPU_INT_IIDX_STAT_CCD0,
/*! Timer interrupt index for compare 1 down interrupt */
DL_TIMER_IIDX_CC1_DN = GPTIMER_CPU_INT_IIDX_STAT_CCD1,
/*! Timer interrupt index for compare 2 down interrupt */
DL_TIMER_IIDX_CC2_DN = GPTIMER_CPU_INT_IIDX_STAT_CCD2,
/*! Timer interrupt index for compare 3 down interrupt */
DL_TIMER_IIDX_CC3_DN = GPTIMER_CPU_INT_IIDX_STAT_CCD3,
/*! Timer interrupt index for compare 0 up interrupt */
DL_TIMER_IIDX_CC0_UP = GPTIMER_CPU_INT_IIDX_STAT_CCU0,
/*! Timer interrupt index for compare 1 up interrupt */
DL_TIMER_IIDX_CC1_UP = GPTIMER_CPU_INT_IIDX_STAT_CCU1,
/*! Timer interrupt index for compare 2 up interrupt */
DL_TIMER_IIDX_CC2_UP = GPTIMER_CPU_INT_IIDX_STAT_CCU2,
/*! Timer interrupt index for compare 3 up interrupt */
DL_TIMER_IIDX_CC3_UP = GPTIMER_CPU_INT_IIDX_STAT_CCU3,
/*! Timer interrupt index for compare 4 down interrupt */
DL_TIMER_IIDX_CC4_DN = GPTIMER_CPU_INT_IIDX_STAT_CCD4,
/*! Timer interrupt index for compare 5 down interrupt */
DL_TIMER_IIDX_CC5_DN = GPTIMER_CPU_INT_IIDX_STAT_CCD5,
/*! Timer interrupt index for compare 4 up interrupt */
DL_TIMER_IIDX_CC4_UP = GPTIMER_CPU_INT_IIDX_STAT_CCU4,
/*! Timer interrupt index for compare 5 up interrupt */
DL_TIMER_IIDX_CC5_UP = GPTIMER_CPU_INT_IIDX_STAT_CCU5,
/*! Timer interrupt index for fault interrupt */
DL_TIMER_IIDX_FAULT = GPTIMER_CPU_INT_IIDX_STAT_F,
/*! Timer interrupt index for timer overflow interrupt */
DL_TIMER_IIDX_OVERFLOW = GPTIMER_CPU_INT_IIDX_STAT_TOV,
/*! Timer interrupt index for repeat counter
* @note <b> This is a Timer A specific interrupt. </b>
*/
DL_TIMER_IIDX_REPEAT_COUNT = GPTIMER_CPU_INT_IIDX_STAT_REPC,
/*! Timer interrupt index for direction change interrupt
* @note <b> Please refer the Timer TRM to determine TIMG instances which
* support this feature. </b> */
DL_TIMER_IIDX_DIR_CHANGE = GPTIMER_CPU_INT_IIDX_STAT_DC,
} DL_TIMER_IIDX;
示例程序:
#include "ti_msp_dl_config.h"
#define DELAY (16000000)
int i = 0;
int main(void)
{
SYSCFG_DL_init();//芯片资源初始化,由sysconfig配置
NVIC_EnableIRQ(TIMER_0_INST_INT_IRQN);//开启中断管理
DL_TimerA_startCounter(TIMER_0_INST);//开启定时器
DL_GPIO_setPins(LED_PORT,LED_LED0_PIN);//LED初始状态
while(1)
{
}
}
//TIMER_0中断服务例程
void TIMER_0_INST_IRQHandler(void)
{
switch (DL_TimerA_getPendingInterrupt(TIMER_0_INST))
{
case DL_TIMER_IIDX_ZERO:
DL_GPIO_togglePins(LED_PORT,LED_LED0_PIN);
i++;
break;
}
//在只开启单个定时器的情况下,不使用switch也可以
//DL_GPIO_togglePins(LED_PORT,LED_LED0_PIN);
//i++;
}