/**************************************************************************//**
* [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);
}
}
|