1397|8

108

帖子

0

资源

一粒金砂(中级)

【HC32F460开发板测评】02.搭建开发环境、创建工程、实现LED闪烁功能 [复制链接]

本帖最后由 xld0932 于 2021-3-31 22:26 编辑

1、概述

    本篇主要讲述基于HC32F460开发板来搭建开发环境、创建基础工程、编写简单的入门示例,掌握对GPIO输出控制LED灯显示的功能;

2、安装Keil MDK-ARM集成开发环境

2.1.到Keil的官网:https://www.keil.com/download/product/下载最新版本的MDK-ARM软件;

2.2.双击MDK534.EXE来进行软件安装,如下图所示,点击Next:

image.png 2.3.勾选同意事项,然后点击Next,如下图所示:

image.png 2.4.选择软件的安装路径,然后点击Next,如下图所示:

image.png 2.5.填写相应的信息后,点击Next,如下图所示:

image.png 2.6.等待安装完成,如下图所示:

image.png 2.7.软件安装完成后,显示如下图所示界面,点击Finish完成安装:

image.png 2.8.这个时候,会在电脑桌面上自动生成一个Keil uVision的快捷图标,双击这个图标,可以打开Keil MDK-ARM集成开发环境:

image.png

3、安装IDE支持包

3.1.打开HC32F460_IDE_Rev1.0.6压缩包,双击HDSC.HC32F46x.1.0.6进行安装,如下图所示:

11.png 3.2.等待安装完成,点击Finish 12.png

4.创建Keil工程

4.1.双击电脑桌面上的Keil uVision图标,打开Keil MDK-ARM集成开发环境;

4.2.点击菜单栏Project->New uVision Project...

21.png 4.3.在弹出的Create New Project窗口中选择工程需要保存的存储路径,输入工程名称,如下图所示: 22.png

4.4.在弹出的Select Device for Target窗口中,根据开发板上MCU型号,选择MCU型号为HC32F460PET6,然后点击OK,如下图所示:

23.png 4.5.在Manage Run-Time Enviroment窗口中,选择CMSIS中的CORE及Device中的Startup,然后点击OK,如下图所示:

24.png 4.6.这个时候一个空的项目工程就创建好了,这个时候,我们需要在这个空的工程中添加程序文件和对工程进行相应的配置;

4.7.点击工具栏上的Manage Project Items按钮,如下图所示:

25.png 4.8.在弹出的Manage Project Items窗口中,添加工程的Groups分组、每个分组中添加相应程序源文件,然后点击OK,如下图所示:

26.png 4.9.点击工具栏Options for Target对项目工程进行配置,如下图所示:

27.png 4.10.在Target选项卡中,晶振输入8MHz,ARM Compiler选用V5版本,当前不使用硬件浮点、勾选Use MicroLIB选项,如下图所示:

28.png 4.11.在Outout选项卡中,输入编译后项目生成文件的文件名,如下图所示:

29.png 4.12.在C/C++选项卡中,定义相应的宏、添加头文件包含路径;如下图所示:

30.png 31.png

4.13.在Debug选项卡中,选择调试下载工具为J-LINI,点击Settings,选择调试对口为JTAG;当前调试工具与开发处于连接的状态,可以通过如下图所示,工具正常检测到了芯片;如果J-LINK工具无法识别HC32F460的芯片,可以直接选用Cortex-M4核的通用芯片即可;如下图所示:

32.png 32-2.png

4.14在Utilities选项卡中,勾选Use Debug Driver;然后点击Settings,在弹出的对话框中,勾选Reset and Run,点击确定;如下图所示:

33.png 34.png

4.15.到此整个项目的工程就配置完成了,接下来就是编写功能代码了;

5.编程实现LED闪烁功能

5.1.LED.c程序源码

/*******************************************************************************
 * @file    LED.c
 * @author  xld0932
 * @version V1.00
 * @date 31-Mar-2021
 * @brief ......
*******************************************************************************/


/* Define to prevent recursive inclusion -------------------------------------*/
#define __LED_C__


/* Includes ------------------------------------------------------------------*/
#include "LED.h"


/* Private typedef -----------------------------------------------------------*/


/* Private define ------------------------------------------------------------*/
/* LED0 Port/Pin definition */
#define  LED0_PORT        (PortE)
#define  LED0_PIN         (Pin06)

/* LED1 Port/Pin definition */
#define  LED1_PORT        (PortA)
#define  LED1_PIN         (Pin07)

/* LED2 Port/Pin definition */
#define  LED2_PORT        (PortB)
#define  LED2_PIN         (Pin05)

/* LED3 Port/Pin definition */
#define  LED3_PORT        (PortB)
#define  LED3_PIN         (Pin09)


/* Private macro -------------------------------------------------------------*/
/* LED0~3 toggle definition */
#define  LED0_TOGGLE()    (PORT_Toggle(LED0_PORT, LED0_PIN))
#define  LED1_TOGGLE()    (PORT_Toggle(LED1_PORT, LED1_PIN))
#define  LED2_TOGGLE()    (PORT_Toggle(LED2_PORT, LED2_PIN))
#define  LED3_TOGGLE()    (PORT_Toggle(LED3_PORT, LED3_PIN))


/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/


/* Exported variables --------------------------------------------------------*/
/* Exported function prototypes ----------------------------------------------*/


/*******************************************************************************
 * @brief       
 * @param       
 * @retval      
 * @attention *******************************************************************************/
void LED_Init(void)
{
    stc_port_init_t stcPortInit;

    /* configuration structure initialization */
    MEM_ZERO_STRUCT(stcPortInit);

    stcPortInit.enPinMode = Pin_Mode_Out;
    stcPortInit.enExInt   = Enable;
    stcPortInit.enPullUp  = Enable;

    /* LED0 Port/Pin initialization */
    PORT_Init(LED0_PORT, LED0_PIN, &stcPortInit);

    /* LED1 Port/Pin initialization */
    PORT_Init(LED1_PORT, LED1_PIN, &stcPortInit);

    /* LED2 Port/Pin initialization */
    PORT_Init(LED2_PORT, LED2_PIN, &stcPortInit);

    /* LED3 Port/Pin initialization */
    PORT_Init(LED3_PORT, LED3_PIN, &stcPortInit);
}


/*******************************************************************************
 * @brief       
 * @param       
 * @retval      
 * @attention   
*******************************************************************************/
void LED_Toggle(void)
{
    LED0_TOGGLE();  Ddl_Delay1ms(100);
    LED1_TOGGLE();  Ddl_Delay1ms(100);
    LED2_TOGGLE();  Ddl_Delay1ms(100);
    LED3_TOGGLE();  Ddl_Delay1ms(100);
}


/******************* (C) COPYRIGHT 2021 *************************END OF FILE***/

5.2.LED.h程序源码

/*******************************************************************************
 * @file    LED.h
 * @author  xld0932
 * @version V1.00
 * @date    31-Mar-2021
 * @brief   ......
*******************************************************************************/


/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __LED_H__
#define __LED_H__


#ifdef __cplusplus
extern "C" {
#endif


#undef  EXTERN


#ifdef  __LED_C__
#define EXTERN
#else
#define EXTERN extern
#endif


/* Includes ------------------------------------------------------------------*/
#include "config.h"


/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/


/* Exported functions --------------------------------------------------------*/
EXTERN void LED_Init(void);
EXTERN void LED_Toggle(void);


#ifdef __cplusplus
}
#endif


#endif


/******************* (C) COPYRIGHT 2021 *************************END OF FILE***/

5.3.main.c程序源码

/*******************************************************************************
 * @file    main.c
 * @author  xld0932
 * @version V1.00
 * @date    31-Mar-2021
 * @brief   ......
*******************************************************************************/


/* Define to prevent recursive inclusion -------------------------------------*/
#define __MAIN_C__


/* Includes ------------------------------------------------------------------*/
#include "main.h"


/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/


/* Exported variables --------------------------------------------------------*/
/* Exported function prototypes ----------------------------------------------*/


/*******************************************************************************
 * @brief       
 * @param       
 * @retval      
 * @attention   
*******************************************************************************/
int main(void)
{
    LED_Init();

    while(1)
    {
        LED_Toggle();
    }
}


/******************* (C) COPYRIGHT 2021 *************************END OF FILE***/

5.4.需要注意的是,在使用MCU的各个外设时,需要在ddl_config.h配置文件中进行相应的开关设置,如下所示:

/*******************************************************************************
 * Copyright (C) 2016, Huada Semiconductor Co., Ltd. All rights reserved.
 *
 * This software is owned and published by:
 * Huada Semiconductor Co., Ltd. ("HDSC").
 *
 * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
 * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
 *
 * This software contains source code for use with HDSC
 * components. This software is licensed by HDSC to be adapted only
 * for use in systems utilizing HDSC components. HDSC shall not be
 * responsible for misuse or illegal use of this software for devices not
 * supported herein. HDSC is providing this software "AS IS" and will
 * not be responsible for issues arising from incorrect user implementation
 * of the software.
 *
 * Disclaimer:
 * HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
 * REGARDING THE SOFTWARE (INCLUDING ANY ACCOMPANYING WRITTEN MATERIALS),
 * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
 * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
 * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
 * WARRANTY OF NONINFRINGEMENT.
 * HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
 * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
 * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
 * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
 * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
 * SAVINGS OR PROFITS,
 * EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
 * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
 * FROM, THE SOFTWARE.
 *
 * This software may be replicated in part or whole for the licensed use,
 * with the restriction that this Disclaimer and Copyright notice must be
 * included with each copy of this software, whether used in part or whole,
 * at all times.
 */
/******************************************************************************/
/** \file ddl_config.h
 **
 ** A detailed description is available at
 ** @link DdlConfigGroup Ddl Config description @endlink
 **
 **   - 2018-9-27  1.0  Yangjp First version for Device Driver Library config.
 **
 ******************************************************************************/
#ifndef __DDL_CONFIG_H__
#define __DDL_CONFIG_H__

/*******************************************************************************
 * Include files
 ******************************************************************************/

/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif

/**
 *******************************************************************************
 ** \defgroup DdlConfigGroup Device Driver Library config(DDLCONFIG)
 **
 ******************************************************************************/
//@{

/*******************************************************************************
 * Global type definitions ('typedef')
 ******************************************************************************/

/*******************************************************************************
 * Global pre-processor symbols/macros ('#define')
 ******************************************************************************/
/*! Chip module on-off define */
#define DDL_ON                                      1u
#define DDL_OFF                                     0u

/**
 *******************************************************************************
 ** \brief This is the list of modules to be used in the device driver library
 ** Select the modules you need to use to DDL_ON.
 **
 ** \note DDL_ICG_ENABLE and DDL_UTILITY_ENABLE must be turned on(DDL_ON) to
 ** ensure that the chip works properly.
 ******************************************************************************/
#define DDL_ICG_ENABLE                              DDL_ON
#define DDL_UTILITY_ENABLE                          DDL_ON

#define DDL_ADC_ENABLE                              DDL_OFF
#define DDL_AES_ENABLE                              DDL_OFF
#define DDL_CAN_ENABLE                              DDL_OFF
#define DDL_CMP_ENABLE                              DDL_OFF
#define DDL_CLK_ENABLE                              DDL_OFF
#define DDL_DCU_ENABLE                              DDL_OFF
#define DDL_DMAC_ENABLE                             DDL_OFF
#define DDL_EFM_ENABLE                              DDL_OFF
#define DDL_EMB_ENABLE                              DDL_OFF
#define DDL_EXINT_NMI_SWI_ENABLE                    DDL_OFF
#define DDL_GPIO_ENABLE                             DDL_ON
#define DDL_HASH_ENABLE                             DDL_OFF
#define DDL_I2C_ENABLE                              DDL_OFF
#define DDL_I2S_ENABLE                              DDL_OFF
#define DDL_INTERRUPTS_ENABLE                       DDL_OFF
#define DDL_KEYSCAN_ENABLE                          DDL_OFF
#define DDL_MPU_ENABLE                              DDL_OFF
#define DDL_OTS_ENABLE                              DDL_OFF
#define DDL_PGA_ENABLE                              DDL_OFF
#define DDL_PWC_ENABLE                              DDL_OFF
#define DDL_QSPI_ENABLE                             DDL_OFF
#define DDL_RMU_ENABLE                              DDL_OFF
#define DDL_RTC_ENABLE                              DDL_OFF
#define DDL_SDIOC_ENABLE                            DDL_OFF
#define DDL_SPI_ENABLE                              DDL_OFF
#define DDL_SRAM_ENABLE                             DDL_OFF
#define DDL_SWDT_ENABLE                             DDL_OFF
#define DDL_TIMER0_ENABLE                           DDL_OFF
#define DDL_TIMER4_CNT_ENABLE                       DDL_OFF
#define DDL_TIMER4_EMB_ENABLE                       DDL_OFF
#define DDL_TIMER4_OCO_ENABLE                       DDL_OFF
#define DDL_TIMER4_PWM_ENABLE                       DDL_OFF
#define DDL_TIMER4_SEVT_ENABLE                      DDL_OFF
#define DDL_TIMER6_ENABLE                           DDL_OFF
#define DDL_TIMERA_ENABLE                           DDL_OFF
#define DDL_TRNG_ENABLE                             DDL_OFF
#define DDL_USART_ENABLE                            DDL_OFF
#define DDL_USBFS_ENABLE                            DDL_OFF
#define DDL_WDT_ENABLE                              DDL_OFF


/*! Midware module on-off define */
#define MW_ON                                       1u
#define MW_OFF                                      0u

/**
 *******************************************************************************
 ** \brief This is the list of Midware modules to use
 ** Select the modules you need to use to MW_ON.
 ******************************************************************************/
#define MW_SD_CARD_ENABLE                           MW_OFF
#define MW_USB_ENABLE                               MW_OFF


/*******************************************************************************
 * Global variable definitions ('extern')
 ******************************************************************************/

/*******************************************************************************
 * Global function prototypes (definition in C source)
 ******************************************************************************/

//@} // DdlConfigGroup

#ifdef __cplusplus
}
#endif

#endif /* __DDL_CONFIG_H__ */

/*******************************************************************************
 * EOF (not truncated)
 ******************************************************************************/

 

6.在完成代码功能后,对代码进行编译、下载、运行;我们就来看一下最终程序运行的效果吧

7.工程源代码

Project_Template_LED.zip (772.07 KB, 下载次数: 13)

赞赏

1

查看全部赞赏

个人签名We are a team and we work as a team !

回复

1万

帖子

2853

资源

管理员

赞~谢谢分享~~

个人签名

玩板看这里:

http://bbs.eeworld.com.cn/elecplay.html

EEWorld测评频道众多好板等你来玩,还可以来频道许愿树许愿说说你想要玩的板子,我们都在努力为大家实现!


回复

283

帖子

2

资源

一粒金砂(高级)

开发板配套的历程就一个.C文件,看着不习惯,还是这个写发看着舒服


回复

6301

帖子

0

资源

五彩晶圆(初级)

最后的那个程序运行的效果的视频,录制的有点短


回复

283

帖子

2

资源

一粒金砂(高级)

image.png 我用历程里面的空工程文件(hc32f460petb_template)添加了driver文件之后总是出错

不知道是哪里出了问题

 

点评

我在config文件里面将GPIO使能打开了,但是编译后main,c文件并没有把GPIO相应的头文件包含进来    详情 回复 发表于 2021-4-2 11:31

回复

283

帖子

2

资源

一粒金砂(高级)

1nnocent 发表于 2021-4-2 11:22 我用历程里面的空工程文件(hc32f460petb_template)添加了driver文件之后总是出错 不知道是哪里出了问 ...

我在config文件里面将GPIO使能打开了,但是编译后main,c文件并没有把GPIO相应的头文件包含进来

 


回复

1998

帖子

3

资源

版主

感觉还不错,这个教程非常详细了!点个赞,期待后续的测评帖子哦!


回复

76

帖子

2

资源

一粒金砂(中级)

赞~很好的帖子


回复

13

帖子

0

资源

一粒金砂(中级)


不需要系统时钟使能吗?


回复
您需要登录后才可以回帖 登录 | 注册

最新文章 更多>>
    关闭
    站长推荐上一条 1/10 下一条

    About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

    站点相关: 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

    北京市海淀区知春路23号集成电路设计园量子银座1305 电话:(010)82350740 邮编:100191

    电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2021 EEWORLD.com.cn, Inc. All rights reserved
    快速回复 返回顶部 返回列表