[DemoCode下载] NUC130最新库函数与例子

[复制链接]
708|11
 楼主| zhuomuniao110 发表于 2020-4-9 22:53 | 显示全部楼层 |阅读模式
EC_Nano130_Wireless_Communication_With_Bluetooth_Module_V1.00.zip (9.42 MB, 下载次数: 35)


 楼主| zhuomuniao110 发表于 2020-4-9 22:54 | 显示全部楼层
  1. /**************************************************************************//**
  2. * [url=home.php?mod=space&uid=288409]@file[/url]     main.c
  3. * [url=home.php?mod=space&uid=895143]@version[/url]  V1.00
  4. * $Revision: 1 $
  5. * $Date: 14/05/13 7:19p $
  6. * [url=home.php?mod=space&uid=247401]@brief[/url]    Bluetooth Communication with VICTOR-BT4030
  7. *                                         to control devices on NuEdu-Basic01 board
  8. *
  9. * @note
  10. * Copyright (C) 2014 Nuvoton Technology Corp. All rights reserved.
  11. ******************************************************************************/
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <stdint.h>
  15. #include "NuEdu-Basic01.h"

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

  21. /*---------------------------------------------------------------------------------------------------------*/
  22. /* Init System Clock                                                                                       */
  23. /*---------------------------------------------------------------------------------------------------------*/
  24. void SYS_Init(void)
  25. {
  26.     /* Unlock protected registers */
  27.     SYS_UnlockReg();

  28.     /* Enable 12MHz HIRC */
  29.     CLK_EnableXtalRC(CLK_PWRCTL_HIRC_EN_Msk);

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

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

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

  37.     /* Lock protected registers */
  38.     SYS_LockReg();

  39. }

  40. /*---------------------------------------------------------------------------------------------------------*/
  41. /* Init UART1                                                                                              */
  42. /*---------------------------------------------------------------------------------------------------------*/
  43. void UART1_Init(void)
  44. {
  45.     /* Enable IP clock */
  46.     CLK_EnableModuleClock(UART1_MODULE);

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

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

  52.     SYS_ResetModule(UART1_RST);

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

  57. }

  58. /*---------------------------------------------------------------------------------------------------------*/
  59. /* ISR to handle UART1 interrupt event                                                                     */
  60. /*---------------------------------------------------------------------------------------------------------*/
  61. void UART1_IRQHandler(void)
  62. {
  63.     /* Get all the input characters */
  64.     while (UART_IS_RX_READY(UART1))
  65.     {
  66.         /* Get the character from UART Buffer */
  67.         UART_Read(UART1, Command, 4);
  68.     }
  69. }

  70. /*---------------------------------------------------------------------------------------------------------*/
  71. /*  MAIN function                                                                                          */
  72. /*---------------------------------------------------------------------------------------------------------*/
  73. int main(void)
  74. {

  75.     /* Initial System Clock */
  76.     SYS_Init();

  77.     /* Initial UART1 for connecting Bluetooth */
  78.     UART1_Init();
  79.     /* Enable UART1 interrupt*/
  80.     UART_EnableInt(UART1, UART_IER_RDA_IE_Msk);
  81.     NVIC_EnableIRQ(UART1_IRQn);

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

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

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

  88.     while (1)
  89.     {
  90.         LED_on(Command[0]);
  91.         Show_Seven_Segment(Command[1], 1);
  92.         CLK_SysTickDelay(10000);
  93.         Show_Seven_Segment(Command[2], 2);
  94.         CLK_SysTickDelay(10000);

  95.         if (scale[Command[3]] == 0)
  96.             PWM_DisableOutput(PWM1, 0x02);
  97.         else
  98.             Write_Buzzer(scale[Command[3]], 50);
  99.     }
  100. }
 楼主| zhuomuniao110 发表于 2020-4-9 22:54 | 显示全部楼层
新版的库函数更好用。跟其他型号库函数保持一致,增加可移植性。
xuanhuanzi 发表于 2020-4-9 23:36 | 显示全部楼层
官方没找到库函数BSP,多谢。
598330983 发表于 2020-4-12 13:36 | 显示全部楼层
什么蓝牙模块
xuanhuanzi 发表于 2020-4-12 23:47 | 显示全部楼层
官方的例子越来越棒了。
kxsi 发表于 2020-5-5 15:42 | 显示全部楼层
非常感谢楼主分享
nawu 发表于 2020-5-5 15:43 | 显示全部楼层
非诚完整的代码
qcliu 发表于 2020-5-5 15:43 | 显示全部楼层
好好 正好可以用的上
tfqi 发表于 2020-5-5 15:44 | 显示全部楼层
感谢楼主分享
wiba 发表于 2020-5-5 15:44 | 显示全部楼层
这是官网的例程吗
 楼主| zhuomuniao110 发表于 2020-5-9 23:47 | 显示全部楼层
wiba 发表于 2020-5-5 15:44
这是官网的例程吗

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

本版积分规则

233

主题

3529

帖子

11

粉丝
快速回复 在线客服 返回列表 返回顶部