AD9516

/******************************************
*
* Description: AD9516-1 config.
* Author:LY
* Date: 2013-07-24 
*
******************************************/
#include <C8051F340.h>
#include "public.h"
#include <intrins.h>


void Byte_Write_AD1(uint addr,uchar dat)
{
   uchar i,j;
   Sclk = 0;
   Cs1 = 0;
   for(j = 0;j < 16;j++)
   {
     Sclk = 0;        //在SCLK的上升沿写出一位,高位在前,低位在后
     if(addr & 0x8000)
        Sdio  = 1;
     else 
        Sdio  = 0;
     _nop_();
     Sclk = 1;
     _nop_();
     addr = addr << 1; 
   }
   for( i = 0;i < 8;i++)
   { 
      Sclk = 0;        //在SCLK的上升沿写出一位,高位在前,低位在后
      if(dat & 0x80)
         Sdio  = 1;
      else
         Sdio  = 0;
      //Sclk = 0;        //在SCLK的上升沿写出一位,高位在前,低位在后
      _nop_();
      Sclk = 1;
      _nop_();
      dat = dat << 1;
   }
   Cs1 = 1;
}


void Byte_Write_AD2(uint addr,uchar dat)
{
   uchar i,j;
   Sclk = 0;
   Cs2 = 0;
   for(j = 0;j < 16;j++){
     Sclk = 0;        //在SCLK的上升沿写出一位,高位在前,低位在后
     if(addr & 0x8000)
        Sdio  = 1;
     else 
        Sdio  = 0;
     _nop_();
     Sclk = 1;
     _nop_();
     addr = addr << 1; 
   }
   for( i = 0;i < 8;i++){ 
      Sclk = 0;        //在SCLK的上升沿写出一位,高位在前,低位在后
      if(dat & 0x80)
         Sdio  = 1;
      else
         Sdio  = 0;
      //Sclk = 0;        //在SCLK的上升沿写出一位,高位在前,低位在后
      _nop_();
      Sclk = 1;
      _nop_();
      dat = dat << 1;
   }
   Cs2 = 1;
}


#ifdef SDO_READ
uchar Byte_Read_AD1(uint addr)//,uchar id
{
   uchar i;
   uint  send_addr;
   uchar receive_data;


   send_addr = addr & 0x1FFF;
   send_addr |= 0x8000;


   Sdio = 0x0;//Sdio
   Cs1 = 0x0;
   for(i=0; i<16; i++)
   {
      Sclk = 0x0;
 if(send_addr & 0x8000)
 {
    Sdio = 0x1;
 }
 else
 {
    Sdio = 0x0;
 }
 send_addr <<= 1;
 Delay(1);
      Sclk = 0x1;
 Delay(1);
   }


   receive_data = 0x00;
   for(i=0; i<8; i++)
   {
      Sclk = 0x0;
 receive_data <<= 1;
 Sdo1=1; //sdo
 if(Sdo1) //sdo
 {
    receive_data |= 0x01;
 }
 Delay(1);
      Sclk = 0x1;
 Delay(1);
   }
   Cs1 = 0x1;
   return(receive_data);
}
uchar Byte_Read_AD2(uint addr)//,uchar id
{
   uchar i;
   uint  send_addr;
   uchar receive_data;


   send_addr = addr & 0x1FFF;
   send_addr |= 0x8000;


   Sdio = 0x0;//Sdio
   Cs2 = 0x0;
   for(i=0; i<16; i++)
   {
      Sclk = 0x0;
 if(send_addr & 0x8000)
 {
    Sdio = 0x1;
 }
 else
 {
    Sdio = 0x0;
 }
 send_addr <<= 1;
 Delay(1);
      Sclk = 0x1;
 Delay(1);
   }


   receive_data = 0x00;
   for(i=0; i<8; i++)
   {
      Sclk = 0x0;
 receive_data <<= 1;
 Sdo2=1; //sdo
 if(Sdo2) //sdo
 {
    receive_data |= 0x01;
 }
 Delay(1);
      Sclk = 0x1;
 Delay(1);
   }
   Cs2 = 0x1;
   return(receive_data);
}
#else 
#if 0 
uchar Byte_Read_AD1(uint addr)//,uchar id
{
   uchar i;
   uint  send_addr;
   uchar receive_data;


   send_addr = addr & 0x1FFF;
   send_addr |= 0x8000;


   Sdio = 0;//Sdio
   Cs1 = 0;
   for(i=0; i<16; i++)
   {
      Sclk = 0x0;
 if(send_addr & 0x8000)
 {
    Sdio = 0x1;
 }
 else
 {
    Sdio = 0x0;
 }
 send_addr <<= 1;
 Delay(1);
      Sclk = 0x1;
 Delay(1);
   }
   Delay(1);
   receive_data = 0x00;
   for(i=0; i<8; i++)
   {
      Sclk = 0x0;
 receive_data <<= 1;
 Sdio=1; //sdo
 if(Sdio)//sdo
 {
    receive_data |= 0x01;
 }    
 Delay(1);
      Sclk = 1;
 Delay(1);
   }
   Cs1 = 1; 
   return(receive_data);

#endif
#endif


void Init_9516_1()//40/8*480=2400   /24=100M
{ //01356路
Byte_Write_AD1(0x0000,0x18);
Byte_Write_AD1(0x0001,0x00);
Byte_Write_AD1(0x0002,0x10);
Byte_Write_AD1(0x0003,0x41);
Byte_Write_AD1(0x0004,0x00);
Byte_Write_AD1(0x0010,0x7C);
Byte_Write_AD1(0x0011,0x08);
Byte_Write_AD1(0x0012,0x00);
Byte_Write_AD1(0x0013,0x00);
Byte_Write_AD1(0x0014,0x3C);
Byte_Write_AD1(0x0015,0x00);
Byte_Write_AD1(0x0016,0x04);
Byte_Write_AD1(0x0017,0x08);
Byte_Write_AD1(0x0018,0x07);        
Byte_Write_AD1(0x0019,0x00);        
Byte_Write_AD1(0x001A,0x00);        
Byte_Write_AD1(0x001B,0x27);        
Byte_Write_AD1(0x001C,0x02);        
Byte_Write_AD1(0x001D,0x00);        
Byte_Write_AD1(0x001E,0x00);        
Byte_Write_AD1(0x001F,0x0E);        
Byte_Write_AD1(0x00A0,0x01);        
Byte_Write_AD1(0x00A1,0x00);        
Byte_Write_AD1(0x00A2,0x00);        
Byte_Write_AD1(0x00A3,0x01);        
Byte_Write_AD1(0x00A4,0x00);        
Byte_Write_AD1(0x00A5,0x00);        
Byte_Write_AD1(0x00A6,0x01);        
Byte_Write_AD1(0x00A7,0x00);        
Byte_Write_AD1(0x00A8,0x00);        
Byte_Write_AD1(0x00A9,0x01);        
Byte_Write_AD1(0x00AA,0x00);        
Byte_Write_AD1(0x00AB,0x00);        
Byte_Write_AD1(0x00F0,0x08);        
Byte_Write_AD1(0x00F1,0x0C);        
Byte_Write_AD1(0x00F2,0x0A);        
Byte_Write_AD1(0x00F3,0x08);        
Byte_Write_AD1(0x00F4,0x0A);        
Byte_Write_AD1(0x00F5,0x08);        
Byte_Write_AD1(0x0140,0x42);        
Byte_Write_AD1(0x0141,0x43);        
Byte_Write_AD1(0x0142,0x53);        
Byte_Write_AD1(0x0143,0x43);        
Byte_Write_AD1(0x0190,0x22);        
Byte_Write_AD1(0x0191,0x00);        
Byte_Write_AD1(0x0192,0x00);        
Byte_Write_AD1(0x0193,0x22);        
Byte_Write_AD1(0x0194,0x00);        
Byte_Write_AD1(0x0195,0x00);        
Byte_Write_AD1(0x0196,0x22);        
Byte_Write_AD1(0x0197,0x00);        
Byte_Write_AD1(0x0198,0x00);        
Byte_Write_AD1(0x0199,0x22);        
Byte_Write_AD1(0x019A,0x00);        
Byte_Write_AD1(0x019B,0x00);        
Byte_Write_AD1(0x019C,0x20);        
Byte_Write_AD1(0x019D,0x00);        
Byte_Write_AD1(0x019E,0x22);        
Byte_Write_AD1(0x019F,0x00);        
Byte_Write_AD1(0x01A0,0x00);        
Byte_Write_AD1(0x01A1,0x20);        
Byte_Write_AD1(0x01A2,0x00);        
Byte_Write_AD1(0x01A3,0x00);        
Byte_Write_AD1(0x01E0,0x02);        
Byte_Write_AD1(0x01E1,0x02);        
Byte_Write_AD1(0x0230,0x00);        
Byte_Write_AD1(0x0231,0x00);        
Byte_Write_AD1(0x0232,0x00);  
Byte_Write_AD1(0x0232,0x01);
Delay(10);
Sync1=0;//低电平有效 同步
Delay(100);
Sync1=1;



void Init_9516_2()//40/8*480=2400   /20=120M
{
uchar temp;
//06789路
Byte_Write_AD2(0x0000,0x18);
Byte_Write_AD2(0x0001,0x00);
Byte_Write_AD2(0x0002,0x10);
Byte_Write_AD2(0x0003,0x41);
Byte_Write_AD2(0x0004,0x00);
Byte_Write_AD2(0x0010,0x7C);        
Byte_Write_AD2(0x0011,0x08);
Byte_Write_AD2(0x0012,0x00);        
Byte_Write_AD2(0x0013,0x00);        
Byte_Write_AD2(0x0014,0x3C);        
Byte_Write_AD2(0x0015,0x00);        
Byte_Write_AD2(0x0016,0x04);        
Byte_Write_AD2(0x0017,0x08);
Byte_Write_AD2(0x0018,0x07);
Byte_Write_AD2(0x0019,0x00);        
Byte_Write_AD2(0x001A,0x00);        
Byte_Write_AD2(0x001B,0x27);        
Byte_Write_AD2(0x001C,0x02);        
Byte_Write_AD2(0x001D,0x00);        
Byte_Write_AD2(0x001E,0x00);        
Byte_Write_AD2(0x001F,0x0E);        
Byte_Write_AD2(0x00A0,0x01);        
Byte_Write_AD2(0x00A1,0x00);        
Byte_Write_AD2(0x00A2,0x00);        
Byte_Write_AD2(0x00A3,0x01);        
Byte_Write_AD2(0x00A4,0x00);        
Byte_Write_AD2(0x00A5,0x00);        
Byte_Write_AD2(0x00A6,0x01);        
Byte_Write_AD2(0x00A7,0x00);        
Byte_Write_AD2(0x00A8,0x00);        
Byte_Write_AD2(0x00A9,0x01);        
Byte_Write_AD2(0x00AA,0x00);
Byte_Write_AD2(0x00AB,0x00);        
Byte_Write_AD2(0x00F0,0x08);        
Byte_Write_AD2(0x00F1,0x0E);        
Byte_Write_AD2(0x00F2,0x0A);        
Byte_Write_AD2(0x00F3,0x1A);        
Byte_Write_AD2(0x00F4,0x0A);        
Byte_Write_AD2(0x00F5,0x0A);        
Byte_Write_AD2(0x0140,0x4A);        
Byte_Write_AD2(0x0141,0x4A);        
Byte_Write_AD2(0x0142,0x5A);        
Byte_Write_AD2(0x0143,0x4A);        
Byte_Write_AD2(0x0190,0x44);        
Byte_Write_AD2(0x0191,0x00);        
Byte_Write_AD2(0x0192,0x00);        
Byte_Write_AD2(0x0193,0x44);        
Byte_Write_AD2(0x0194,0x00);        
Byte_Write_AD2(0x0195,0x00);        
Byte_Write_AD2(0x0196,0x44);        
Byte_Write_AD2(0x0197,0x00);    
Byte_Write_AD2(0x0198,0x00);        
Byte_Write_AD2(0x0199,0x44);        
Byte_Write_AD2(0x019A,0x00);        
Byte_Write_AD2(0x019B,0x00);        
Byte_Write_AD2(0x019C,0x20);        
Byte_Write_AD2(0x019D,0x00);        
Byte_Write_AD2(0x019E,0x44);        
Byte_Write_AD2(0x019F,0x00);        
Byte_Write_AD2(0x01A0,0x00);        
Byte_Write_AD2(0x01A1,0x20);        
Byte_Write_AD2(0x01A2,0x00);        
Byte_Write_AD2(0x01A3,0x00);        
Byte_Write_AD2(0x01E0,0x00);        
Byte_Write_AD2(0x01E1,0x02);        
Byte_Write_AD2(0x0230,0x00);        
Byte_Write_AD2(0x0231,0x00);        
Byte_Write_AD2(0x0232,0x00);
Byte_Write_AD2(0x0232,0x01);
Delay(10);
// Sync2=0;//低电平有效
// Delay(100);
// Sync2=1;


//测试ADF9516读写
#ifdef SDO_READ
Byte_Write_AD1(0x00, 0x99); //16-bit instruction,MSB firs,SDO used for read, SDIO used for write,default(18) 99:SDO For Read.
Byte_Write_AD2(0x00, 0x99);
#else
Byte_Write_AD1(0x00, 0x18); //SDIO for read and write.
Byte_Write_AD2(0x00, 0x18);
#endif
    temp = Byte_Read_AD1(0x03);  //read AD9516 Part ID,AD9516-0,4: 0x01,0x41,0x81,0x43,0xC3 ;41
temp = Byte_Read_AD2(0x03);//*/

/* for(i=0;i<20;i++){//Test_FPGA_Read_And_Write
XBYTE[0x2000]=i;
Delay(100);
temp = XBYTE[0x2000];
if(temp!=i)
Delay(10);
}//*/
  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值