我写了个TLC2543的程序,不过采样值跳跃的特别厉害。
硬件EOC腿没接。
程序如下:
#include<reg51.h>
#include<intrins.h>
#include<absacc.h>
#define uint unsigned int
#define uchar unsigned char
sbit AD_EOC= P3^1;
sbit AD_CLOCK= P3^3;
sbit AD_IN= P3^4;
sbit AD_OUT= P3^5;
sbit AD_CS= P3^2;
union ccb
{uint y;
uchar x[2];
}a;
static const uchar ad_chunnel_select[]={0x00,
0x10,0x20,0x30,0x40,
0x50,0x60,0x70,0x80,
0x90,0xa0};
uint ad2543(uchar chunnel_select)
{uint din;
uchar dout,i;
din=0;
dout=ad_chunnel_select[chunnel_select];
//while(AD_EOC==0);
AD_CLOCK=0;
AD_CS=0;
for(i=0;i<12;i++)
{if(dout&0x80)AD_IN=1;
else AD_IN=0;
AD_CLOCK=1;
dout<<=1;
din<<=1;
if(AD_OUT==1) din|=0x0001;
AD_CLOCK=0;
}
AD_CS=1;
return(din);
}
void main(void)
{ while(1)
{ a.y=ad2543(0);
a.y>>=4;
P1=a.x[1];
}
}
请高手指点,谢谢! |