1_S32K118_按键中断(S32 Studio for arm)

该代码示例展示了在S32K118开发板上使用S32StudioforARM2.2SDK3.0.0进行中断处理的实现。主要功能包括时钟和引脚初始化,以及对三个按键中断的处理,当按键被按下时,对应的LED灯会闪烁。
摘要由CSDN通过智能技术生成

@TOC

  • 品智科技S32K118开发板
  • S32 STUDIO FOR ARM 2.2
  • SDK 3.0.0
    • pin_mux
    • clockMan
    • osif

PE设置

在这里插入图片描述
在这里插入图片描述

按键中断代码

/* ###################################################################
 **     Filename    : main.c
 **     Processor   : S32K1xx
 **     Abstract    :
 **         Main module.
 **         This module contains user's application code.
 **     Settings    :
 **     Contents    :
 **         No public methods
 **
 ** ###################################################################*/
/*!
 ** @file main.c
 ** @version 01.00
 ** @brief
 **         Main module.
 **         This module contains user's application code.
 */
/*!
 **  @addtogroup main_module main module documentation
 **  @{
 */
/* MODULE main */


/* 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) */

/*按键中断函数*/
static void SW_IRQHandler(void)
{
	if(PINS_DRV_GetPortIntFlag(PORTC) & (1 << KEY1_PIN))
	{
		PINS_DRV_TogglePins(LED_1_B_PORT, 1 << LED_1_B_PIN);
	}else if(PINS_DRV_GetPortIntFlag(PORTC) & (1 << KEY2_PIN))
	{
		PINS_DRV_TogglePins(LED_2_G_PORT, 1 << LED_2_G_PIN);
	}else if(PINS_DRV_GetPortIntFlag(PORTC) & (1 << KEY3_PIN))
	{
		PINS_DRV_TogglePins(LED_3_R_PORT, 1 << LED_3_R_PIN);
	}

	PINS_DRV_ClearPortIntFlagCmd(PORTC);
}

/*! 
  \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);

	/* 使能3个按键中断*/
	INT_SYS_InstallHandler(PORT_IRQn, SW_IRQHandler, (isr_t *)NULL);
	INT_SYS_EnableIRQ(PORT_IRQn);
	
	PINS_DRV_WritePin(LED_1_B_PORT, LED_1_B_PIN, 1);
	PINS_DRV_WritePin(LED_2_G_PORT, LED_2_G_PIN, 0);
	PINS_DRV_WritePin(LED_3_R_PORT, LED_3_R_PIN, 1);
	PINS_DRV_WritePin(LED_4_Y_PORT, LED_4_Y_PIN, 0);


	for (;;)
	{
#if 1

		PINS_DRV_TogglePins(LED_4_Y_PORT, 1 << LED_4_Y_PIN);
		OSIF_TimeDelay(100);
	}
	/*** 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 */
/*!
 ** @}
 */
/*
 ** ###################################################################
 **
 **     This file was created by Processor Expert 10.1 [05.21]
 **     for the NXP S32K series of microcontrollers.
 **
 ** ###################################################################
 */

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值