CW32L010F8P6_StartKit_Schematic_V1.0.pdf
(100.55 KB)
CW32L010F8P6_StartKit_UserManual_CN_V1.0.pdf
(4.19 MB)
下载手册,并下载LIB
https://www.whxy.com/uploads/fil ... heralLib_V1.0.2.zip
先试试里面的DEMO blink,效果可以。
收到板子时候DEMO是LED闪缩,按下按钮剩下对应的LED闪缩,接下来完成它。
开发板上按钮
KEY1----PB04
KEY2----PA06
LED
LED1----PB03
LED2----PB02
在blink示例基础上编写代码
/******************************************************************************/
/** \file main.c
**
** A detailed description is available at
** [url=home.php?mod=space&uid=48136]@link[/url] 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);
}
}
/**
* [url=home.php?mod=space&uid=247401]@brief[/url] 简单延时
*
* @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 */
/**
******************************************************************************
* [url=home.php?mod=space&uid=288409]@file[/url] 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). */
/******************************************************************************/
/**
* @brief This funcation handles WDT
*/
void WDT_IRQHandler(void)
{
/* USER CODE BEGIN */
/* USER CODE END */
}
/**
* @brief This funcation handles LVD
*/
void LVD_IRQHandler(void)
{
/* USER CODE BEGIN */
/* USER CODE END */
}
/**
* @brief This funcation handles RTC
*/
void RTC_IRQHandler(void)
{
/* USER CODE BEGIN */
/* USER CODE END */
}
/**
* @brief This funcation handles FLASHRAM
*/
void FLASHRAM_IRQHandler(void)
{
/* USER CODE BEGIN */
/* USER CODE END */
}
/**
* @brief This funcation handles SYSCTRL
*/
void SYSCTRL_IRQHandler(void)
{
/* USER CODE BEGIN */
/* USER CODE END */
}
/**
* @brief This funcation handles GPIOA
*/
void GPIOA_IRQHandler(void)
{
/* USER CODE BEGIN */
GPIOA_IRQHandlerCallback();
/* USER CODE END */
}
/**
* @brief This funcation handles GPIOB
*/
void GPIOB_IRQHandler(void)
{
/* USER CODE BEGIN */
GPIOB_IRQHandlerCallback();
/* USER CODE END */
}
/**
* @brief This funcation handles ADC
*/
void ADC_IRQHandler(void)
{
/* USER CODE BEGIN */
/* USER CODE END */
}
/**
* @brief This funcation handles ATIM
*/
void ATIM_IRQHandler(void)
{
/* USER CODE BEGIN */
/* USER CODE END */
}
/**
* @brief This funcation handles VC1
*/
void VC1_IRQHandler(void)
{
/* USER CODE BEGIN */
/* USER CODE END */
}
/**
* @brief This funcation handles VC2
*/
void VC2_IRQHandler(void)
{
/* USER CODE BEGIN */
/* USER CODE END */
}
/**
* @brief This funcation handles GTIM1
*/
void GTIM1_IRQHandler(void)
{
/* USER CODE BEGIN */
/* USER CODE END */
}
/**
* @brief This funcation handles LPTIM
*/
void LPTIM_IRQHandler(void)
{
/* USER CODE BEGIN */
/* USER CODE END */
}
/**
* @brief This funcation handles BTIM1
*/
void BTIM1_IRQHandler(void)
{
/* USER CODE BEGIN */
/* USER CODE END */
}
/**
* @brief This funcation handles BTIM2
*/
void BTIM2_IRQHandler(void)
{
/* USER CODE BEGIN */
/* USER CODE END */
}
/**
* @brief This funcation handles BTIM3
*/
void BTIM3_IRQHandler(void)
{
/* USER CODE BEGIN */
/* USER CODE END */
}
/**
* @brief This funcation handles I2C1
*/
void I2C1_IRQHandler(void)
{
/* USER CODE BEGIN */
/* USER CODE END */
}
/**
* @brief This funcation handles SPI1
*/
void SPI1_IRQHandler(void)
{
/* USER CODE BEGIN */
/* USER CODE END */
}
/**
* @brief This funcation handles UART1
*/
void UART1_IRQHandler(void)
{
/* USER CODE BEGIN */
/* USER CODE END */
}
/**
* @brief This funcation handles UART2
*/
void UART2_IRQHandler(void)
{
/* USER CODE BEGIN */
/* USER CODE END */
}
/**
* @brief This funcation handles FAULT
*/
void CLKFAULT_IRQHandler(void)
{
/* USER CODE BEGIN */
/* USER CODE END */
}
/************************ (C) COPYRIGHT CW *****END OF FILE****/
编译烧录,功能正常,复位后两个都在闪烁。按下KEY1后只有KEY1在闪烁,按下KEY2后,只有KEY2在闪烁。
|