这是我学习写的测距代码,在使用过程中发现LED的灯亮度不一。请问如何解决?
[code]#include <reg52.h>
sbit echo = P1 ^ 0;
sbit trig = P1 ^ 1;
sbit wei1 = P2 ^ 4;
sbit wei2 = P2 ^ 5;
sbit wei3 = P2 ^ 6;
sbit wei4 = P2 ^ 7;
#define dula P0
#define uchar unsigned char
#define uint unsigned int
long int distance = 0;
uchar count;
unsigned char code table[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d,
0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71
};
unsigned char code table1[] = {0xbf, 0x86, 0xdb, 0xcf, 0xe6, 0xed, 0xfd,
0x87, 0xff, 0xef, 0x71
};
void delay(unsigned int xms)
{
unsigned int i, j;
for(i = xms; i > 0; i--)
for(j = 112; j > 0; j--);
}
void display(long int num)
{
uchar qian, bai, shi, ge;
if((num > 5000) || (num == 0)) {
qian = 15; //距离值上为百位
bai = 15;
shi = 10;
ge = 15;
} else {
qian = num / 1000; //距离值上为百位
bai = (num / 100) % 10; //距离值上为十位
shi = (num / 10) % 10; //距离值上为个位,并且显示时需要加小数点
ge = num % 10; //距离值上为小数位,并已经四舍五入
}
wei1 = 1; |