打印
[开发工具]

GPIO点灯操作

[复制链接]
427|7
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
huahuagg|  楼主 | 2022-12-22 21:41 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/*******************************************************************************
* Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
*
* This software component is licensed by HDSC under BSD 3-Clause license
* (the "License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*                    opensource.org/licenses/BSD-3-Clause
*/
/******************************************************************************/
/** \file main.c
**
** \brief This sample demonstrates how to set GPIO as output function.
**
**   - 2018-10-14 CDT first version for Device Driver Library of GPIO.
**
******************************************************************************/

/*******************************************************************************
* Include files
******************************************************************************/
#include "hc32_ddl.h"

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

/*******************************************************************************
* Local pre-processor symbols/macros ('#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)

/* 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))

#define  DLY_MS           (100ul)

/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/

/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/

/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/

/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*******************************************************************************
** \brief  Main function of GPIO output
**
** \param  None
**
** \retval int32_t Return value, if needed
**
******************************************************************************/
int32_t main(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);

    while(1)
    {
        LED0_TOGGLE();
        Ddl_Delay1ms(DLY_MS);
        LED1_TOGGLE();
        Ddl_Delay1ms(DLY_MS);
        LED2_TOGGLE();
        Ddl_Delay1ms(DLY_MS);
        LED3_TOGGLE();
        Ddl_Delay1ms(DLY_MS);
        /* de-init if necessary */
        //PORT_DeInit();
    };
}

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


使用特权

评论回复
沙发
huahuagg|  楼主 | 2022-12-22 21:42 | 只看该作者
http://xhsc.com.cn/Productlist/info.aspx?itemid=1850
资料下载地址

使用特权

评论回复
板凳
aoyi| | 2023-1-3 14:32 | 只看该作者
能介绍一下硬件是如何连接的吗 使用的是什么引脚

使用特权

评论回复
地板
tpgf| | 2023-1-3 14:53 | 只看该作者
看了一下软件中对寄存器的配置非常简单了 就是实现小灯的亮灭

使用特权

评论回复
5
nawu| | 2023-1-3 15:14 | 只看该作者
功能非常简单 关键还得看时钟配置以及io配置

使用特权

评论回复
6
zljiu| | 2023-1-3 15:26 | 只看该作者
可以看一下楼主的io口初始化的那部分的代码吗

使用特权

评论回复
7
gwsan| | 2023-1-3 15:48 | 只看该作者
楼主的这种匀速点灯完全可以通过pwm来实现吧

使用特权

评论回复
8
tfqi| | 2023-1-3 15:56 | 只看该作者
每个新手入门的操作就是点灯 不过点灯也是有一定技巧的

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

118

主题

1187

帖子

1

粉丝