c51單片機驅(qū)動AD9954的程序及調(diào)試
下面是部分程序,與有興趣的朋友們一起分享(才起步,拙劣之處還請多多包涵):
公共程序段:
#include reg51.h>#include absacc.h>#include intrins.h>#define uchar unsigned charsbit ioupdate = P1^0;sbit sdio = P1^1;sbit clk = P1^2;sbit adcs = P1^3;sbit adreset = P1^4;sbit tlvcs = P1^5;sbit ps0 = P1^6;void send(uchar dat){uchar i;for(i=0;i 8;i++){clk = 0;dat = _crol_(dat,1);sdio = dat0x01;clk = 1;}}程序1:(Single-Tone Mode)void main(){P1 = 0xff;adreset = 0;adcs = 0;send(0x00); //CFR1send(0x02); //bit1 OSK Enable,bit0 Auto OSK Enable;send(0x00);send(0x00);send(0x42); //bit6 comp PD,bit1 SYNC_clk Disable;SYNC_clk = DDSclk/4;ioupdate = 0;ioupdate = 1;send(0x01); //CFR2send(0x00); //not used;send(0x08); //bit3 High Speed SYNC Enable;send(0xa4); //bit7-bit3 REF clk Multiplier factor;bit2 VCO Range //(0:100-250;1:250-400);bit1-bit0 Charge Pump;send(0x02); //ASF,when OSK Enabled(CFR1 bit25);send(0x3f);send(0xff);send(0x04); //FTW0 0x 00 a3 d7 0a=1MHz (0x ff ff ff ff ==> 400MHz)send(0x00);send(0xa3);send(0xd7);send(0x0a);send(0x05); //POW0,Phase Initialsend(0x00);send(0x00);ioupdate = 0;ioupdate = 1;adcs = 1;adcs = 0; //POW0.Phase shift 180 (0x 3f ff ==> 360)send(0x05);send(0x20);send(0x00);adcs = 1;ioupdate = 0;ioupdate = 1;}程序2:(Linear-Sweeping Mode)void main(){P1 = 0xff;adreset = 0;adcs = 0;send(0x00); //CFR1send(0x00);send(0x20); //bit5 Linear Sweeping Enablesend(0x00);send(0x46); //bit2 Linear Sweeping No-Dwellioupdate = 0;ioupdate = 1;send(0x07); //NLSCWsend(0x10);send(0x00);send(0x00);send(0x00);send(0x10);send(0x08); //PLSCWsend(0x10);send(0x00);send(0x00);send(0x00);send(0x10);send(0x04); //FTW0 0x 00 a3 d7 0a ==1MHz (0x ff ff ff ff ==> 400MHz)send(0x00);send(0xa3);send(0xd7);send(0x0a);send(0x06); //FTW1 0x 01 68 72 b0 ==2.2MHz (0x ff ff ff ff ==> 400MHz))send(0x01);send(0x68);send(0x72);send(0xb0);adcs = 1;ioupdate = 0;ioupdate = 1;ps0 = ~ps0; //Toggle ps0 to sweep;ps0 = ~ps0;}程序3:(AD9954_ADIcode)程序4:(RAM Mode) void main(){P1 = 0xff;ps0 = 0;adreset = 0;adcs = 0;send(0x01); //CFR2send(0x00); //not used;send(0x00); //bit3 High Speed SYNC Enable;send(0xa4); //bit7-bit3 REF clk Multiplier factor; bit1-bit0 Charge Pump;send(0x04); //FTW0;send(0x12);send(0xf6);send(0x84);send(0xbe);ioupdate = 0;ioupdate = 1;send(0x00); //CFR1send(0x80); // bit7 RAM Enable;bit5-3 Internal Profile Controlsend(0x00);send(0x02); //bit1 SDIO Only;send(0x00); //bit6 comp PD,bit1 SYNC_clk Disable;SYNC_clk = DDSclk/4;send(0x02); //ASF,when OSK Enabled(CFR1 bit25);send(0x3f);send(0xff);ioupdate = 0;ioupdate = 1;send(0x07); //RSCW0;ps0 = 0; ps1 = 0;send(0xff); //RAM Segment Address Ramp Rate 7:0>send(0xff); //RAM Segment Address Ramp Rate 15:8>send(0x07);send(0x00); //Segment0 Address:0x00000-0x00007send(0x00); //RSCW0send(0x08); //RSCW1;ps0 = 1; ps1 = 0;send(0xff); //RAM Segment Address Ramp Rate 7:0>send(0xff); //RAM Segment Address Ramp Rate 15:8>send(0x00);send(0x01); //Segment1 Address:0x00000-0x00001send(0x04);adcs = 1;ioupdate = 0;ioupdate = 1;adcs = 0;send(0x0b); //RAMsend(0x00); //stall freq into RAM from the final address to beginning address;send(0xa3);send(0xd7);send(0x0a); //RAM0 1MHzsend(0x00);send(0xf5);send(0xc2);send(0x8f); //RAM1 1.5MHzsend(0x01);send(0x47);send(0xae);send(0x14); //RAM2 2MHzsend(0x01);send(0x99);send(0x99);send(0x99); //RAM3 2.5MHzsend(0x01);send(0xeb);send(0x85);send(0x1e); //RAM4 3MHzsend(0x02);send(0x3d);send(0x70);send(0xa3); //RAM5 3.5MHzsend(0x02);send(0x8f);send(0x5c);send(0x28); //RAM6 4MHzsend(0x02);send(0xe1);send(0x47);send(0xae); //RAM7 4.5MHzps0 = 1;send(0x0b); //RAM Instruction Againsend(0x03);send(0x33);send(0x33);send(0x33); //RAM0 5MHzioupdate = 0;ioupdate = 1;send(0x07); //RSCW0;ps0 = 0; ps1 = 0;send(0x00); //RAM Segment Address Ramp Rate 7:0>send(0x04); //RAM Segment Address Ramp Rate 15:8>send(0x07);send(0x00);send(0x60); //RAM Mode of Operation: Continuous Bidirectional Rampadcs = 1; //RSCW0ioupdate = 0;ioupdate = 1;}
評論