文章目录目标建立工程ProcessorExpert配置代码拖动和补全调试设置工程源码
目标
通过定时器每1s翻转一次 LED_GREEN(引脚PTE22) 的亮灭状态.
建立工程
步骤:
File -> New -> S32DS Application Project
Processors 选择 S32K148, Project Name 填你自己的工程名
Select SDK: SDKs 选择 S32K148_SDK 3.0.0, Finish
ProcessorExpert配置
双击工程名, 点击Components窗口Components目录下的 pin_mux:PinSetting
, 设置绿色LED引脚PTE22为输出:
导入lpit组件:
双击Components窗口Components目录下的 lpit1:lpit
:
此处周期单元选择了us, 周期1000000us, 也就是1s, 使能中断.
到此配置完毕, 点击生成代码:
代码拖动和补全
打开 main.c
, 函数可以从Components中的组件展开直接用鼠标拖入, 然后补全代码即可:
/* Including necessary module. Cpu.h contains other modules needed for compiling.*/
#include "Cpu.h"volatile int exit_code = 0;
/* User includes (#include below this line is not maintained by Processor Expert) */
#define LED0_PIN_INDEX 22U
#define LED_GPIO_PORT PTE#define LPIT_CHANNEL 0UL
#define LPIT_Channel_IRQn LPIT0_Ch0_IRQnvoid LPIT_Callback(void) {
LPIT_DRV_ClearInterruptFlagTimerChannels(INST_LPIT1, (1 << LPIT_CHANNEL));
PINS_DRV_TogglePins(LED_GPIO_PORT, (1 << LED0_PIN_INDEX));
}
/*!
\brief The main function for the project.
\details The startup initialization sequence is the following:
* - startup asm routine
* - main()
*/
int main(void)
{
/* Write your local variable definition here *//*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
#ifdef PEX_RTOS_INIT
PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of Processor Expert internal initialization. ***//* Write your code here */
/* For example: for(;;) { } */
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT, g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
PINS_DRV_SetPinsDirection(LED_GPIO_PORT, (1 << LED0_PIN_INDEX));
PINS_DRV_WritePin(LED_GPIO_PORT, LED0_PIN_INDEX, 1);LPIT_DRV_Init(INST_LPIT1, &lpit1_InitConfig);
LPIT_DRV_InitChannel(INST_LPIT1, LPIT_CHANNEL, &lpit1_ChnConfig0);
INT_SYS_InstallHandler(LPIT_Channel_IRQn, &LPIT_Callback, (isr_t *)0);
LPIT_DRV_StartTimerChannels(INST_LPIT1, (1 << LPIT_CHANNEL));/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
#ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of RTOS startup code. ***/
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
for(;;) {
if(exit_code != 0) {
break;
}
}
return exit_code;
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***//* END main */
时钟:
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT, g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);
IO:
#define LED0_PIN_INDEX 22U
#define LED_GPIO_PORT PTEPINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
PINS_DRV_SetPinsDirection(LED_GPIO_PORT, (1 << LED0_PIN_INDEX));
PINS_DRV_WritePin(LED_GPIO_PORT, LED0_PIN_INDEX, 1); //点亮LED
定时器:
#define LPIT_CHANNEL 0UL
#define LPIT_Channel_IRQn LPIT0_Ch0_IRQnvoid LPIT_Callback(void) {
LPIT_DRV_ClearInterruptFlagTimerChannels(INST_LPIT1, (1 << LPIT_CHANNEL));
PINS_DRV_TogglePins(LED_GPIO_PORT, (1 << LED0_PIN_INDEX));
}LPIT_DRV_Init(INST_LPIT1, &lpit1_InitConfig);
LPIT_DRV_InitChannel(INST_LPIT1, LPIT_CHANNEL, &lpit1_ChnConfig0);
INT_SYS_InstallHandler(LPIT_Channel_IRQn, &LPIT_Callback, (isr_t *)0); //回调函数
LPIT_DRV_StartTimerChannels(INST_LPIT1, (1 << LPIT_CHANNEL));
调试设置参考前篇, 此处略.
工程源码
https://download.csdn.net/download/weifengdq/11813519
原创:https://www.panoramacn.com
源码网提供WordPress源码,帝国CMS源码discuz源码,微信小程序,小说源码,杰奇源码,thinkphp源码,ecshop模板源码,微擎模板源码,dede源码,织梦源码等。专业搭建小说网站,小说程序,杰奇系列,微信小说系列,app系列小说
免责声明,若由于商用引起版权纠纷,一切责任均由使用者承担。
您必须遵守我们的协议,如果您下载了该资源行为将被视为对《免责声明》全部内容的认可-> 联系客服 投诉资源www.panoramacn.com资源全部来自互联网收集,仅供用于学习和交流,请勿用于商业用途。如有侵权、不妥之处,请联系站长并出示版权证明以便删除。 敬请谅解! 侵权删帖/违法举报/投稿等事物联系邮箱:2640602276@qq.com未经允许不得转载:书荒源码源码网每日更新网站源码模板! » S32K148_ProcessorExpert之定时器中断
关注我们小说电影免费看关注我们,获取更多的全网素材资源,有趣有料!120000+人已关注
评论抢沙发