请高人指点 程序主要是用数码管显示P0口的数, P0口的数AD转换来的,
旋转变阻器,P0口的8个灯会变化,所以想把P0口的值给数码管显示。单只显示一个值107 切前面两个10会闪,后面的7不会闪,旋转变阻器没变化。原以为是二进制数转十进制数有问题, 有找了个转十进制的程序,可是没用,不知错哪里?谢谢
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit wela=P2^7;
sbit dula=P2^6;
sbit cada=P3^2;
sbit wr=P3^6;
sbit rd=P3^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar num,bai,shi,ge,b,j,aa;
int a;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void init();
void start();
void display(uchar,uchar,uchar);
void main()
{
int a=0;
uchar aa=0,j=1;
num=0;
init();
while(1)
{
start();
delay(20);
rd=0;
delay(10);
rd=1;
delay(50);
a=P0; //P0赋值转十进制数
while(a)
{
num+=(a%10)*j;
a/=10;
j*=2;
}
// num=125;
bai=num/100;
shi=num%100/10;
ge=num%10;
display(bai,shi,ge);
}
}
void init()
{
P0=0;
}
void start()
{
wr=1;
wr=0;
wr=1;
}
void display(uchar bai,uchar shi,uchar ge)
{
P0=0xff;
dula=1;
P0=table[bai];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(5);
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(5);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(5);
} |