📄 tlc1543.c
字号:
//TI TLC1543 10位AD驱动程序 [龙啸九天] [953次] 01-3-24 下午 07:50:17
/*————————————————————
〖说明〗TI TLC1543 10位AD驱动程序,51晶振是11.0592MHz的。
〖文件〗TLC1543.c ﹫2001/03/23
〖作者〗龙啸九天 c51@yeah.net <a href=http://mcs51.yeah.net target=_blank>http://mcs51.yeah.net</a>
〖修改〗修改建议请到论坛公布 <a href=http://c51bbs.yeah.net target=_blank>http://c51bbs.yeah.net</a>
〖版本〗V2.00A Build 0323
—————————————————————*/
/*------------------------------------------------------------------------------
--
调用方式: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);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -