⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 joy.c

📁 /* DSK6713 功能:无任何键按下时4个灯闪烁并放音8s(事先存好在 flash 0x90020000--0x90040000里)可在led2程序中修改内容 * 当第一个键按下时LED
💻 C
字号:


/* 功能:无任何键按下时4个灯闪烁并放音8s(事先存好在 flash  0x90020000--0x90040000里)可在led2程序中修改内容
 *      当第一个键按下时LED0点亮,音乐通过line in直通输出
 *      当第二个键按下时LED1点亮,音乐通过line in直通加密后输出
 *      当第三个键按下时LED2点亮,音乐通过line in直通加密后输出
 *      当第四个键按下时LED3闪开始录音,话筒输入录音4s后播放 (存在 flash  0x90010000--0x90020000)  
 */
/*
 *  DSP/BIOS is configured using the DSP/BIOS configuration tool.  Settings
 *  for this example are stored in a configuration file called led.cdb.  At
 *  compile time, Code Composer will auto-generate DSP/BIOS related files
 *  based on these settings.  A header file called ledcfg.h contains the
 *  results of the autogeneration and must be included for proper operation.
 *  The name of the file is taken from led.cdb and adding cfg.h.
 */
#include "joycfg.h"

/*
 *  The 6713 DSK Board Support Library is divided into several modules, each
 *  of which has its own include file.  The file dsk6713.h must be included
 *  in every program that uses the BSL.  This example also includes
 *  dsk6713_led.h and dsk6713_dip.h because it uses the LED and DIP modules.
 */
#include "dsk6713.h"
#include "dsk6713_led.h"
#include "dsk6713_dip.h"
#include "dsk6713_aic23.h"
#include "dsk6713_flash.h"

#define AUDIOPASS 0
#define AUDIOCODE 1
#define AUDIODECODE 2
#define RECORDPLAY 3  
#define BLINK 4 
#define FLASH_ADDR 0x90010000                //录音存放起始地址
#define FLASH_ADDR_MAX 0x90020000            //录音存放结束地址共64k空间,8k sampling,时长4s


Uint32 flashaddress,i;
Uint32 data32;
Uint16 data16,data161,data162;    //data16 将32位转换成16位,data161,data162 加密解密
Uint8  data8;                    //data8 将16位转换成8位

Int choose,time=0;               //choose 开关控制选择        time 解密时选择对应钥匙

/* Codec configuration settings */
 DSK6713_AIC23_Config config = { \
    0x0017,  /* 0 DSK6713_AIC23_LEFTINVOL  Left line input channel volume */ \
    0x0017,  /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume */\
    0x01f9,  /* 2 DSK6713_AIC23_LEFTHPVOL  Left channel headphone volume */  \
    0x01f9,  /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */ \
    0x0011,  /* 4 DSK6713_AIC23_ANAPATH    Analog audio path control :line in*/      \
    0x0000,  /* 5 DSK6713_AIC23_DIGPATH    Digital audio path control */     \
    0x0000,  /* 6 DSK6713_AIC23_POWERDOWN  Power down control */             \
    0x0043,  /* 7 DSK6713_AIC23_DIGIF      Digital audio interface format */ \
    0x0001,  /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control 48khz*/            \
    0x0001   /* 9 DSK6713_AIC23_DIGACT     Digital interface activation */   \
};

  
 /* Codec configuration settings */
  DSK6713_AIC23_Config config1 = { \
    0x0017,  /* 0 DSK6713_AIC23_LEFTINVOL  Left line input channel volume */ \
    0x0017,  /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume */\
    0x01f9,  /* 2 DSK6713_AIC23_LEFTHPVOL  Left channel headphone volume */  \
    0x01f9,  /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */ \
    0x0015,  /* 4 DSK6713_AIC23_ANAPATH    Analog audio path control:mic */      \
    0x0000,  /* 5 DSK6713_AIC23_DIGPATH    Digital audio path control */     \
    0x0000,  /* 6 DSK6713_AIC23_POWERDOWN  Power down control */             \
    0x0043,  /* 7 DSK6713_AIC23_DIGIF      Digital audio interface format */ \
    0x000d,  /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control 8khz*/            \
    0x0001   /* 9 DSK6713_AIC23_DIGACT     Digital interface activation */   \
  };


/*
 *  main() - Main code routine, initializes BSL and runs LED application
 */
 
void main()
{   
    DSK6713_AIC23_CodecHandle hCodec;      
    
    /* Initialize the board support library, must be first BSL call */
    DSK6713_init();
    
    /*  Start the codec */    
    hCodec = DSK6713_AIC23_openCodec(0, &config1);
     
    /* Initialize the LED and DIP switch modules of the BSL */
    DSK6713_LED_init();
    DSK6713_DIP_init();
       
       
     
    while(1)  {  
    
    if (DSK6713_DIP_get(0) == 0) choose= AUDIOPASS;
      else if (DSK6713_DIP_get(1) == 0) choose= AUDIOCODE;
      else if (DSK6713_DIP_get(2) == 0) choose= AUDIODECODE;
      else if (DSK6713_DIP_get(3) == 0) choose= RECORDPLAY;
      else  choose=BLINK;
    
      switch(choose)
       {  
       
           
        case AUDIOPASS://直通采样率48k
        
           DSK6713_AIC23_closeCodec(hCodec);  
           hCodec = DSK6713_AIC23_openCodec(0, &config);
        
           while(1) 
           {
             if(DSK6713_DIP_get(1) == 0||DSK6713_DIP_get(2) == 0||DSK6713_DIP_get(3) == 0) 
               {DSK6713_LED_off(0);break;}
             DSK6713_LED_on(0);
             /* Read a sample from the left channel */
             while (!DSK6713_AIC23_read(hCodec,&data32));
             
             
             /* Send a sample to the left channel */
             while (!DSK6713_AIC23_write(hCodec,data32));            
  	                       
            } 
            
                   
        
        case AUDIOCODE: //直通加密
        
            DSK6713_AIC23_closeCodec(hCodec);  
            hCodec = DSK6713_AIC23_openCodec(0, &config);
           
            while(1)
             {  
                if(DSK6713_DIP_get(0) == 0||DSK6713_DIP_get(2) == 0||DSK6713_DIP_get(3) == 0) 
                  {DSK6713_LED_off(1);break;}
               DSK6713_LED_on(1);
               /* Read a sample from the left channel */
               while (!DSK6713_AIC23_read(hCodec,&data32));
               data161=data32;
               //加密
                 if(time==0)
                   {data162=data161&0x0ff;time=1;}
                   
                  else if
                   (time==1)
                   {data162=data161&0xff00;time=0;}
                
              /* Send a sample to the left channel */
              while (!DSK6713_AIC23_write(hCodec,data162));
                                                                                     
           } break;
           
           
        case AUDIODECODE:          //直通解密
           DSK6713_AIC23_closeCodec(hCodec);  
           hCodec = DSK6713_AIC23_openCodec(0, &config);
        
           while(1)
            {
              if(DSK6713_DIP_get(0) == 0||DSK6713_DIP_get(1) == 0||DSK6713_DIP_get(3) == 0) 
                {DSK6713_LED_off(2);break;}
              
              DSK6713_LED_on(2);            
            
              /* Read a sample from the left channel */
              while (!DSK6713_AIC23_read(hCodec,&data32));
                 data161=data32;
                //加密
                 if(time==0)
                   {data162=data161^0x0ff;time=1;}
                   
                  else if
                   (time==1)
                   {data162=data161^0xff00;time=0;}
                  //解密 
                  if(time==1)
                    {data162=data162^0x0ff;time=0;}
                   
                   else if
                    (time==0)
                    {data162=data162^0xff00;time=1;}
                   
                                
             /* Send a sample to the left channel */
             while (!DSK6713_AIC23_write(hCodec,data162));           
          
           
          
             }break;
            
       case  RECORDPLAY: //录音播放
           DSK6713_AIC23_closeCodec(hCodec);  
           hCodec = DSK6713_AIC23_openCodec(0, &config1);
           if(DSK6713_DIP_get(0) == 0||DSK6713_DIP_get(1) == 0||DSK6713_DIP_get(2) == 0) 
              {DSK6713_LED_off(3);break;}
              
           DSK6713_FLASH_erase(FLASH_ADDR, DSK6713_FLASH_PAGESIZE*2);
                        
           
           for(i=0;i<6;i++)
               {
                  DSK6713_LED_toggle(3);
                  DSK6713_waitusec(200000);         
                }
            //接收数据4s 16bit量化成8bit保存在flash中 8k采样 64k空间可保存4s
            
           flashaddress=FLASH_ADDR;
            
           while(1)
             {
                   
               while (!DSK6713_AIC23_read(hCodec,&data32));
               data16=data32;             
               data8=data16/256;
                
               //copy one 8bit from data1 to flashaddess 
               DSK6713_FLASH_write((Uint32)&data8, flashaddress,1);
               // while (!DSK6713_AIC23_write(hCodec,data16));          
               flashaddress++;
               if(flashaddress-FLASH_ADDR_MAX==0)break;              
                       	                      
              }
           
           DSK6713_LED_on(3);
           
           flashaddress=FLASH_ADDR;
           while(1)
             {                           
                DSK6713_FLASH_read(flashaddress, (Uint32)&data8, 1);
                data16=data8*256; 
             
                while (!DSK6713_AIC23_write(hCodec,data16));
                        
                flashaddress++;
                if(flashaddress-FLASH_ADDR_MAX==0)break; 
                        
                       	                      
             }
        
           
           
               DSK6713_LED_off(3);
               
               break;           
           
           
        case BLINK:
             DSK6713_AIC23_closeCodec(hCodec);  
             hCodec = DSK6713_AIC23_openCodec(0, &config1);
                // Toggle all LEDs  
                                
             while(1)
                 {
                 if(DSK6713_DIP_get(0) == 0||DSK6713_DIP_get(1) == 0||DSK6713_DIP_get(2) == 0||DSK6713_DIP_get(3) == 0) 
                   {DSK6713_LED_off(0);
                    DSK6713_LED_off(1);
                    DSK6713_LED_off(2);
                    DSK6713_LED_off(3);
                    break;}
                   
                 DSK6713_LED_off(0);
                 DSK6713_LED_off(1);
                 DSK6713_LED_off(2);
                 DSK6713_LED_off(3);
                 
                 //流水灯
                 for(i=0;i<4;i++)
                  {
                    DSK6713_LED_toggle(0);DSK6713_waitusec(200000);
                    DSK6713_LED_toggle(1);DSK6713_waitusec(200000);
                    DSK6713_LED_toggle(2);DSK6713_waitusec(20000);
                    DSK6713_LED_toggle(3);DSK6713_waitusec(200000);         
                   }
                    
                  //接力灯
               /*   for(i=0;i<4;i++)
                   {
                    DSK6713_LED_toggle(0);
                    DSK6713_LED_toggle(2);DSK6713_waitusec(400000);
                    DSK6713_LED_toggle(1);
                    DSK6713_LED_toggle(3);DSK6713_waitusec(400000);         
                   }
                    
                    //放音提示  All LED blink three times
                   for(i=0;i<5;i++)
                    {
                      DSK6713_LED_toggle(0);DSK6713_LED_toggle(1);
                      DSK6713_LED_toggle(2);DSK6713_LED_toggle(3);
                      DSK6713_waitusec(200000);         
                     }
                 
                flashaddress=0x90020000; //放音数据存放起始地址                   
   
                while(1)
                 {                           
                   DSK6713_FLASH_read(flashaddress, (Uint32)&data8, 1);
                   data16=data8<<8; 
               
                   while (!DSK6713_AIC23_write(hCodec,data16));
                         
                   flashaddress++;
                   if( flashaddress==0x9003d000) flashaddress=0x9003e000;
                   if(flashaddress-0x90040000==0)break; 
                       
                       	                      
                  } */
               
                   
              }//外层 while                      
        
        
       }//switch 配对   
       
   }//外层while配对

           
} //main结束          
                  
                            

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -