/******************************
AD9835程序
******************************/
#include
#define FMCLK 50
/*AD9835*/
sbit D_CS = P1^5;
sbit D_SDA = P1^7;
sbit D_SCLK = P1^6;
sbit LED = P1^1;
void SendData(unsigned int d)
{
unsigned char i;
D_CS = 0;
for(i=0;i<16;i++ )
{
d<<=1;
D_SDA=CY;
D_SCLK=1;
D_SCLK=0;
}
D_CS = 1;
}
void main(void)
{
unsigned int i;
D_CS = 1;
for(i=0;i<1000;i ){/* //"开机延时 */ }
/****************"初始化 AD9835*****************************/
//Control register write D15 D14 11
// D13 D12 D11
// sleep="1" reset="1" clr="1"
// 1111 1xxx xxxx xxxx
SendData(0xf800);
//Setting SYNC and SELSRC D15 D14 10
//D13 SYNC==1
//D12 SELSRC="0" 0/1 using the pins/bits FSELECT,PSEL0 and PSEL1
// 1010 xxxx xxxx xxxx
SendData(0xa000);
//write initial data
//输出14.8 f1=14.8-0.2=14.6 f0=14.8 0.2=15 fmclk="50"
//14.6 freg1 = fout0/fmclk*2^32 = 1254130450.432 = 1254130450
// = 0x 4A C0 83 12 实际14.599999995
//15 freg0 = fout1/fmclk*2^32 = 1288490188.8 = 1288490188
// = 0x 4c cc cc cc 实际14.999999991
//f1=14.8-0.05=14.75 f0=14.85 fmclk="50MHz"
//freg1=14.75/50*2^32=0x4b851eb8
//freg0=14.85/50*2^32=0x4c083126
//"高8位是固定的,具体看手册
//0011 0000 freg0 L LSBS
//0010 0001 freg0 H LSBS
//0011 0010 freg0 L MSBS
//0010 0011 freg0 H MSBS
//50M 14.6M 1254130450=0x 4A C0 83 12
SendData(0x3012);
SendData(0x2183);
SendData(0x32c0);
SendData(0x234a);
//"高8位是固定的,具体看手册
//0011 0100 freg1 L LSBS cc
//0010 0101 freg1 H LSBS cc
//0011 0110 freg1 L MSBS cc
//0010 0111 freg1 H MSBS 4c
//50M 15M 1288490188=0x4c cc cc cc
SendData(0x34cc);
SendData(0x25cc);
SendData(0x36cc);
SendData(0x274c);
//phase
//0001 1000 phase0 LSBS
//0000 1001 phase0 MSBS
//0001 1010 phase1 LSBS
//0000 1011 phase1 MSBS
//0001 1100 phase2 LSBS
//0000 1101 phase2 MSBS
//0001 1110 phase3 LSBS
//0000 1111 phase3 MSBS
SendData(0x1800);
SendData(0x0900);
SendData(0x1a00);
SendData(0x0b00);
SendData(0x1c00);
SendData(0x0d00);
SendData(0x1e00);
SendData(0x0f00);
//Control register write D15 D14 11
// D13 D12 D11
// sleep="0" reset="0" clr="0"
// 1100 0xxx xxxx xxxx
SendData(0xc000);
while(1);
}
用户265026 2008-6-16 10:23
用户154032 2008-6-16 10:22
用户1076896 2008-3-26 23:17
用户1076896 2008-3-26 23:14