模数转换,数码管前两位亮度没最后一位高,相差比较多,怎么会这样呢?
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit wr=P3^6;
sbit rd=P3^7;
void init();
void start();
uchar temp;bai,shi,ge;
//uint temp;
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void display(uchar bai,uchar shi,uchar ge);
void delay(uint z) //延时子程序
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void main()
{
init();
while(1)
{
start();
delay(10);
rd=0;
temp=P1;
bai=temp/100; //分离百位
shi=temp%100/10; //分离十位
ge=temp%10; //分离个位
display(bai,shi,ge);
delay(10);
rd=1;
delay(10);
}
}
void init()
{
P0=0x7f;
}
void start()
{
wr=1;
wr=0;
wr=1;
}
void display(uchar bai,uchar shi,uchar ge) //三位数的显示子程序
{
dula=1;
P0=table[bai];
dula=0;
wela=1;
P0=0x7e;
wela=0;
delay(5);
dula=1;
P0=table[shi];
dula=0;
wela=1;
P0=0x7d;
wela=0;
delay(5);
dula=1;
P0=table[ge];
dula=0;
wela=1;
P0=0x7b;
wela=0;
delay(5);
} |