其他声音然后是原始的.wav文件

时间:2011-05-27 18:15:44

标签: c microcontroller pic microchip

我正在使用微芯片v8.63中的pic18F4550:我使用了pic程序的C语言:我们创建了以下程序:我们检索转换为8bit 8000Hz的.wav文件的二进制数据(声音是:有人说是“红色”),我们将数据写入picdem的'rom'。每个值都将写入port =>有一个盒子连接到。

问题:我不能在这里,原始声音(有人说:“红色”)而不是那个听到响亮的其他声音(没有噪音或噼啪声),而是一个响亮的其他声音。

这就是代码:

unsigned int b = 0;
unsigned int i = 0;
unsigned int j= 0;

#pragma romdata const_table  = 0x1200

const rom char my_const_array[] = "0b01010101
,0b10101010
,0b10101010
,0b10101010
,0b10101001
,0b01010101
,0b01010110
,0b10100101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010100
,0b10110101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01001010
,0b10101010
,0b11010101
,0b00101010
,0b10101011
,0b01010101
,0b01010101
,0b01010101
,0b01001010
,0b10101010
,0b11010100
,0b10101010
,0b10101010
,0b10110101
,0b01010101
,0b01010101
,0b01001010
,0b10101010
,0b10101010
,0b10101010
,0b10101010
,0b10101010
,0b10101101
,0b01010100
,0b10101010
,0b10011010
,0b10101010
,0b10101010
,0b10101010
,0b10101010
,0b10101010
,0b10110010
,0b10100101
,0b01010110
,0b10101010
,0b10100101
,0b01011010
,0b10101010
,0b10101010
,0b11001010
,0b10010101
,0b01011010
,0b10101001
,0b01010101
,0b01101010
,0b10101010
,0b10101101
,0b00101001
,0b01010101
,0b10101010
,0b10010101
,0b01010101
,0b10101010
,0b10101010
,0b11010010
,0b10010101
,0b01011010
,0b10101001
,0b01010101
,0b01011010
,0b10010101
,0b10101101
,0b00101001
,0b01010101
,0b10101010
,0b01010100
,0b11010101
,0b10100101
,0b01011010
,0b11001010
,0b01010101
,0b01011010
,0b10100101
,0b00101101
,0b01010101
,0b01010110
,0b10110010
,0b10010011
,0b01010110
,0b10010101
,0b00101011
,0b01010101
,0b01010101
,0b01101010
,0b01010100
,0b10101011
,0b01100101
,0b00101010
,0b10110101
,0b01010101
,0b01011010
,0b10010101
,0b00101011
,0b01010101
,0b00101010
,0b10110101
,0b01010011
,0b00110101
,0b10100100
,0b10101010
,0b11010101
,0b01001010
,0b10101010
,0b11010010
,0b10101101
,0b01100100
,0b10101010
,0b11010101
,0b01001010
,0b10101010
,0b10101010
,0b10101011
,0b01101001
,0b00101010
,0b10110101
,0b01001010
,0b10101010
,0b11001010
,0b10101011
,0b01010101
,0b00101010
,0b10101101
,0b01010010
,0b10101010
,0b10110010
,0b10101010
,0b11010101
,0b00101010
,0b10101011
,0b00101010
,0b10101010
,0b10101010
,0b10101010
,0b10110101
,0b00100101
,0b01011010
,0b10101010
,0b10010101
,0b01101010
,0b10011010
,0b10101101
,0b00100101
,0b01010110
,0b10101010
,0b10010101
,0b01010110
,0b10100101
,0b10101011
,0b01001001
,0b01010101
,0b10101010
,0b10010101
,0b01010110
,0b10100101
,0b01101010
,0b10101001
,0b01010101
,0b01101010
,0b10100101
,0b01010101
,0b01100101
,0b01010110
,0b10101010
,0b01010101
,0b01010110
,0b10010101
,0b01010101
,0b01010101
,0b01010101
,0b01101010
,0b10010101
,0b01001101
,0b01010101
,0b01001011
,0b01010101
,0b01010101
,0b01010101
,0b10100100
,0b10101010
,0b11010101
,0b01010010
,0b10101011
,0b01010100
,0b10110101
,0b01010101
,0b01001010
,0b10101011
,0b01010101
,0b00101010
,0b10101010
,0b10101010
,0b10101011
,0b01010100
,0b10101010
,0b10101010
,0b10101010
,0b10101010
,0b10101010
,0b10101010
,0b10101101
,0b01010010
,0b10100101
,0b10101010
,0b10101010
,0b01011010
,0b10101010
,0b10101010
,0b10110101
,0b01001010
,0b10010101
,0b10101010
,0b10101001
,0b01010110
,0b10101010
,0b10101010
,0b10101010
,0b10101010
,0b01010101
,0b01011010
,0b10101010
,0b10101010
,0b01010110
,0b10101010
,0b10101010
,0b10101010
,0b10101010
,0b01010101
,0b01010110
,0b10101010
,0b10101010
,0b10100101
,0b01011010
,0b10101010
,0b10101010
,0b10010101
,0b01010101
,0b10010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b01010101
,0b00000000";

#pragma romdata

//void Delay(unsigned int);
void main (void)
{   

    TRISD = 0x00;               // PORTD  als uitgang
    TRISB = 0b00110000;         // RB4 en RB5 als ingang
    TRISA = 0x00;               // RA output

    RCONbits.IPEN = 0;          // prioriteit uit
    INTCONbits.GIE = 1;         // enable interrupt
    INTCONbits.RBIE = 1;        // interrupt portB aan

    while(1)
    {   
        _asm sleep _endasm  
    }
}

#pragma interrupt ISR
void ISR (void)
{

    if (INTCONbits.RBIF==1)
    {
        if(PORTBbits.RB5==0) 
        {
            TBLPTR = (short long) 0x1200;

            for(i = 0 ; i<sizeof(my_const_array); i++) {
                _asm TBLRDPOSTINC _endasm
                LATAbits.LATA2=TABLAT;

                b = 0;

                do{
                    b++;
                }while(b < 200);



            }
        }
    }   
    INTCONbits.RBIF = 0;

}

2 个答案:

答案 0 :(得分:4)

这是一个开放式的问题,我无法给你绝对的答案,但我可以给你一些尝试。

  1. 您确定数据是否正确?取数组my_const_array []并编写一个小程序将其转换回8位wav并确保听到正确的声音。对我来说,你列出的波形数据看起来非常短,只有约430个样本,因此在8000Hz时声音将需要大约50ms才能播放。那是对的吗?同样,大约一半(200 +)个样本的值为'0b01010101'。

  2. 尝试切换每个字节的位排序,因此请翻转每个二进制值。 IE 0b01010101变为0b10101010

  3. 你是否以正确的速度计时?

  4. 我建议您将录制的语音样本替换为方波等更可测量的内容,然后记录输出以进行比较。

答案 1 :(得分:1)

你的程序可能错了!

我想您使用的是单位DAC,所以:

线..

LATAbits.LATA2=TABLAT;

只将第一个(零)位复制到CPU引脚RA2,其余7个丢失。