起个名字这么难啊啊 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条回答

    报告相同问题?

    悬赏问题

    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥15 stable diffusion
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿