搞定了。。还是得靠自己啊。。编译通过,还没有经过验证,等出差回去就测试
/************************************************************
串行驱动 ad9850
frud -- b0
rest -- b1
wclk -- b2
数据接口 d7 -- a7(注意:串行方式时d0,d1接高电平,d2接地)
adout 定义输出频率
****************************************************************/
#include <iom16v.h>
#include <macros.h>
#include <delay.h>
#include <avr_bit.h>
#define uint unsigned int
#define uchar unsigned char
#define set_1(a,b) a|=(1<<b)
#define cle_0(a,b) a&=~(1<<b)
#define frud_1 portb_0=1
#define frud_0 portb_0=0
#define rest_1 portb_1=1
#define rest_0 portb_1=0
#define wclk_1 portb_2=1
#define wclk_0 portb_2=0
#define adout 5000000 // 定义 输出 频率 adout
#define io9850 porta
#define io_1 set_1(io9850,7)
#define io_0 cle_0(io9850,7)
void initio(void)
{
ddra = 0xff;
ddrb = 0xff;
}
void init9850(void)
{
wclk_0;
frud_0;
rest_1;
rest_0;
}
void update(void)
{
frud_1;
frud_0;
}
void sentcom(void)
{
sendword(0);
sendword(0);
sendword(1);
sendword(0);
sendword(0);
sendword(0);
sendword(0);
}
void sendword(uchar dat)
{
if(dat)
io_1;
else
io_0;
wclk_1;
wclk_0;
}
void startad(void)
{ long unsigned int dat;
unsigned char i = 0;
update();
dat =(long int) adout * 42.949672;
dat=dat>>1;
for(;i<32;i++)
{
sendword((uchar) (dat&1));
dat=dat>>1;
}
sentcom();
update();
}
int main(void)
{ initio();
init9850();
startad();
while(1)
{
nop();
}
}