《2022年AD驱动程序 .pdf》由会员分享,可在线阅读,更多相关《2022年AD驱动程序 .pdf(9页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、#include #include sys.h #include delay.h #define AD9854_DATA GPIOC-ODR #define AD9854_ADDR GPIOC-ODR #define ad9854_reset PBout(12) #define ad9854_rd PBout(13) #define ad9854_wr PBout(14) #define ad9854_updata PBout(15) unsigned char ControlRegister=0 x14,0 x4f,0 x00,0 x60; /AD9852 控制寄存器初始值, Mode 0
2、unsigned char FTW=0 x00,0 x00,0 x37,0 xec; /Frequency Tuning Word 1 倍频 300MHz 后输出频率对应的 FTW 值unsigned char PAR=0 x00,0 x00; /Phase Adjust Register 1 unsigned char OSK=0 x0a,0 xff; /Output shaped keying multiplier, 650mv 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1
3、 页,共 9 页 - - - - - - - - - voidsingle_wave(unsigned long intfre); void Init_AD9854(void); void AD9854_Set_Mode0(void); void AD9852_Send(unsigned char addr,unsigned char data); voidchange_frequency(unsigned long intfre_temp); voidInit_Port(void); int main( void ) Stm32_Clock_Init(9); / 9倍频delay_init(
4、72); / 72M 晶振时延时delay_ms(200); Init_Port(); Init_AD9854(); single_wave(1000000); while(1); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 9 页 - - - - - - - - - voidInit_Port(void) RCC-APB2ENR |= 1CRH &= 0 x0000ffff ; GPIOB-CRH |= 0 x33330000 ; GPIOB-ODR |= 0 xf
5、000 ; RCC-APB2ENR |= 1CRL &= 0 x00000000 ; GPIOC-CRL |= 0 x33333333 ; GPIOC-CRH &= 0 x00000000 ; GPIOC-CRH |= 0 x33333333 ; GPIOC-ODR |= 0 xffff ; void AD9852_Send(unsigned char addr,unsigned char data) /按照并行输入时序 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 9
6、 页 - - - - - - - - - ad9854_wr = 1; / AD9854_WR_SET; AD9854_ADDR &= 0 x00ff|addr8; AD9854_ADDR |= 0 xff00&addr0;i-) AD9852_Send(addr,ControlRegister4-i); addr+; void AD9854_Set_Mode0(void) /Mode 0 设置名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 9 页 - - - - - -
7、 - - - unsigned char addr; unsigned char counter; for(addr=0 x00,counter=2;counter0;counter-)/ 设置 Phase Adjust Register 1 AD9852_Send(addr,PAR2-counter); addr+; for(addr=0 x04,counter=4;counter0;counter-)/ 设置 Frequency Tuning Word 1 AD9852_Send(addr,FTW4-counter); addr+; for(addr=0 x21,counter=2;cou
8、nter0;counter-)/ 设置 Output shaped keying multiplier AD9852_Send(addr,OSK2-counter); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 9 页 - - - - - - - - - addr+; voidsingle_wave(unsigned long intfre) unsigned char addr,i; unsigned long intff; unsigned char *p; ff
9、=(unsigned long int)(4294967296*fre/300000000); p=(unsigned char*)&ff; for(addr=0 x04,i=0;i4;i+) / 设置 Frequency Tuning Word 1 AD9852_Send(addr,*(p+3-i); addr+; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 9 页 - - - - - - - - - for(addr=0 x00,i=0;i0;i-) / 设置 O
10、utput shaped keying multiplier AD9852_Send(addr,OSK2-i); addr+; voidchange_frequency(unsigned long intfre_temp) unsigned char addr,counter; unsigned char *p; p=(unsigned char*)&fre_temp; for(addr=0 x04,counter=0;counter4;counter+)名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 8 页,共 9 页 - - - - - - - - - / 设置 Frequency Tuning Word 1 AD9852_Send(addr,*(p+3-counter); addr+; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 9 页,共 9 页 - - - - - - - - -