先试试里面的DEMO blink,效果可以。
收到板子时候DEMO是LED闪缩,按下按钮剩下对应的LED闪缩,接下来完成它。
开发板上按钮
KEY1----PB04
KEY2----PA06
LED
LED1----PB03
LED2----PB02
在blink示例基础上编写代码
/******************************************************************************/
/** \file main.c
**
** A detailed description is available at
** @link Sample Group Some description @endlink
**
** - 2021-03-12 1.0 xiebin First version for Device Driver Library of Module.
**
******************************************************************************/
/*******************************************************************************
*
* 代码许可和免责信息
* 武汉芯源半导体有限公司授予您使用所有编程代码示例的非专属的版权许可,您可以由此
* 生成根据您的特定需要而定制的相似功能。根据不能被排除的任何法定保证,武汉芯源半
* 导体有限公司及其程序开发商和供应商对程序或技术支持(如果有)不提供任何明示或暗
* 含的保证或条件,包括但不限于暗含的有关适销性、适用于某种特定用途和非侵权的保证
* 或条件。
* 无论何种情形,武汉芯源半导体有限公司及其程序开发商或供应商均不对下列各项负责,
* 即使被告知其发生的可能性时,也是如此:数据的丢失或损坏;直接的、特别的、附带的
* 或间接的损害,或任何后果性经济损害;或利润、业务、收入、商誉或预期可节省金额的
* 损失。
* 某些司法辖区不允许对直接的、附带的或后果性的损害有任何的排除或限制,因此某些或
* 全部上述排除或限制可能并不适用于您。
*
*******************************************************************************/
/******************************************************************************
* Include files
******************************************************************************/
#include "../inc/main.h"
/******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
//LED
#define LED1_GPIO_PORT CW_GPIOB
#define LED1_GPIO_PIN GPIO_PIN_3
#define LED2_GPIO_PORT CW_GPIOB
#define LED2_GPIO_PIN GPIO_PIN_2
//KEY
//KEY
#define KEY1_GPIO_PIN GPIO_PIN_4
#define KEY1_GPIO_PORT CW_GPIOB
#define KEY2_GPIO_PIN GPIO_PIN_6
#define KEY2_GPIO_PORT CW_GPIOA
/******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/******************************************************************************
* Local variable definitions ('static') *
******************************************************************************/
/******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/*****************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
void Delay(uint16_t nCount);
volatile uint8_t gKey1Status,gKey2Status;
/**
******************************************************************************
** \brief Main function of project
**
** \return uint32_t return value, if needed
**
**
**
******************************************************************************/
int32_t main(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
SYSCTRL_HSI_Enable(SYSCTRL_HSIOSC_DIV12);
__SYSCTRL_GPIOA_CLK_ENABLE();
__SYSCTRL_GPIOB_CLK_ENABLE();
GPIO_InitStruct.IT = GPIO_IT_NONE;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pins = LED1_GPIO_PIN;
GPIO_Init(LED1_GPIO_PORT, &GPIO_InitStruct);
GPIO_InitStruct.Pins = LED2_GPIO_PIN;
GPIO_Init(LED2_GPIO_PORT, &GPIO_InitStruct);
GPIO_InitStruct.Mode = GPIO_MODE_INPUT_PULLUP;
GPIO_InitStruct.IT = GPIO_IT_FALLING;
GPIO_InitStruct.Pins = KEY1_GPIO_PIN;
GPIO_Init(KEY1_GPIO_PORT, &GPIO_InitStruct);
GPIO_InitStruct.Pins = KEY2_GPIO_PIN;
GPIO_Init(KEY2_GPIO_PORT, &GPIO_InitStruct);
GPIOA_INTFLAG_CLR(bv6);
NVIC_EnableIRQ(GPIOA_IRQn);
GPIOB_INTFLAG_CLR(bv4);
NVIC_EnableIRQ(GPIOB_IRQn);
while (1)
{
if( (gKey1Status == 1) && (gKey2Status == 0) )
{
GPIO_TogglePin(LED1_GPIO_PORT, LED1_GPIO_PIN);
GPIO_WritePin(LED2_GPIO_PORT,LED2_GPIO_PIN,GPIO_Pin_RESET);
}
else if( (gKey1Status == 0) && (gKey2Status == 1) )
{
GPIO_TogglePin(LED2_GPIO_PORT, LED2_GPIO_PIN);
GPIO_WritePin(LED1_GPIO_PORT,LED1_GPIO_PIN,GPIO_Pin_RESET);
}
else
{
GPIO_TogglePin(LED1_GPIO_PORT, LED1_GPIO_PIN);
Delay(0xFFFF);
GPIO_TogglePin(LED2_GPIO_PORT, LED2_GPIO_PIN);
}
Delay(0xFFFF);
}
}
/**
* @brief 简单延时
*
* @param nCount
*/
void Delay(__IO uint16_t nCount)
{
/* Decrement nCount value */
while (nCount != 0)
{
nCount--;
}
}
void GPIOB_IRQHandlerCallback(void)
{
if (CW_GPIOB->ISR_f.PIN4)
{
gKey1Status = 1;
gKey2Status = 0;
GPIOB_INTFLAG_CLR(bv4);
}
}
void GPIOA_IRQHandlerCallback(void)
{
if (CW_GPIOA->ISR_f.PIN6)
{
gKey1Status = 0;
gKey2Status = 1;
GPIOA_INTFLAG_CLR(bv6);
}
}
/******************************************************************************
* EOF (not truncated)
******************************************************************************/
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif
将中断回调函数传入中断函数入口。
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file interrupts.c
* @brief Interrupt Service Routines.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2021 CW.
* All rights reserved.</center></h2>
*
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "../inc/interrupts_cw32l010.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */
/* USER CODE END TD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
extern void GPIOA_IRQHandlerCallback(void);
extern void GPIOB_IRQHandlerCallback(void);
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/* External variables --------------------------------------------------------*/
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/******************************************************************************/
/* Cortex-M0P Processor Interruption and Exception Handlers */
/******************************************************************************/
/**
* @brief This function handles Non maskable interrupt.
*/
void NMI_Handler(void)
{
/* USER CODE BEGIN NonMaskableInt_IRQn */
/* USER CODE END NonMaskableInt_IRQn */
}
/**
* @brief This function handles Hard fault interrupt.
*/
void HardFault_Handler(void)
{
/* USER CODE BEGIN HardFault_IRQn */
/* USER CODE END HardFault_IRQn */
while (1)
{
/* USER CODE BEGIN W1_HardFault_IRQn */
/* USER CODE END W1_HardFault_IRQn */
}
}
/**
* @brief This function handles System service call via SWI instruction.
*/
void SVC_Handler(void)
{
/* USER CODE BEGIN SVCall_IRQn */
/* USER CODE END SVCall_IRQn */
}
/**
* @brief This function handles Pendable request for system service.
*/
void PendSV_Handler(void)
{
/* USER CODE BEGIN PendSV_IRQn */
/* USER CODE END PendSV_IRQn */
}
/******************************************************************************/
/* CW030 Peripheral Interrupt Handlers */
/* Add here the Interrupt Handlers for the used peripherals. */
/* For the available peripheral interrupt handler names, */
/* please refer to the startup file (startup_ps030.s). */
/***************************** |