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

📄 ad9852.asm

📁 控制ad9852
💻 ASM
字号:
//函数:_main
//功能:
//参数:
.include hardware.inc
.ram 
.var lxp_Delay_t;
.var FreqH;                 //频率控制字
.var FreqM;
.var FreqL;
.var ControlH;              //控制寄存器控制字
.var ControlL;
.var AMPL;                  //幅度控制字
.var Shape;                 //输出斜率控制字
.code
.public _main
_main:
init:
     r1 = 0x0000;
     [FreqH] = r1;
     r1 = 0x0000; 
     [FreqM] = r1;
     r1 = 0x0000;
     [FreqL] = r1;
     r1 = 0x1464;
     [ControlH] = r1;
     r1 = 0x8070;
     [ControlL] = r1;
     r1 = 0x0f00;
     [AMPL] = r1;
     r1 = 0xff00;
     [Shape] = r1;

     irq off;
     r1 =0x000f;               //IOB0为CS;IOB1为CLK;IOB2为SDIO;IOB3为UDC;
     [P_IOB_Dir] = r1;
     [P_IOB_Attrib] = r1; 
     r1 = 0x0000;
     [P_IOB_Data] = r1;



     r1 = 0x0002;
     push r1 to [sp];
     call _lxp_SPI_Write;
     pop r1 from [sp]; 

     r2 = [FreqH];
     r1 = r2;
     r1 = r1 lsr 4;
     r1 = r1 lsr 4;

     push r1 to [sp];
     call _lxp_SPI_Write;
     pop r1 from [sp]; 

     r1 = r2;
     r1 &= 0x00ff;

     push r1 to [sp];
     call _lxp_SPI_Write;
     pop r1 from [sp]; 

     r2 = [FreqM];
     r1 = r2;
     r1 = r1 lsr 4;
     r1 = r1 lsr 4;

     push r1 to [sp];
     call _lxp_SPI_Write;
     pop r1 from [sp]; 

     r1 = r2;
     r1 &= 0x00ff;

     push r1 to [sp];
     call _lxp_SPI_Write;
     pop r1 from [sp]; 

     r2 = [FreqL];
     r1 = r2;
     r1 = r1 lsr 4;
     r1 = r1 lsr 4;

     push r1 to [sp];
     call _lxp_SPI_Write;
     pop r1 from [sp]; 

     r1 = r2;
     r1 &= 0x00ff;

     push r1 to [sp];
     call _lxp_SPI_Write;
     pop r1 from [sp]; 



     r1 = 0x0007;
     push r1 to [sp];
     call _lxp_SPI_Write;
     pop r1 from [sp]; 

     r2 = [ControlH];
     r1 = r2;
     r1 = r1 lsr 4;
     r1 = r1 lsr 4;

     push r1 to [sp];
     call _lxp_SPI_Write;
     pop r1 from [sp]; 

     r1 = r2;
     r1 &= 0x00ff;

     push r1 to [sp];
     call _lxp_SPI_Write;
     pop r1 from [sp]; 

     r2 = [ControlL];
     r1 = r2;
     r1 = r1 lsr 4;
     r1 = r1 lsr 4;

     push r1 to [sp];
     call _lxp_SPI_Write;
     pop r1 from [sp]; 

     r1 = r2;
     r1 &= 0x00ff;

     push r1 to [sp];
     call _lxp_SPI_Write;
     pop r1 from [sp];



     r1 = 0x0008;
     push r1 to [sp];
     call _lxp_SPI_Write;
     pop r1 from [sp];

     r2 = [AMPL];
     r1 = r2;
     r1 = r1 lsr 4;
     r1 = r1 lsr 4;

     push r1 to [sp];
     call _lxp_SPI_Write;
     pop r1 from [sp];

     r1 = r2;
     r1 &= 0x00ff;

     push r1 to [sp];
     call _lxp_SPI_Write;
     pop r1 from [sp];



     r1 = 0x000a;
     push r1 to [sp];
     call _lxp_SPI_Write;
     pop r1 from [sp];

     r1 = [Shape];
     r1 = r1 lsr 4;
     r1 = r1 lsr 4;

     push r1 to [sp];
     call _lxp_SPI_Write;
     pop r1 from [sp];



     r1 = [P_IOB_Data];
     r1 |= 0x0008;
     [P_IOB_Data] = r1;



     r1 = [P_IOB_Data];
     r1 |= 0x0001;
     [P_IOB_Data] = r1;



//函数:_lxp_ShortDelay()
//功能:短延时
//说明:延时(lxp_Delay_t*2+2)个机器周期
.public _lxp_ShortDelay
_lxp_ShortDelay: .proc
      push r1 to [sp];
      r1 = [lxp_Delay_t];            
loop:
      r1 -= 1; 
      jnz loop;
      r1=0x0001;                      
      [P_Watchdog_Clear]=r1;	   //清看门狗
      pop r1 from [sp];
      retf
.endp
//函数:_lxp_LongDelay()
//功能:长延时
//说明:延时(lxp_Delay_t*2*6+8)个机器周期
.public _lxp_LongDelay
_lxp_LongDelay: .proc
      push r1,r2 to [sp];
      r1 = [lxp_Delay_t];
      r2 = r1;                     
      r1 = r1 lsl 2;   
      r1 += r2;                    //r1 *= 6;
      r1 += r2;                    //
loop1:
       r2=0x0001;                  //清看门狗
      [P_Watchdog_Clear]=r2;	
      r1 -= 1;
      jnz loop1;
      pop r1,r2 from [sp];
     retf
.endp
//函数:_lxp_SPI_Write()
//功能:向SPI 总线写入1 个字节的数据
//参数:dat:要写入的数据
.public _lxp_SPI_Write
_lxp_SPI_Write: .proc
     push r1,r5 to [sp];
     irq off;
     r1 = [P_IOB_Dir];
     r1 |= 0x0007;
     r1 &= 0xfff7;
     [P_IOB_Dir] = r1;
     [P_IOB_Attrib] = r1;
     bp = sp + 8;                  //bp指向参数
     r4 = [bp];                    //参数放入r4
     r3 = 8;                       //向SPI 总线写入八位数二进制数
loopx:
     test r4,0x80;
     jz DIO_0_1;                   //dat7为低,制DIO为0
     jmp DIO_1_1;                  //dat7为高,制DIO为1
DIO_0_1:
     r1 = [P_IOB_Data];            //lxp_pin_DIO = 0;
     r1 &= 0xfffb;                 //1&x = x;0&x = 0;    1111111111111011
     [P_IOB_Data] = r1;
     jmp zbt_1;
DIO_1_1:
     r1 = [P_IOB_Data];            //lxp_pin_DIO = 1;
     r1 |= 0x0004;                 //0|x = x;1|x = 1;    0000000000000100
     [P_IOB_Data] = r1;
zbt_1:
     r4 = r4 lsl 1;                //dat<<=1;
     r1 = [P_IOB_Data];         
     r1 |= 0x0002;
     [P_IOB_Data] = r1;            //lxp_pin_CLK = 1;
     call _lxp_ShortDelay;
     r1 = [P_IOB_Data];         
     r1 &= 0xfffd;
     [P_IOB_Data] = r1;            //lxp_pin_CLK = 0;
     call _lxp_ShortDelay;
     r3 -= 1;
     jnz loopx;
     irq on;
     pop r1,r5 from [sp];
     retf
     .endp

⌨️ 快捷键说明

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