起个名字这么难啊啊 2016-04-05 06:24 采纳率: 50%
浏览 1193

通过CC2540作为从机,通过手机发送数据‘a’实现从机播放“收到”声音。

现在是的问题是通过设置定时器1来完成,
但是具体的声音“收到”的频率是怎么装载到定时器里面的,产生要的PWM波形。
我的程序只能改变占空比,只是发出声音的高低,还有就是网上都是音乐的频率,没有说话的
有没有取模软件把说话的声音频率算出来??求大神指导,
#include
#include "bcomdef.h"
#include "OSAL.h"
#include "pwm.h"

//pwm pins:
//P0.0
//P0.1

uint16 gRed;
uint16 gGreen;
uint16 gBlue;

void PWM_init()
{
//设置pwm端口为输出
P1DIR|= BV(0)|BV(1);
//设置pwm端口为外设端口,非gpio
P1SEL|= BV(0)|BV(1);
//由于uart等会占用我们当前使用的pwm端口,因此需要将uart等重映射到别的端口去。
PERCFG |= 0x40; // Move USART1&2 to alternate2 location so that T1 is visible

// Initialize Timer 1
T1CTL = 0x0C; // Div = 128, CLR, MODE = Suspended

T1CCTL1 = 0x0C; // IM = 0; CMP = Clear output on compare; Mode = Compare
T1CCTL2 = 0x0C; // IM = 0; CMP = Clear output on compare; Mode = Compare
T1CCTL3 = 0x0C; // IM = 0, CMP = Clear output on compare; Mode = Compare
T1CNTL = 0; // Reset timer to 0;

T1CCTL0 = 0x4C;

T1CC0H = 0x01;

T1CC0L = 0x77;

T1CC1H = 0x01;

T1CC1L = 0x77;
T1CC2H = 0x01;

T1CC2L = 0x77;
T1CC3H = 0x01;

T1CC3L = 0x77;

EA=1;
IEN1 |= 0x02; // Enable T1 cpu interrupt
}

void pwmPulse(uint16 red, uint16 green, uint16 blue)
{
uint16 r,g,b;
// stop,注意,不能加这句,加了周期偏差十几倍,具体原因未查明
//T1CTL &= BV(0)|BV(1);
#if 0
r=375;
g=1;
b=1;
#else
r=red;
g=green;
b=blue;
#endif
// Set up the timer registers

T1CC1L = (uint8)r;
T1CC1H = (uint8)(r >> 8);
T1CC2L = (uint8)g;
T1CC2H = (uint8)(g >> 8);
T1CC3L = (uint8)b;
T1CC3H = (uint8)(b >> 8);

// Reset timer
T1CNTL = 0;

// Start timer in modulo mode.
T1CTL |= 0x02;

}

void setRGB(uint16 red, uint16 green, uint16 blue)
{
gRed=red;
gGreen=green;
gBlue=blue;
}

//#pragma register_bank=2
#pragma vector = T1_VECTOR
__interrupt void pwmISR (void) {
uint8 flags = T1STAT;
// T1 ch 0
if (flags & 0x01){

pwmPulse(gRed,gGreen,gBlue);

}
T1STAT = ~ flags;

}

if ( events & SBP_START_DEVICE_EVT )
{
static uint8 count=1;
static uint8 updown=1;

if(updown)
  count++;
else
  count--;
if(count==200)
  updown=0;
if(count==1)
  updown=1;
//设置占空比
setRGB(count,count,count);

osal_start_timerEx( SimpleOsal_TaskID, SBP_START_DEVICE_EVT, 5 );
return ( events ^ SBP_START_DEVICE_EVT );

}
// Discard unknown events
return 0;

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥20 删除和修改功能无法调用
    • ¥15 kafka topic 所有分副本数修改
    • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
    • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
    • ¥40 串口调试助手打开串口后,keil5的代码就停止了
    • ¥15 电脑最近经常蓝屏,求大家看看哪的问题
    • ¥60 高价有偿求java辅导。工程量较大,价格你定,联系确定辅导后将采纳你的答案。希望能给出完整详细代码,并能解释回答我关于代码的疑问疑问,代码要求如下,联系我会发文档
    • ¥50 C++五子棋AI程序编写
    • ¥30 求安卓设备利用一个typeC接口,同时实现向pc一边投屏一边上传数据的解决方案。
    • ¥15 SQL Server analysis services 服务安装失败