为什么电路不能仿真(ADC0832),请指导下.
时间:10-02
整理:3721RD
点击:
#include "reg51.h"
sbit CS=P3^4;
sbit Clk=P1^0;
sbit DIO=P1^1;
unsigned char adval;
unsigned char code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char A_D(bit CH)
{
unsigned char i;
CS=0;
Clk=0;
Clk=1;
DIO=1;
if(CH==0)
{
Clk=0;
Clk=1;
DIO=1;
Clk=0;
Clk=1;
DIO=0;
}
else
{
Clk=0;
Clk=1;
DIO=1;
Clk=0;
Clk=1;
DIO=1;
}
Clk=1;
Clk=0;
for(i=0;i<8;i++)
{
Clk=1;
Clk=0;
if(DIO)
adval=(adval>>1)|0x80;
else
adval=(adval>>1)|0x00;
}
CS=1;
return(adval);
}
void delay1(void)
{
int k;
for(k=0;k<400;k++);
}
void display(int k)
{
P2=0xfe;
P0=tab[k/1000];
delay1();
P2=0xfd;
P0=tab[k%1000/100];
delay1();
P2=0xfb;
P0=tab[k%100/10];
delay1();
P2=0xf7;
P0=tab[k%10];
delay1();
P2=0xff;
}
void main(void)
{
P0=0xff;
P2=0xff;
while(1)
{
A_D(0x01);
display(adval);
}
}
sbit CS=P3^4;
sbit Clk=P1^0;
sbit DIO=P1^1;
unsigned char adval;
unsigned char code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char A_D(bit CH)
{
unsigned char i;
CS=0;
Clk=0;
Clk=1;
DIO=1;
if(CH==0)
{
Clk=0;
Clk=1;
DIO=1;
Clk=0;
Clk=1;
DIO=0;
}
else
{
Clk=0;
Clk=1;
DIO=1;
Clk=0;
Clk=1;
DIO=1;
}
Clk=1;
Clk=0;
for(i=0;i<8;i++)
{
Clk=1;
Clk=0;
if(DIO)
adval=(adval>>1)|0x80;
else
adval=(adval>>1)|0x00;
}
CS=1;
return(adval);
}
void delay1(void)
{
int k;
for(k=0;k<400;k++);
}
void display(int k)
{
P2=0xfe;
P0=tab[k/1000];
delay1();
P2=0xfd;
P0=tab[k%1000/100];
delay1();
P2=0xfb;
P0=tab[k%100/10];
delay1();
P2=0xf7;
P0=tab[k%10];
delay1();
P2=0xff;
}
void main(void)
{
P0=0xff;
P2=0xff;
while(1)
{
A_D(0x01);
display(adval);
}
}
附上照片。
请大家帮忙顶下,谢谢。