我想温度显示在1~3的数码管上,但是只显示8.59,。。。
我知道时序要求很严格,我看了十几遍的时序图了,延时函数都调准了,就是不行,晕。。。
#include <reg52.h>
#include <intrins.h>
sbit ds = P2^2;
sbit dula = P2^6;
sbit wela = P2^7;
void init (void);
void write_com (unsigned char);
unsigned char read_data (void);
void display (unsigned int);
void delay (unsigned int);
unsigned int c;
int main (void)
{
unsigned int a,b,x;
float t;
while (1)
{
init ();
delay (1);
write_com (0xcc);
write_com (0x44);
for (x = 10;x>0;x--)
{
init ();
delay (1);
write_com (0xcc);
write_com (0xbe);
a = read_data ();
b = read_data ();
c = b;
c<<=8;
c = c | a;
t = c * 0.0625;
c = t * 10;
display (c);
}
}
}
void delay (unsigned int a1)
{
while (a1--);
}
void init (void)
{
ds = 0;
delay (55); //延时550us
ds = 1;
delay (55);
}
void write_com (unsigned char com)
{
int i;
ds = 1;
for (i = 0;i < 8;i++)
{
ds = 0;
_nop_ ();
com>>=1;
ds = com&0x01;
delay (1);
ds = 1;
delay (3);
}
}
unsigned char read_data (void)
{
unsigned char y;
int i;
ds = 1;
for (i = 0;i < 8;i++)
{
ds = 0;
_nop_ ();
ds = 1;
_nop_ ();
y >>= 1;
if (ds)
y |= 0x80;
delay (5);
}
return y;
}
void display (unsigned int c1)
{
unsigned int a,b,c;
unsigned char code choice[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//数码管段选
unsigned char code choice1[] = {0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
a = c1/100;
b = (c1%100)/10;
c = (c1%100)%10;
wela = 1;
P0 = 0x3e;
wela = 0;
dula = 1;
P0 = choice[a];
dula = 0;
delay (500);
wela = 1;
P0 = 0x3d;
wela = 0;
dula = 1;
P0 = choice1[b];
dula = 0;
delay (500);
wela = 1;
P0 = 0x3b;
wela = 0;
dula = 1;
P0 = choice[c];
dula = 0;
delay (500);
}
------解决方案--------------------
时序你应该遵照了时序图
但是delay(1) = 10us么?这个准不准很重要