我在做AD实验时,用C语言的程序里,把P1置1了,发现还是不能当做输入,具体该怎么做呢?下面是我写的程序:
硬件:AD输出接到P1,同时也接到8个LED。led可以显示不同的灯亮。我想把这些值从P1输入,然后从P0输出,从P0口输出后面的也解决了。只是P1=1后,还是没有 能 把AD的值从P1输入(这就是问题)。请问程序里有什么问题?
该怎么修改?不胜感激!
#include<reg52.h>
sbit wr=P3^6;
sbit rd=P3^7;
sbit dula=P2^6;
sbit wela=P2^7;
#define uchar unsigned char
#define uint unsigned int
uchar disnum,count,bai,shi,ge;
uint m,n;
display(uchar,uchar,uchar);
delay(uchar);
uchar code tabledu[]=
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void init();
void start();
void main()
{
P1=0xFF; //P1 gao?
delay(500);
while(1)
{
init();
start();
delay(2);
rd=0;
delay(2);
rd=1;
delay(2);
//P0=P1;
disnum=P1;//?????P1??
bai=disnum/100;
shi=disnum%100/10;
ge=disnum%100%10;
display(bai,shi,ge);
}
}
void init()//
{
P0=0x7f;
dula=0;//
wela=0;
}
void start()
{
wr=1;
wr=0;
wr=1;
}
delay(uchar x)
{
for(m=10;m>0;m--)
for(n=x;n>0;n--);
}
display(uchar bai,uchar shi,uchar ge)
{
P0=0x7f;//0111 1111,make ADC's CS low.
wela=1;
wela=0;
P0=tabledu[bai];
dula=1;
dula=0;
P0=0x7e;//0111 1111,make ADC's CS low.
wela=1;
wela=0;
delay(1);
P0=0x7f;
wela=1;
wela=0;//
P0=tabledu[shi];//
dula=1;
dula=0;
P0=0x7d;
wela=1;
wela=0;
delay(1);//lesson4_5
P0=0x7f;
wela=1;
wela=0;//
P0=tabledu[ge];//
dula=1;
dula=0;
P0=0x7b;
wela=1;
wela=0;
//delay(1);
} |