DAC1220使用参考代码


void SPI2_Init(void)  

{

// PB13:SCK2; PB14:MISO2; PB15:MOSI2;

GPIO_InitTypeDef GPIO_InitStructure;

RCC_APB2PeriphClockCmd ( RCC_APB2Periph_GPIOB,ENABLE );//



GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;

GPIO_Init(GPIOB, &GPIO_InitStructure);



GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_12|GPIO_Pin_13 |GPIO_Pin_15 ;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

GPIO_Init(GPIOB, &GPIO_InitStructure);

GPIO_ResetBits( GPIOB,GPIO_Pin_1|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_15 );



}




DAC1220//

void dac1220_init( void )

{

dac_cs_set(0);//



clk_delay(400);

dac1220_write(0x04);

clk_delay(400);

dac1220_write(0x02);

dac_cs_toggle(); ///toggle

/

dac1220_write(0x05);

clk_delay(400);

dac1220_write(0x00);

clk_delay(400);

dac_cs_set(1);//

clk_delay(800);

/

dac_cs_set(0);//

clk_delay(400);

dac1220_write(0x04);

clk_delay(400);

dac1220_write(0x00);

dac_cs_toggle(); ///toggle 

/

dac1220_write(0x05);

clk_delay(400);

dac1220_write(0xA1);

delay_ms(100);

dac_cs_set(1);//

delay_ms(50);

}



void dac1220_set( u32 value )

{

dac_cs_set(0);

clk_delay(800);

/

dac1220_write(0x00);

clk_delay(400);

dac1220_write( ( value>>12)&0xff );

dac_cs_toggle( );///cs toggle

//  

dac1220_write(0x01);

clk_delay(400);

dac1220_write( ( value>>4)&0xff );

dac_cs_toggle( );///cs toggle

//  

dac1220_write(0x02);

clk_delay(400);

dac1220_write( ( value<<4)&0xf0 );

dac_cs_toggle( );///cs toggle

//  

dac_cs_set(1);

delay_ms(200);

}



void dac1220_write( u8 dat )

{

  u8 i;

  sclk=0;

  mosi=0;

  for( i=0;i<8;i++)

  {

      clk_delay(80);

      sclk=1;

      clk_delay(80);

      mosi=( (dat&0x80) ? 1:0 );

      dat<<=1;

      clk_delay(80);

      sclk=0;

      clk_delay(80);

      mosi=0;

  }

}

void dac_cs_set(u8 sta )

{

cs1=sta;

}



void dac_cs_toggle( void )

{

  cs1=1;

  clk_delay(800);

  cs1=0;

  clk_delay(400);

}

//

void clk_delay(u16 delay_time )     

{

while( delay_time>0 )

{

delay_time--;

}

}

 

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 成长之路 设计师:Amelia_0503 返回首页