#include <stdio.h>
#include <unistd.h>
#include "ohos_init.h"
#include "cmsis_os2.h"
#include "iot_gpio.h"
#include "iot_watchdog.h"
#include "iot_pwm.h"
#include "hi_pwm.h"
static volatile int g_buttonPressed = 0;
static const uint16_t g_tuneFreqs[] = {
0, // 523.3, 0
0, // 523.3, 1
0, // 587.4, 2
659, // 659.3, 3
699, // 698.5, 4
784, // 784, 5
880, // 880, 6
988, // 987.8, 7
0, //
0, //
0, //
1047, // 1046.5, 11
1175, // 1174.7, 12
1319, // 1318.5, 13
1397, // 1396.9, 14
1568, // 1568, 15
1760, // 1760, 16
1976, // 1975.5, 17
0, //
0, //
0, //
2093, // 2093, 21
2349, // 2349.4, 22
2637, // 2637, 23
2794, // 2793.8, 24
3136, // 3136, 25
3520, // 3520, 26
3951, // 3951, 27
};
// 曲谱音符
static const uint8_t g_scoreNotes[] = {
// 简谱:http://www.jianpu.cn/pu/41/41614.htm
11,5,12,11, 6, 5, 11,5,13,12,11, 5,
5,11,13,16, 15,13,11, 13,13,15,11,6,5, 12,
11,5,12,11, 6,5, 11,5,13,12,11, 15,
5,11,13,16, 15,11,13, 12,13,15,6,5,12, 11,
5,11,13,16, 15,11,13, 12,13,15,6,5,12, 11,
11,5,12,11, 6, 5, 11,5,13,12,11, 15,
5,11,13,16, 15,13,11, 13,13,15,11,6,5, 12,
11,5,12,11,6,5, 11,5,13,12,11, 15,
5,11,13,16, 15,11,13, 12,13,15,6,5,12,11,
};
// 曲谱时值
static const uint8_t g_scoreDurations[] = {
2,2,2,2, 1, 7, 2,2,2,1,1, 8,
2,2,2,2, 2,2,4, 2,1,1,2,1,1, 8,
2,2,2,2, 1,7, 2,2,2,1,1,8,
2,2,2,2, 2,2,4, 2,1,1,1,1,2, 8,
2,2,2,2, 2,2,4, 2,1,1,1,1,2, 8,
2,2,2,2, 1,7, 2,2,2,1,1, 8,
2,2,2,2, 2,2,4, 2,1,1,2,1,1, 8,
2,2,2,2, 1,7, 2,2,2,1,1, 8,
2,2,2,2, 2,2,4, 2,1,1,1,1,2, 8,
};
static void *TaiyangzuihongTask(const char *arg)
{
(void)arg;
printf("TaiyangzuihongTask start!\r\n");
hi_pwm_set_clock(PWM_CLK_XTAL); // 设置时钟源为晶体时钟(40MHz,默认时钟源160MHz)
for (size_t i = 0; i < sizeof(g_scoreNotes)/sizeof(g_scoreNotes[0]); i++) {
uint32_t tune = g_scoreNotes[i]; // 音符
uint16_t freqDivisor = g_tuneFreqs[tune];
uint32_t tuneInterval = g_scoreDurations[i] * (160); // 音符时间
printf("%d %d %d %d\r\n", tune, (40*1000*1000) / freqDivisor, freqDivisor, tuneInterval);
IoTPwmStart(0, 50, freqDivisor);
msleep(tuneInterval);
IoTPwmStop(0);
}
return NULL;
}
static void StartTaiyangzuihongTask(void)
{
osThreadAttr_t attr;
IoTGpioInit(9);
// 蜂鸣器引脚 设置为 PWM功能
IoTGpioSetFunc(9, 5);
IoTPwmInit(0);
IoTWatchDogDisable();
attr.name = "TaiyangzuihongTask";
attr.attr_bits = 0U;
attr.cb_mem = NULL;
attr.cb_size = 0U;
attr.stack_mem = NULL;
attr.stack_size = 1024;
attr.priority = osPriorityNormal;
if (osThreadNew((osThreadFunc_t)TaiyangzuihongTask, NULL, &attr) == NULL) {
printf("[Taiyangzuihong] Falied to create TaiyangzuihongTask!\n");
}
}
SYS_RUN(StartTaiyangzuihongTask);
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.
- 110.
- 111.
- 112.
- 113.
- 114.
- 115.
- 116.
- 117.
- 118.
- 119.
- 120.
- 121.
- 122.
- 123.
东方红,太阳升!这个好有意义
可以,很红,很专
饮水思源
可以问一i下include_dirs的内容吗