我程序如下
#include<reg52.h>
#include<intrins.h>
#ifndef __tlc2543__h_
#define __tlc2543_h__
#define uint unsigned int
#define uchar unsigned char
sbit ADout=P1^0;
sbit ADin=P1^1;
sbit ADCS=P1^2;
sbit CLK=P1^3;
sbit EOC=P1^4;
uchar duan[]=
{0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x7c};
uchar D=0,wei[]={0xfe,0xfd,0xfb,0xf7,0xdf,0xef};
float k=0;
float n=0;
uint readAD(uchar port)
{
uchar ch,i,j;
uint ad;
ch=port;
for(j=0;j<3;j++)
{
ad=0;
ch=port;
EOC=1;
CS=1;
CS=0;
CLK=0;
for(i=0;i<12;i++)
{
if(ADout) ad|=0x01;
ADin=(bit)(ch&0x80);
CLK=1;
CLK=0;
ch<<=1;
ad<<=1;
}
}
CS=1; /////////转换和读取数值
while(!EOC);
ad>>=1;
return(ad);
}
#endif
|