#include<reg51.h>
sbit clk=P3^0;
sbit din=P3^1;
sbit dout=P3^2;
sbit cs=P3^3;
#define outport P2
void delay(unsigned int);
void adc_init();
void adc_read();
void main()
{
clk=0;
din=0;
dout=1;
outport=0x00;
while(1)
{
adc_init();
adc_read();
}
}
void delay(unsigned int count)
{
unsigned int i,j;
for(i=0;i<=count;i++)
for(j=0;j<=1300;j++);
}
void adc_init()
{
clk=0;
cs=1;
din=0;
delay(1);
clk=0;
cs=0;
din=1;
delay(1);
clk=1;
cs=0;
din=1;
delay(1);
clk=0;
cs=0;
din=1;
delay(1);
clk=1;
cs=0;
din=1;
delay(1);
clk=0;
cs=0;
din=0;
delay(1);
clk=1;
cs=0;
din=0;
delay(1);
clk=0;
cs=0;
din=0;
delay(1);
}
void adc_read()
{
int m, byte_in=0x01;
clk=1;
delay(1);
clk=0;
delay(1);
for(m=0;m<=7;m++)
{
clk=1;
cs=0;
delay(1);
clk=0;
delay(1);
byte_in=byte_in&dout;
byte_in=byte_in<<1;
delay(1);
}
outport=byte_in;
cs=1;
}