CW32L010F8P6_StartKit_Schematic_V1.0.pdf
(100.55 KB, 下载次数: 8)
CW32L010F8P6_StartKit_UserManual_CN_V1.0.pdf
(4.19 MB, 下载次数: 3)
下载手册,并下载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
将中断回调函数传入中断函数入口。
编译烧录,功能正常,复位后两个都在闪烁。按下KEY1后只有KEY1在闪烁,按下KEY2后,只有KEY2在闪烁。
|