/*
;程 序 最 后 修 改 时 间 0-4-3 23:48
;软 件 标 题:TLC1543 AD采样子程序.c
;软 件 说 明:从TLC1543读取采样值,形参port是采样的通道号
;_________________________________________
;原作者: 龙啸九天 deviser@126.com
;程序修改人:
;版本号: 2.0
;_________________________________________
*/
//==========AD采样模块============//
//TLC1543 A/D用转换用
#define CLOCK P1_3
#define D_IN P1_4
#define D_OUT P1_5
#define _CS P1_6
//========================新版本=======================
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_();_CS=0; //等待AD转换
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|=al; //得到AD值
return (ad);
}