| 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 ));
49 SYS->PC_H_MFP |= SYS_PC_H_MFP_PC13_MFP_PWM1_CH1;
50
51 }
52
58 void Open_Buzzer(void)
59 {
60
61 Initial_PWM_GPIO();
62 Buzzer_Power_ON;
63
64 /* Enable PWM clock */
65 CLK_EnableModuleClock(PWM1_CH01_MODULE);
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 {
93 Buzzer_Power_OFF;
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. ***/
PWM_EnableOutput
void PWM_EnableOutput(PWM_T *pwm, uint32_t u32ChannelMask)
This function enables PWM output generation of selected channels.
Definition: pwm.c:334
CLK_EnableModuleClock
void CLK_EnableModuleClock(uint32_t u32ModuleIdx)
This function enable module clock.
Definition: clk.c:436
Buzzer_Power_OFF
#define Buzzer_Power_OFF
Control Buzzer module power down.
Definition: NuEdu-Basic01_Buzzer.c:29
Initial_PWM_GPIO
void Initial_PWM_GPIO(void)
This function config PC.13 multi-function for PWM to drive Buzzer module, and config PE....
Definition: NuEdu-Basic01_Buzzer.c:42
BIT6
#define BIT6
Bit 6 mask of an 32 bit integer.
Definition: Nano100Series.h:11875
Nano100Series.h
Nano100 series peripheral access layer header file. This file contains all the peripheral register's ...
SYS_PC_H_MFP_PC13_MFP_Msk
#define SYS_PC_H_MFP_PC13_MFP_Msk
Definition: Nano100Series.h:3188
BIT13
#define BIT13
Bit 13 mask of an 32 bit integer.
Definition: Nano100Series.h:11882
PWM1
#define PWM1
Pointer to PWM1 register structure.
Definition: Nano100Series.h:11680
PWM_ConfigOutputChannel
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
Write_Buzzer
void Write_Buzzer(unsigned int frequence, unsigned int duty)
This function set PWM output frequence and duty to drive Buzzer module.
Definition: NuEdu-Basic01_Buzzer.c:78
SYS_PC_H_MFP_PC13_MFP_PWM1_CH1
#define SYS_PC_H_MFP_PC13_MFP_PWM1_CH1
Definition: sys.h:387
NuEdu-Basic01_Buzzer.h
NuEdu-Basic01 Buzzer driver header file.
PC
#define PC
Pointer to GPIO port C register structure.
Definition: Nano100Series.h:11697
PWM1_CH01_MODULE
#define PWM1_CH01_MODULE
Definition: clk.h:308
Buzzer_Power_ON
#define Buzzer_Power_ON
Control Buzzer module power on.
Definition: NuEdu-Basic01_Buzzer.c:28
GPIO_PMD_OUTPUT
#define GPIO_PMD_OUTPUT
Definition: gpio.h:38
PE
#define PE
Pointer to GPIO port E register structure.
Definition: Nano100Series.h:11699
Close_Buzzer
void Close_Buzzer(void)
This function power down the Buzzer module.
Definition: NuEdu-Basic01_Buzzer.c:91
Open_Buzzer
void Open_Buzzer(void)
This function enable PWM1 module clock and set clock source to start Buzzer module.
Definition: NuEdu-Basic01_Buzzer.c:58
PWM_Start
void PWM_Start(PWM_T *pwm, uint32_t u32ChannelMask)
This function start PWM module.
Definition: pwm.c:227
GPIO_SetMode
void GPIO_SetMode(GPIO_T *gpio, uint32_t u32PinMask, uint32_t u32Mode)
Set GPIO operation mode.
Definition: gpio.c:40
CLK_SetModuleClock
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
SYS
#define SYS
Pointer to SYS register structure.
Definition: Nano100Series.h:11692