cpubbs 发表于 2004-10-27 23:23:24

TI TLC1543 10位AD驱动程序 [转载]

/*------------------------------------------------------------------------------
--
调用方式:uint read1543(uchar port)
函数说明:read1543()返回10位AD芯片TLC1543的port通道采样值。
--------------------------------------------------------------------------------
-*/
#define CLOCK P1_3
#define D_IN P1_4
#define D_OUT P1_5
#define _CS P1_7

uint read1543(uchar port) //从TLC1543读取采样值,形参port是采样的通道号
{
uint data ad;uint data i;
uchar data al=0,ah=0;

CLOCK=0;
_CS=0;
port<<=4;
for (i=0;i<4;i++) //把通道号打入1543
{
D_IN=(bit)(port&0x80);CLOCK=1;CLOCK=0;
port<<=1;
}

for (i=0;i<6;i++) //填充6个CLOCK
{
CLOCK=1;CLOCK=0;
}

_CS=1;
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
_CS=0; //等待AD转换

_nop_();_nop_();_nop_();

for (i=0;i<2;i++) //取D9,D8
{
D_OUT=1;
CLOCK=1;
ah<<=1;
if (D_OUT) ah|=0x01;
CLOCK=0;
}

for (i=0;i<8;i++) //取D7--D0
{
D_OUT=1;
CLOCK=1;
al<<=1;
if (D_OUT) al|=0x01;
CLOCK=0;
}

_CS=1;
ad=(uint)ah;ad<<=8;ad|=(uint)al; //得到AD值
return (ad);
}

bianbowei 发表于 2006-8-30 21:32:55

<p>不知道有没有汇编的.</p>
页: [1]
查看完整版本: TI TLC1543 10位AD驱动程序 [转载]