【目的】创建自定义的模版

灵动微官网给出了官方的示例,可以方便的实现示例的展示:

forum.jpg

但是如果直接在示例上修改,特别往往会不小心把示例修改,不方便回看,因为建立自己的模版非常重要。

【创建模版】

新建一个文件夹:

forum.jpg

2、新建keil工程选择该文件夹,并输入工程名称:

forum.jpg

选择MCU为MM32G0001ATC:

forum.jpg

在文件里新建APP文件夹用于存放工程的用户文件。

forum.jpg

复制官方示例文件夹Device到项目文件夹下:

forum.jpg

在Keil下面新建APP、HAL_LIB、STARTUP项目

forum.jpg

分别按下图添加文件:

forum.jpg

forum.jpg

从官方的示例中复制如下文件到APP文件内,并添到APP项目内:

forum.jpg

forum.jpg

添加文件路径到工程之中:

forum.jpg

到此工程模版组建成功。

编写main.c文件内容如下:


  • /* Define to prevent recursive inclusion */
  • #define _MAIN_C_

  • /* Files include */

  • #include "main.h"
  • #include "platform.h"

  • /**
  •   * @addtogroup MM32G0001_LibSamples
  •   * @{
  •   */

  • /**
  •   * @addtogroup GPIO
  •   * @{
  •   */

  • /**
  •   * @addtogroup GPIO_LED_Toggle
  •   * @{
  •   */

  • /* Private typedef ****************************************************************************************************/

  • /* Private define *****************************************************************************************************/

  • /* Private macro ******************************************************************************************************/

  • /* Private variables **************************************************************************************************/

  • /* Private functions **************************************************************************************************/
  • /***********************************************************************************************************************
  •   * @brief
  •   * @note   none
  •   * @param  none
  •   * @retval none
  •   *********************************************************************************************************************/
  • void GPIO_Configure(void)
  • {
  •     GPIO_InitTypeDef GPIO_InitStruct;

  •     RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOA, ENABLE);

  •     GPIO_StructInit(&GPIO_InitStruct);
  •     GPIO_InitStruct.GPIO_Pin   = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_10 | GPIO_Pin_15;
  •     GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
  •     GPIO_InitStruct.GPIO_Mode  = GPIO_Mode_Out_PP;
  •     GPIO_Init(GPIOA, &GPIO_InitStruct);

  •     GPIO_WriteBit(GPIOA, GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_10 | GPIO_Pin_15, Bit_SET);
  • }

  • /***********************************************************************************************************************
  •   * @brief
  •   * @note   none
  •   * @param  none
  •   * @retval none
  •   *********************************************************************************************************************/
  • void GPIO_IO_Toggle(GPIO_TypeDef *GPIOn, uint16_t PINn)
  • {
  •     if (Bit_RESET == GPIO_ReadOutputDataBit(GPIOn, PINn))
  •     {
  •         GPIO_SetBits(GPIOn, PINn);
  •     }
  •     else
  •     {
  •         GPIO_ResetBits(GPIOn, PINn);
  •     }
  • }

  • /***********************************************************************************************************************
  •   * @brief
  •   * @note   none
  •   * @param  none
  •   * @retval none
  •   *********************************************************************************************************************/
  • void GPIO_LED_Toggle_Sample(void)
  • {
  •     //printf("\r\nTest %s", __FUNCTION__);

  •     GPIO_Configure();

  •     while (1)
  •     {
  •         GPIO_IO_Toggle(GPIOA, GPIO_Pin_5);
  •         GPIO_IO_Toggle(GPIOA, GPIO_Pin_6);
  •         GPIO_IO_Toggle(GPIOA, GPIO_Pin_10);
  •         GPIO_IO_Toggle(GPIOA, GPIO_Pin_15);

  •         PLATFORM_DelayMS(100);
  •     }
  • }

  • /***********************************************************************************************************************
  •   * @brief  This function is main entrance
  •   * @note   main
  •   * @param  none
  •   * @retval none
  •   *********************************************************************************************************************/
  • int main(void)
  • {
  •                 PLATFORM_Init();
  •                 GPIO_LED_Toggle_Sample();
  •     while (1)
  •     {
  •                        
  •     }
  • }
  • 复制代码

    下载到开发板就可以实现灯的闪烁了。

    复制这个文件夹,以后就可以在这个工程中修改了。附工程如下:

    mypro_template.zip (411.1 KB, 下载次数: 2)

    全部回复 0
    暂无评论,快来抢沙发吧