基于STM32的AD9851并行源代码
- 格式:doc
- 大小:22.00 KB
- 文档页数:3
#include"stm32f10x.h"
#define ad9851_rest_l GPIO_ResetBits(GPIOC,GPIO_Pin_0)
#define ad9851_rest_h GPIO_SetBits(GPIOC,GPIO_Pin_0)
#define ad9851_fq_up_l GPIO_ResetBits(GPIOC,GPIO_Pin_1)
#define ad9851_fq_up_h GPIO_SetBits(GPIOC,GPIO_Pin_1)
#define ad9851_w_clk_l GPIO_ResetBits(GPIOC,GPIO_Pin_2)
#define ad9851_w_clk_h GPIO_SetBits(GPIOC,GPIO_Pin_2)
/*
void RCC_HSE_Configuration(void)
{
RCC_DeInit();//将外设RCC寄存器重设为缺省值
RCC_HSEConfig(RCC_HSE_ON);//设置外部高速晶振(HSE),HSE晶振打开(ON)
if(RCC_WaitForHSEStartUp()==SUCCESS)//等待HSE起振,SUCCESS:HSE 晶振稳定且就绪
{
RCC_HCLKConfig(RCC_SYSCLK_Div1);//设置AHB时钟(HCLK)RCC_SYSCLK_Div1--AHB时钟=系统时钟
RCC_PCLK2Config(RCC_HCLK_Div1);//设置高速AHB时钟(PCLK2)RCC_HCLK_Div1--APB2时钟=HCLK
RCC_PCLK1Config(RCC_HCLK_Div2);//设置低速AHB时钟(PCLK1)RCC_HCLK_Div2--APB1时钟=HCLK/2
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);//选择FLASH预取指缓存的模,预取指缓存使能
FLASH_SetLatency(FLASH_Latency_2);//设置FLASH存储器延时时钟周期数FLASH_LATENCY_2 2延时周期
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_2);//设置PLL时钟源及倍频系数
RCC_PLLCmd(ENABLE);//PLL使能
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==RESET);//检查指定的RCC标志位(PLL准备好标志)设置与否
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);//设置系统时钟SYSCLK
while(RCC_GetSYSCLKSource()!= 0x08);//0x08:PLL作为系统时钟}
}
*/
void AD9851_GPIOC_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_InitStructure);
}
void AD9851_GPIOD_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pi n_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOD,&GPIO_InitStructure);
}
void ad9851_reset_parrel()
{
ad9851_w_clk_l;
ad9851_fq_up_l;
//rest信号
ad9851_rest_l;
ad9851_rest_h;
ad9851_rest_l;
}
void ad9851_wr_parrel(u8 w0,u32 frequence)
{
u8 w;
frequence=frequence*4294967296/180000000;
//写w0数据
w=w0;
GPIO_Write(GPIOD,w); //w0
ad9851_w_clk_h;
ad9851_w_clk_l;
//写w1数据
w=(frequence>>24);
GPIO_Write(GPIOD,w); //w1
ad9851_w_clk_h;
ad9851_w_clk_l;
//写w2数据
w=(frequence>>16);
GPIO_Write(GPIOD,w); //w2
ad9851_w_clk_h;
ad9851_w_clk_l;
//写w3数据
w=(frequence>>8);
GPIO_Write(GPIOD,w); //w3
ad9851_w_clk_h;
ad9851_w_clk_l;
//写w4数据
w=(frequence>>=0);
GPIO_Write(GPIOD,w); //w4
ad9851_w_clk_h;
ad9851_w_clk_l;
//移入始能
ad9851_fq_up_h;
ad9851_fq_up_l;
}
int main()
{
// RCC_HSE_Configuration();
AD9851_GPIOC_Configuration();
AD9851_GPIOD_Configuration();
GPIO_Write(GPIOC,0x0000);
GPIO_Write(GPIOD,0x0000);
//串行写1000Hz程序
ad9851_reset_parrel();
ad9851_wr_parrel(0x01,10000000);
while(1);
}。