找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1106|回复: 0
打印 上一主题 下一主题
收起左侧

Nations G031源码 点亮LED灯

[复制链接]
跳转到指定楼层
楼主
ID:1036413 发表于 2022-6-22 16:15 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
LED闪烁的程序源码:

#include "main.h"
#include <stdio.h>
#include <stdint.h>

/**
* @brief  Main program.
*/
int main(void)
{
    /*SystemInit() function has been called by startup file startup_n32g031.s*/

    /* Initialize Led1~Led3 as output pushpull mode*/
    LedInit(PORT_GROUP, LED1_PIN | LED2_PIN | LED3_PIN);

    /*Turn on Led1~Led3*/
    LedOn(PORT_GROUP, LED1_PIN | LED2_PIN | LED3_PIN);

    while (1)
    {
        /*LED1_PORT, LED2_PORT and LED3_PORT are the same port group.  
         *Enable Led2 blink and not effect Led1 and Led2 by Exclusive-OR operation.*/
        LedBlink(PORT_GROUP, LED2_PIN);
        LedOff(PORT_GROUP, LED3_PIN);
        /* Insert delay */
        Delay(0x28FFFF);
         LedOff(PORT_GROUP, LED1_PIN);
      Delay(0x28FFFF);


        LedOn(PORT_GROUP, LED1_PIN | LED3_PIN);

        Delay(0x28FFFF);
    }
}
void Delay(uint32_t count)
{
    for (; count > 0; count--)
        ;
}void LedInit(GPIO_Module* GPIOx, uint16_t Pin)
{
    GPIO_InitType GPIO_InitStructure;

    /* Check the parameters */
    assert_param(IS_GPIO_ALL_PERIPH(GPIOx));

    /* Enable the GPIO Clock */
    if (GPIOx == GPIOA)
    {
        RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE);
    }
    else if (GPIOx == GPIOB)
    {
        RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE);
    }
    else if (GPIOx == GPIOC)
    {
        RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOC, ENABLE);
    }
    else if (GPIOx == GPIOF)
    {
        RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOF, ENABLE);
    }
    else
    {
        return;
    }

    /* Configure the GPIO pin */
    if (Pin <= GPIO_PIN_ALL)
    {
        GPIO_InitStruct(&GPIO_InitStructure);
        GPIO_InitStructure.Pin = Pin;
        GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP;
        GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure);
    }
}
void LedOn(GPIO_Module *GPIOx, uint16_t Pin)
{
    GPIO_SetBits(GPIOx, Pin);
}
void LedOff(GPIO_Module* GPIOx, uint16_t Pin)
{
    GPIO_ResetBits(GPIOx, Pin);
}void LedBlink(GPIO_Module* GPIOx, uint16_t Pin)
{
    GPIO_TogglePin(GPIOx, Pin);
}
#ifdef USE_FULL_ASSERT
void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line)
{
    while (1)
    {
    }
}
#endif // USE_FULL_ASSERT
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表