打印
[DemoCode下载]

NUC130最新库函数与例子

[复制链接]
314|11
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
zhuomuniao110|  楼主 | 2020-4-9 22:53 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
EC_Nano130_Wireless_Communication_With_Bluetooth_Module_V1.00.zip (9.42 MB)


使用特权

评论回复
沙发
zhuomuniao110|  楼主 | 2020-4-9 22:54 | 只看该作者
/**************************************************************************//**
* [url=home.php?mod=space&uid=288409]@file[/url]     main.c
* [url=home.php?mod=space&uid=895143]@version[/url]  V1.00
* $Revision: 1 $
* $Date: 14/05/13 7:19p $
* [url=home.php?mod=space&uid=247401]@brief[/url]    Bluetooth Communication with VICTOR-BT4030
*                                         to control devices on NuEdu-Basic01 board
*
* @note
* Copyright (C) 2014 Nuvoton Technology Corp. All rights reserved.
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "NuEdu-Basic01.h"

/*---------------------------------------------------------------------------------------------------------*/
/* Global Variale                                                                                          */
/*---------------------------------------------------------------------------------------------------------*/
uint8_t Command[4] = {0, 0, 0, 0};
uint32_t scale[8] = {0, 523, 578, 659, 698, 784, 880, 988};

/*---------------------------------------------------------------------------------------------------------*/
/* Init System Clock                                                                                       */
/*---------------------------------------------------------------------------------------------------------*/
void SYS_Init(void)
{
    /* Unlock protected registers */
    SYS_UnlockReg();

    /* Enable 12MHz HIRC */
    CLK_EnableXtalRC(CLK_PWRCTL_HIRC_EN_Msk);

    /* Waiting for 12MHz clock ready */
    CLK_WaitClockReady(CLK_CLKSTATUS_HIRC_STB_Msk);

    /* Set HCLK source form HIRC and HCLK source divide 1  */
    CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HIRC, CLK_HCLK_CLK_DIVIDER(1));

    /* Update System Core Clock */
    /* User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CycylesPerUs automatically. */
    SystemCoreClockUpdate();

    /* Lock protected registers */
    SYS_LockReg();

}

/*---------------------------------------------------------------------------------------------------------*/
/* Init UART1                                                                                              */
/*---------------------------------------------------------------------------------------------------------*/
void UART1_Init(void)
{
    /* Enable IP clock */
    CLK_EnableModuleClock(UART1_MODULE);

    /* Select IP clock source */
    CLK_SetModuleClock(UART1_MODULE, CLK_CLKSEL1_UART_S_HIRC, CLK_UART_CLK_DIVIDER(1));

    /* Set PA multi-function pins for UART1 RXD and TXD */
    SYS->PC_H_MFP &= ~(SYS_PC_H_MFP_PC10_MFP_Msk | SYS_PC_H_MFP_PC11_MFP_Msk);
    SYS->PC_H_MFP |= (SYS_PC_H_MFP_PC10_MFP_UART1_RX | SYS_PC_H_MFP_PC11_MFP_UART1_TX);

    SYS_ResetModule(UART1_RST);

    /* Configure UART1 and set UART1 Baudrate */
    UART_Open(UART1, 9600);
    /* Set RX FIFO Trigger Level to 4 bytes */
    UART0->TLCTL |= UART_TLCTL_RFITL_4BYTES ;

}

/*---------------------------------------------------------------------------------------------------------*/
/* ISR to handle UART1 interrupt event                                                                     */
/*---------------------------------------------------------------------------------------------------------*/
void UART1_IRQHandler(void)
{
    /* Get all the input characters */
    while (UART_IS_RX_READY(UART1))
    {
        /* Get the character from UART Buffer */
        UART_Read(UART1, Command, 4);
    }
}

/*---------------------------------------------------------------------------------------------------------*/
/*  MAIN function                                                                                          */
/*---------------------------------------------------------------------------------------------------------*/
int main(void)
{

    /* Initial System Clock */
    SYS_Init();

    /* Initial UART1 for connecting Bluetooth */
    UART1_Init();
    /* Enable UART1 interrupt*/
    UART_EnableInt(UART1, UART_IER_RDA_IE_Msk);
    NVIC_EnableIRQ(UART1_IRQn);

    /* Initial the LED on Basic board */
    initial_led();

    /* Initial the 7-segments on Basic board */
    Open_Seven_Segment();

    /* Initial the buzzer on Basic board */
    Open_Buzzer();

    while (1)
    {
        LED_on(Command[0]);
        Show_Seven_Segment(Command[1], 1);
        CLK_SysTickDelay(10000);
        Show_Seven_Segment(Command[2], 2);
        CLK_SysTickDelay(10000);

        if (scale[Command[3]] == 0)
            PWM_DisableOutput(PWM1, 0x02);
        else
            Write_Buzzer(scale[Command[3]], 50);
    }
}

使用特权

评论回复
板凳
zhuomuniao110|  楼主 | 2020-4-9 22:54 | 只看该作者
新版的库函数更好用。跟其他型号库函数保持一致,增加可移植性。

使用特权

评论回复
地板
xuanhuanzi| | 2020-4-9 23:36 | 只看该作者
官方没找到库函数BSP,多谢。

使用特权

评论回复
5
598330983| | 2020-4-12 13:36 | 只看该作者
什么蓝牙模块

使用特权

评论回复
6
xuanhuanzi| | 2020-4-12 23:47 | 只看该作者
官方的例子越来越棒了。

使用特权

评论回复
7
kxsi| | 2020-5-5 15:42 | 只看该作者
非常感谢楼主分享

使用特权

评论回复
8
nawu| | 2020-5-5 15:43 | 只看该作者
非诚完整的代码

使用特权

评论回复
9
qcliu| | 2020-5-5 15:43 | 只看该作者
好好 正好可以用的上

使用特权

评论回复
10
tfqi| | 2020-5-5 15:44 | 只看该作者
感谢楼主分享

使用特权

评论回复
11
wiba| | 2020-5-5 15:44 | 只看该作者
这是官网的例程吗

使用特权

评论回复
12
zhuomuniao110|  楼主 | 2020-5-9 23:47 | 只看该作者
wiba 发表于 2020-5-5 15:44
这是官网的例程吗

是的

使用特权

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

本版积分规则

188

主题

3247

帖子

10

粉丝