Nano100BN Series BSP  V3.03.002
The Board Support Package for Nano100BN Series
NuEdu-Basic01_Buzzer.c
Go to the documentation of this file.
1 /**************************************************************************/
12 #include <stdio.h>
13 #include "Nano100Series.h"
14 #include "NuEdu-Basic01_Buzzer.h"
15 
16 
28 #define Buzzer_Power_ON PE6=1
29 #define Buzzer_Power_OFF PE6=0
30 
31  /* end of group Nano130_Basic01_FUNCTIONS Buzzer Exported Constants */
32 
42 void Initial_PWM_GPIO(void)
43 {
44  GPIO_SetMode(PC, BIT13, GPIO_PMD_OUTPUT); //Buzzer OUT
45  GPIO_SetMode(PE, BIT6, GPIO_PMD_OUTPUT); //Buzzer POWER
46 
47  /* Set PC 13 multi-function pins for PWM0 channel 0*/
48  SYS->PC_H_MFP = (SYS->PC_H_MFP & ~(SYS_PC_H_MFP_PC13_MFP_Msk ));
50 
51 }
52 
58 void Open_Buzzer(void)
59 {
60 
63 
64  /* Enable PWM clock */
66 
67  /* Set HCLK as PWM clock source */
68  CLK_SetModuleClock(PWM1_CH01_MODULE, (0x2UL<<4), 0);
69 
70  /* Start PWM1 channel 1 */
71  PWM_Start(PWM1, 0x02);
72 }
73 
78 void Write_Buzzer(unsigned int frequence, unsigned int duty)
79 {
80 
81  // Config PWM1 channel 1
82  PWM_ConfigOutputChannel(PWM1, 1, frequence, duty);
83  // Enable PWM1 channel 1 to drive buzzer module
84  PWM_EnableOutput(PWM1, 0x02);
85 }
86 
91 void Close_Buzzer(void)
92 {
94 }
95 
96  /* end of group Nano130_Basic01_FUNCTIONS Buzzer Exported Functions */
98  /* end of group NuEdu-SDK-Nano130_Basic01 Nano130_Basic01 Library */
100  /* end of group NANO100_Library NANO100 Library */
102 
103 /*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/
void PWM_EnableOutput(PWM_T *pwm, uint32_t u32ChannelMask)
This function enables PWM output generation of selected channels.
Definition: pwm.c:334
void CLK_EnableModuleClock(uint32_t u32ModuleIdx)
This function enable module clock.
Definition: clk.c:436
#define Buzzer_Power_OFF
Control Buzzer module power down.
void Initial_PWM_GPIO(void)
This function config PC.13 multi-function for PWM to drive Buzzer module, and config PE....
#define BIT6
Bit 6 mask of an 32 bit integer.
Nano100 series peripheral access layer header file. This file contains all the peripheral register's ...
#define SYS_PC_H_MFP_PC13_MFP_Msk
#define BIT13
Bit 13 mask of an 32 bit integer.
#define PWM1
Pointer to PWM1 register structure.
uint32_t PWM_ConfigOutputChannel(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Frequency, uint32_t u32DutyCycle)
This function config PWM generator and get the nearest frequency in edge aligned auto-reload mode.
Definition: pwm.c:37
void Write_Buzzer(unsigned int frequence, unsigned int duty)
This function set PWM output frequence and duty to drive Buzzer module.
#define SYS_PC_H_MFP_PC13_MFP_PWM1_CH1
Definition: sys.h:387
NuEdu-Basic01 Buzzer driver header file.
#define PC
Pointer to GPIO port C register structure.
#define PWM1_CH01_MODULE
Definition: clk.h:308
#define Buzzer_Power_ON
Control Buzzer module power on.
#define GPIO_PMD_OUTPUT
Definition: gpio.h:38
#define PE
Pointer to GPIO port E register structure.
void Close_Buzzer(void)
This function power down the Buzzer module.
void Open_Buzzer(void)
This function enable PWM1 module clock and set clock source to start Buzzer module.
void PWM_Start(PWM_T *pwm, uint32_t u32ChannelMask)
This function start PWM module.
Definition: pwm.c:227
void GPIO_SetMode(GPIO_T *gpio, uint32_t u32PinMask, uint32_t u32Mode)
Set GPIO operation mode.
Definition: gpio.c:40
void CLK_SetModuleClock(uint32_t u32ModuleIdx, uint32_t u32ClkSrc, uint32_t u32ClkDiv)
This function set selected module clock source and module clock divider.
Definition: clk.c:339
#define SYS
Pointer to SYS register structure.