white_mcu@163.c 该用户已被删除
|
code unsigned int ad_lst[16]={32768,16384,8192,4096,2048,1024,512,256,128,64,32,16,8,4,2,1};
//=====================================
//===========A/D转换函数================
//=====================================
unsigned int adzh(unsigned char prot)
{
unsigned char i;
unsigned char ad_reg=prot; //通道号
unsigned int ad16=0;
CS=1; //TLC2543片选
CS=0; //片选使能
//设置A/D 16位 通道0,单极性信号转换,高位在先
for (i=0;i<8;i++)
{
ACC=ad_reg;
CLOCK=0;
CLOCK=1; //CP上升沿
if (D_OUT)
{
ad16=ad16+ad_lst;
D_IN=ACC^7; //写入
}
else
{
ad16=ad16+0;
D_IN=ACC^7; //写入
}
ad_reg=(ad_reg<<1);
}
for (i=8;i<16;i++)
{
CLOCK=0;
CLOCK=1;
if (D_OUT)
{
ad16=ad16+ad_lst;
}
ad16=ad16+0;
D_IN=0;
}
CS=1; //片选禁止!
return (ad16>>4);
}
上面的程序我已经调试通过的,供网有参考!
误见笑! |
|