ADF4106配置

#include<c8051f330.h>


sbit clk   =  P0^0;
sbit dat   =  P0^2;
sbit le    =  P0^3;


unsigned char send1,send2;


void delay(unsigned char yc)
{
  while(--yc);
}


void init_mcu(void)
{  
  OSCICN = 0xc3;  
  OSCICL = 0x00;  
  PCA0MD = 0x00;
  XBR0 = 0x00;    
  XBR1 = 0x40;
  P0MDIN = 0xff;  //P0端口为数字输入
  P0MDOUT = 0xff; //P0端口推挽输出
  P0SKIP = 0x00;  //无引脚被跳过
  P1MDIN = 0xff;  //P1端口为数字输入
  P1MDOUT = 0xff; //端口P1.6为开漏输出,其它推挽开漏输出
  P1SKIP = 0x00;  //无引脚被跳过
}




void send_data(unsigned char temp)

  unsigned char i;
  clk=0;
  for(i=0;i<=7;i++)
  {
   
   temp=temp<<1;
   dat=CY;
   delay(50);
   clk=1;
   delay(50);
   clk=0;
  }
  clk=0;
}
void send_data16(unsigned int temp)

  unsigned char i;
  clk=1;
  temp=~temp;
  for(i=0;i<=15;i++)
  {
      temp=temp<<1;
   dat=CY;
   delay(50);
   clk=0;
   delay(50);
   clk=1;
  }
  clk=1;
}


void init_4106(void)
{
  le=0;
  delay(10);
  le=0;
  send_data(0x1F);
  send_data(0x80);
  send_data(0x93);//INIT REG
  delay(10);
  le=1;
  delay(10);
  le=0;
  send_data(0x1F);
  send_data(0x80);
  send_data(0x92);//FUNCTION REG
  delay(10);
  le=1;
  delay(10);
  le=0;
  send_data(0x00);
  send_data(0x11);
  send_data(0x0D);//N REG
  delay(10);
  le=1;
  delay(10);
  le=0;
  send_data(0x00);
  send_data(0x00);
  send_data(0x20);//R REG
  delay(10);
  le=1;
 }


  main()
  {
  unsigned char in;
  unsigned char buf;
  unsigned char calA;
  unsigned int calB;
   in=P0;
   buf=in;
   init_mcu();
   init_4106();
   while(1)
   {
  // in=P0;
   //if (buf!=in)
   //{
    //buf=in;
// calB=in+103;
// calA=in+103;//0-1030  31-1340
// calB=calB/8;
// calA=calA-calB*8;
// calA=calA*4+1;//(calA<<2)+1;
  //  le=0;
    //send_data16(calB);// N register former 16bits
//send_data(calA);// back 8 bits
//delay(10);
    //le=1;
   //}
   }
  }

你可能感兴趣的:(ADF4106)