子程序:void dac(unsigned char channal,unsigned int Dignum)
{
DDRE=0xff;
unsigned int Dig;
unsigned int flash;
DASCLK_SET;
DACS_CLR; //片选
if(Dignum>0x0fff)
{Dignum=0x0fff;}
if(channal==1)
{ Dig=Dignum|0xc000; }
else
{ Dig=Dignum|0x5000; }
for(unsigned char i=0;i<16;i++) //дÈë16ΪBitµÄ¿ØÖÆλºÍÊý¾Ý
{
flash=Dig&0x8000;
if(flash==0)
{ DADIN_CLR; }
else
{ DADIN_SET; }
Dig=Dig<<1;
DASCLK_CLR;
;
;
DASCLK_SET;
;
;
}
DASCLK_SET;
daDelay(60);
DACS_SET; //ƬѡÎÞЧ
}
主程序中如果
dac(2,0x0fff);
dac(1,0x07ff);
则输出B通道不对,
但如果
dac(2,0x0fff);
dac(2,0x0fff);
dac(1,0x07ff);
dac(1,0x07ff);
则可以输出正确的电压
不知那出错了。 |