问题描述
- 通过CC2540作为从机,通过手机发送数据‘a’实现从机播放“收到”声音。
- 现在是的问题是通过设置定时器1来完成,
但是具体的声音“收到”的频率是怎么装载到定时器里面的,产生要的PWM波形。
我的程序只能改变占空比,只是发出声音的高低,还有就是网上都是音乐的频率,没有说话的
有没有取模软件把说话的声音频率算出来??求大神指导,
#include
#include ""bcomdef.h""
#include ""OSAL.h""
#include ""pwm.h""//pwm pins:
//P0.0
//P0.1uint16 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 = SuspendedT1CCTL1 = 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 rgb;
// 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 registersT1CC1L = (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(gRedgGreengBlue);
}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(countcountcount);osal_start_timerEx( SimpleOsal_TaskID SBP_START_DEVICE_EVT 5 );return ( events ^ SBP_START_DEVICE_EVT );
}
// Discard unknown events
return 0;