2024年5月15日发(作者:张廖念文)
//首先是.h文件
#ifndef __DAC8552_H
#define __DAC8552_H
#include"config.h"
#define SYNC_0 P1OUT&=~BIT0
#define SYNC_1 P1OUT|=BIT0
#define SCLK_0 P1OUT&=~BIT1
#define SCLK_1 P1OUT|=BIT1
#define DIN_0 P1OUT&=~BIT2
#define DIN_1 P1OUT|=BIT2
void port_init();
void write_8552(ulong data);
void DAC_A(ulong data);//启用A通道
void DAC_B(ulong data);//启用B通道
void DAC_AB(ulong data_A,ulong data_B);//启用A、B通道,且同时触发
#endif
//下面为.c文件
#include"DAC8552.h"
void port_init()
{
P1SEL=0X00;
P1DIR=0XFF;
}
void write_8552(ulong data)
{
uchar i;
SYNC_1;
delay_us(1);
SCLK_0;
SYNC_0;
for(i=0;i<24;i++)
{
if(0x800000&data) DIN_1;
else DIN_0;
SCLK_1;
delay_us(1);
SCLK_0;
data=data<<1;
}
delay_us(1);
SYNC_1;
}
void DAC_A(ulong data)
{
ulong ctr=0x10;
data=data|(ctr<<16);
write_8552(data);
}
void DAC_B(ulong data)
{
ulong ctr=0x24;
data=data|(ctr<<16);
write_8552(data);
}
void DAC_AB(ulong data_A,ulong data_B)
{
ulong ctr=0x00;
data_A=data_A|(ctr<<16);
write_8552(data_A);
ctr=0x34;
data_B=data_B|(ctr<<16);
write_8552(data_B);
}
2024年5月15日发(作者:张廖念文)
//首先是.h文件
#ifndef __DAC8552_H
#define __DAC8552_H
#include"config.h"
#define SYNC_0 P1OUT&=~BIT0
#define SYNC_1 P1OUT|=BIT0
#define SCLK_0 P1OUT&=~BIT1
#define SCLK_1 P1OUT|=BIT1
#define DIN_0 P1OUT&=~BIT2
#define DIN_1 P1OUT|=BIT2
void port_init();
void write_8552(ulong data);
void DAC_A(ulong data);//启用A通道
void DAC_B(ulong data);//启用B通道
void DAC_AB(ulong data_A,ulong data_B);//启用A、B通道,且同时触发
#endif
//下面为.c文件
#include"DAC8552.h"
void port_init()
{
P1SEL=0X00;
P1DIR=0XFF;
}
void write_8552(ulong data)
{
uchar i;
SYNC_1;
delay_us(1);
SCLK_0;
SYNC_0;
for(i=0;i<24;i++)
{
if(0x800000&data) DIN_1;
else DIN_0;
SCLK_1;
delay_us(1);
SCLK_0;
data=data<<1;
}
delay_us(1);
SYNC_1;
}
void DAC_A(ulong data)
{
ulong ctr=0x10;
data=data|(ctr<<16);
write_8552(data);
}
void DAC_B(ulong data)
{
ulong ctr=0x24;
data=data|(ctr<<16);
write_8552(data);
}
void DAC_AB(ulong data_A,ulong data_B)
{
ulong ctr=0x00;
data_A=data_A|(ctr<<16);
write_8552(data_A);
ctr=0x34;
data_B=data_B|(ctr<<16);
write_8552(data_B);
}