使用pic 18f4550根据位值发音一种颜色 [英] pronounce a color based on the bits values with the pic 18f4550

查看:89
本文介绍了使用pic 18f4550根据位值发音一种颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新2

我想制作一个可以在我的pic 18f4550上播放声音(可以说红色,绿色和蓝色)的程序,并且在picdem上连接了一个扬声器,该部分效果很好,我编写了以下程序,其芯片版本为6.83使用C编译器.

当我说红色(这有位模式)时,我需要检索.wav文件的位值. 我的正确问题是,如何获取.wav文件的位值.

void main (void)
{   

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

    RCONbits.IPEN = 0;  // interrupts
    INTCONbits.GIE = 1; 
    INTCONbits.RBIE = 1;

    while(1)
    {   
        _asm sleep _endasm  
    }
}

#pragma interrupt ISR
void ISR (void)
{
    int red[] = {bit values off sound red???};
    int blue[] = {bit values off sound green???};
    int green[] = {bit values off sound blue???};


    if (INTCONbits.RBIF==1)
    {
        if(PORTBbits.RB5==0)        // S3 pressed?
        {
            int i = 0;
            int b;
            do {
                LATAbits.LATA2 = rood[i];
                LATDbits.LATD1 ^= 1;
                b = 0;

                //do-while voor de frequentie (1500 is de freq)
                do {
                    b++;
                }while(b <= 2000);

                i++;
            }while(rood[i] <= 50);

            //LATDbits.LATD1 ^= 1;      // D2 togglen

        }

    }   
    INTCONbits.RBIF = 0;
}

解决方案

原始问题的答案: 您要求的红色频率,以位表示"是480至405 THz,因此以位为111100000至110010101.但是您也说以纳米为单位",因此是630至740nm,即1001110110至1011100100以二进制形式.如果要使用波形驱动扬声器,则需要采样音频波形或语音合成芯片.无论哪种情况,我给您的二进制值都与单词"red"的声音无关,后者需要更多的位来表示任何可听见的声音(例如,在16 kbps PCM上至少需要0.5秒,PCM才是8 kbp = 1 KB).

另一种以二进制表示颜色的方法是RGB系统,其中红色为0xFF0000,二进制为111111110000000000000000.

有关如何获取wav文件中位的问题的答案 首先,我们必须确定wav文件的存储位置.它可以作为const数组存储在PIC中,也可以存储在外部存储设备中,您必须通过某种串行或并行总线来读取它.由于PIC18F4550具有32k字节的闪存,因此,如果程序很小,则可能会为3个wav文件留出足够的空间.

然后,我们必须确定硬件如何播放声音.您似乎正在尝试通过移位从位端口发送字节值.但是要正确处理此问题,我们需要了解更多有关硬件的信息,因为您无法将扬声器连接到位端口并期望发出声音(无论如何也不能不进一步处理PCM信号-您是否尝试 解决方案

Answer to original question: The "frequency of red, represent in bits" you asked for is 480 to 405 THz, so in bits that is 111100000 to 110010101. But you also said "its defined in nanometers", so that is 630 to 740nm which is 1001110110 to 1011100100 in binary. If you want to drive a loudspeaker with a waveform, you need either a sample audio waveform or a speech synthesis chip. In either case, the binary values I have given you have nothing to do with the sound of the word "red" which would need many more bits to represent any audible sound (eg a minimum of 0.5 second at 16 kbps PCM would be 8 kbp = 1 kbyte).

Another way representing a colour in binary is the RGB system where red would be 0xFF0000, which is 111111110000000000000000 in binary.

Answer to question on how to get bits in wav file First we have to determine where the wav file is stored. It could be stored as a const array in the PIC, or in an external memory device where you have to read it over some kind of serial or parallel bus. Since the PIC18F4550 has 32k bytes of flash, if your program is fairly small there could be enough room left for the 3 wav files.

Then we have to determine how the hardware is going to play the sound. You seem to be attempting to send a byte value out of bit port by shifting it. But to get this right we need to know more about the hardware, because you cannot connect a speaker to a bit port and expect sound out (not without further processing of a PCM signal anyway - are you attempting a 1 bit DAC design? If so, there are further notes here but this is quite ambitious).

Apart from that, the bit values in wav file, would be obtained by obtaining each sample (8 bit?) in the file and shifting a mask value of 0x01 round with a bitwise AND operation to determine which bits were set.

这篇关于使用pic 18f4550根据位值发音一种颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆