帮写一个基于C51单片机AD9850的串行扫描C程序,控制IO,P0.3,P0.2,P2.4

2024-12-19 15:22:43
推荐回答(1个)
回答1:

#include"reg52.h"
#define uchar unsigned char
sbit clk = P0^2;
sbit load = P0^3;
sbit dat = P0^4;

void init_dds(void)
{
clk=0;
load=0;
clk=1;
clk=0;
load=1;
load=0;
}

void write_dds(unsigned long dds)
{
uchar i;
load=0;
clk=0;
for(i=0;i<40;i++)
{
clk=0;
if(dds & 0x00000001)
dat=1;
else dat=0;
clk=1;
dds=dds>>1;
}
load=1;
clk=0;
load=0;
}

void write_freq(unsigned long freq)
{
unsigned long dds;
dds=34.35943*freq;
write_dds(dds);
}

void main()
{
init_dds();
write_freq(500000);
write_freq(500000);
while(1)
{
}

}