您当前的位置: 首页 >  ar

txwtech

暂无认证

  • 1浏览

    0关注

    813博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

鸿蒙开发板Hi3861_通过GPIO12 PWM蜂鸣器播放<涛声依旧>-——基于code-2.0-CANARY

txwtech 发布时间:2021-08-25 20:09:11 ,浏览量:1

//通过PWM蜂鸣器实验-A12连接, A12接长脚,蜂鸣器短脚接GND

编译报错参考:

https://blog.csdn.net/txwtech/article/details/119853772

//通过PWM蜂鸣器实验-A12连接, A12接长脚,蜂鸣器短脚接GND
//,by txwtech
#include  
#include "ohos_init.h"
#include "cmsis_os2.h"
#include "iot_gpio.h"
#include "hi_io.h"
#include "iot_pwm.h"
#include "hi_pwm.h"
#include "hi_time.h"
int count1=0;

//音符对照表:
//https://www.cnblogs.com/developer-huawei/p/13959852.html
static const uint16_t g_tuneFreqs[]={
    0,
    
    38223, // 1 1046.5,-
    34052, // 2 1174.7,--
    30338, // 3 1318.5,--
    28635, // 4 1396.4,--
    25511, // 5 1568,---
    22728, // 6 1760,---
    20249, // 7 1975.5,---  
    51021,//  8,5_低音 783.99,   40M=40*1000*1000, 40M/783.99=51021
    45454,//  9,6_     880.00
    40495,//  10,7_     987.77    
    
};
static const uint8_t g_scoreNotes[] = {
    // 《两只老虎》简谱
    1, 2, 3, 1,    1, 2, 3, 1,   3, 4, 5,  3, 4, 5,
    5, 6, 5, 4, 3, 1,  5, 6, 5, 4, 3, 1,   1, 8, 1,  1, 8, 1,
};
static const uint8_t g_scoreNotes_txwtech[] = {
    // 《涛声依旧》简谱
    6,6,3,5,  6,5,5,
    1,2,3,3,  3,5,6,5,3,2,3,0,
    6,5,3,5, 1, 9,8,8,
    9,1,2,2,   2,6,3,      5,6,5,
   
    

};

// 曲谱时值
static const uint8_t g_scoreDurations[] = {
    4, 4, 4, 4,    4, 4, 4, 4,   4, 4, 8,  4, 4, 8,
    3, 1, 3, 1, 4, 4,  3, 1, 3, 1, 4, 4,   4, 4, 8,  4, 4, 8,
};
//txwtech
static const uint8_t g_scoreDurations_txwtech[] = {
    4, 4, 4, 4,  2,2,4,    
    2, 2, 4, 4,   2, 4, 1, 1, 2,2, 8,1,
    4,4,2,2,     4, 2, 2, 4,
    2,2,4,4,       2,4, 2,    2, 2, 8,
};

static void GpioTask(void *arg)
{
    (void) arg;

    uint32_t tune;
    uint16_t freqDivisor;
    uint32_t tuneInterval;
   hi_gpio_init();
   hi_io_set_func(HI_IO_NAME_GPIO_12,HI_IO_FUNC_GPIO_12_PWM3_OUT);  
  // 
   hi_pwm_init(HI_PWM_PORT_PWM3);  
  //  hi_pwm_set_clock(PWM_CLK_160M);   
   hi_pwm_set_clock(PWM_CLK_XTAL);  
   //while(1)
   {
    
       IotGpioValue val=IOT_GPIO_VALUE0;
       IoTGpioGetOutputVal(HI_IO_NAME_GPIO_12,&val);
        count1=sizeof(g_tuneFreqs)/sizeof(g_tuneFreqs[0]);
       printf("count is:  %d\n",count1);
       

       printf("execute pwm,value: %d\n",val);
       if(0)
       {
         for(size_t i=0;i            
关注
打赏
1665060526
查看更多评论
0.0396s