当前位置:首页 > 单片机 > 单片机
[导读]/**************************************TLC2543驱动程序*************************************/#include #include /**************************************2543控制引脚宏定义*********************************

/**************************************
TLC2543驱动程序
*************************************/

#include
#include

/**************************************
2543控制引脚宏定义
*************************************/
#define CLOCK p17 /*2543时钟*/
#define D_IN p16 /*2543输入*/
#define D_OUT p14 /*2543输出*/
#define _CS p15 /*2543片选*/

#define uint unsigned int
#define uchar unsigned char

/**************************************
名称:delay
功能:延时模块
输入参数:n要延时的周期数
输出参数:无
*************************************/
void delay(uchar n)
{
uchar i;
for(i=0;i{
_nop_();
}
}

/**************************************
名称:read2543
功能:TLC2543驱动模块
输入参数:port通道号
输出参数:ad转换值
*************************************/
uint read2543(uchar port)
{
uint ad=0,i;
CLOCK=0;
_CS=0;
port<<=4;
for(i=0;i<12;i++)
{
if(D_OUT) ad|=0x01;
D_IN=(bit)(port&0x80);
CLOCK=1;
delay(3);
CLOCK=0;
delay(3);
port<<=1;
ad<<=1;
}
_CS=1;
ad>>=1;
return(ad);
}

/**************************************
名称:main
功能:主函数
输入参数:无
输出参数:无
*************************************/
void main()
{uint ad;
while(1)
{
ad=read2543(0);
}
}

本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除( 邮箱:macysun@21ic.com )。
换一批
延伸阅读
关闭