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

📄 test.c

📁 基于ti公司TMS320C5416编写的语言程序
💻 C
字号:
#include "math.h"
#pragma CODE_SECTION(vect,"vect")
ioport    unsigned port8006; //ad
ioport    unsigned port8007; //ad

unsigned int *pmem=0;
#define IMR    *(pmem+0x0000)
#define IFR    *(pmem+0x0001)
#define PMST   *(pmem+0x001d)
#define SWCR   *(pmem+0x002b)
#define SWWSR  *(pmem+0x0028)
#define CLKMD  *(pmem+0x0058)


/*mcbsp1*/
#define SPSA1  *(pmem+0x0038)
#define SPSD1  *(pmem+0x0039)
#define DRR11  *(pmem+0x0021)
#define DRR21  *(pmem+0x0020)
#define DXR11  *(pmem+0x0023)
#define DXR21  *(pmem+0x0022)
#define DMPREC *(pmem+0x0054)

/*mcbsp1 subadress*/
#define PCR1    0x000e              
#define RCR11   0x0002
#define RCR21   0x0003
#define XCR11   0x0004
#define XCR21   0x0005
#define SPCR11  0x0000
#define SPCR21  0x0001

unsigned int rrdy,xrdy;
unsigned int data_buffer;

void cpu_init()          /*初始化DSP*/
{
   asm(" ssbx intm");
   PMST=0x24a0;      
   SWWSR=0x6fff;
   SWCR=0x0000;
   CLKMD=0x6007;
   IMR=0; 
   IFR=0xff;   
}
 
void delay()              /*WAIT*/
{
   asm(" STM #0008h, AR0"); 
   asm(" RPT *AR0"); 		
   asm(" NOP");
}    		

void mcbsp_init()
{      
   SPSA1=SPCR11;
   SPSD1=0x0000;
   SPSA1=SPCR21;
   SPSD1=0x0200;
   SPSA1=PCR1;        
   SPSD1=0x000c;            /*PCR1=000CH*/
   SPSA1=SPCR11;
   SPSD1=0x0000;
   SPSA1=SPCR21;
   SPSD1=0x0000;
   SPSA1=RCR11;
   SPSD1=0x0040;            /*RCR1=0040H*/
   SPSA1=RCR21;
   SPSD1=0x0004;            /*RCR2=0004H*/
   SPSA1=XCR11;
   SPSD1=0x0040;            /*XCR1=0040H*/
   SPSA1=XCR21;
   SPSD1=0x0004;            /*XCR2=0004H*/
   delay();  
   DMPREC=DMPREC&0xff3f;    /*BRINT,BXINT*/
   
   DXR11=0;                 
   
   /*启动MCBSp串口*/
   SPSA1=SPCR11;
   SPSD1=0x0001;            
   SPSA1=SPCR21;
   SPSD1=0x0201;
   delay();
}

void aic_init()
{ 
   IMR=IMR|0x030;
                       
   DXR11=0x0001;            /*DIN的LSB为1,与AD50二次通讯*/
   xrdy=0;  
   while(!xrdy)           
   {
     SPSA1=SPCR21;
     xrdy=(SPSD1&0x0002)>>1; 
   }
        
   DXR11=0x0100;            /*设置Control1寄存器*/                     
   xrdy=0;
   while(!xrdy)           
   {
     SPSA1=SPCR21;
     xrdy=(SPSD1&0x0002)>>1;
   }
                             
   DXR11=0x0001;           /*DIN的LSB为1,与AD50二次通讯*/
   xrdy=0;
   while(!xrdy)           
   {
     SPSA1=SPCR21;
     xrdy=(SPSD1&0x0002)>>1;
   } 
       
   DXR11=0x0445;            /*设置Control4寄存器*/
   xrdy=0;
   while(!xrdy)           
   {
     SPSA1=SPCR21;
     xrdy=(SPSD1&0x0002)>>1;
   }     
   
   asm(" rsbx intm"); 
   DXR11=DRR11;             /*传送一个哑元,结束操作*/  
}


main()
{
   cpu_init(); 
   mcbsp_init(); 
   aic_init();
   for(;;)
   {
   port8007=port8006/2;
   }          
} 

interrupt void brint0_int()
{
   data_buffer=DRR11;
   DXR11=data_buffer&0xfffe;
} 

interrupt void bxint0_int()
{
   
   asm(" rsbx xf");	
}                                     

#pragma CODE_SECTION(vect,"vect")
void  vect()
{
   asm(" .ref _c_int00");
   asm(" .ref _brint0_int");
   asm(" .ref _bxint0_int");

   asm(" b _c_int00");  /* reset */
   asm(" nop");
   asm(" nop");

   asm(" rete");        /* nmi  */
   asm(" nop");
   asm(" nop");
   asm(" nop");

   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");

   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");

   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");

   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");

   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");

   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");

   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");

   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");

   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");

   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");

   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");

   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");

   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
 
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");

   asm(" rete");       /* int0 */
   asm(" nop");
   asm(" nop");
   asm(" nop");

   asm(" rete");       /* int1 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
 
   asm(" rete");       /* int2 */
   asm(" nop");
   asm(" nop");
   asm(" nop");

   asm(" rete");       /* tint0 */
   asm(" nop");
   asm(" nop");
   asm(" nop");

   asm(" b _brint0_int");      /* brint0 */
   asm(" nop");
   asm(" nop");

   asm(" b _bxint0_int");      /* bxint0 */
   asm(" nop");
   asm(" nop");
  
   asm(" rete");      /* dmac0 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
  
   asm(" rete");       /* tint1 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   
   asm(" rete");       /* int3 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   
   asm(" rete");       /* hpint */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   
   asm(" nop");       /* brint1 */
   asm(" nop");  
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" nop");       /* bxint1 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");       /* dmac4 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" nop");        /* dmac5 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" nop");
}

⌨️ 快捷键说明

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