利用ADC模块TLC2543实现串行AD转换
#include<reg51.h>
#define uchar unsigned char
sbit CS=P2^0;
sbit CLK=P2^1;
sbit DIN=P2^2;
sbit DOUT=P2^3;
sbit EOC=P2^4;
sbit gwei=P3^3;
uchar tabd[10]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
uchar tab[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar cj,num1,num2;
void Delay()
{
unsigned int i=5;
while(i--);
}
unsigned int AD_Convert(uchar channel)
{
uchar i;
unsigned int ad_value=0;
CLK=0;
CS=1;
EOC=1;
channel<<=4;
CS=0;
Delay();
for(i=0;i<12;i++)
{
if(DOUT)ad_value |=1;
DIN=(bit)(channel & 0x80);
CLK=1;
Delay();
CLK=0;
channel<<=1;
ad_value<<=1;
}
EOC=0;
CS=1;
ad_value>>=1;
return ad_value;
}
void int_t0()
{
TMOD=0x01;
TH0=0xf8;
TL0=0x30;
EA=1;
ET0=1;
TR0=1;
}
void init_t0()interrupt 1