本帖最后由 胡豆豆的春天 于 2017-4-1 12:38 编辑
这是我的代码,可能会有很多错误,希望大神可以耐心的帮我看一下!!
#include <reg52.h>
#include <stdio.h>
#define uchar unsigned char
#define uint unsigned int
sbit wd=P2^2;
sbit du=P2^6;
sbit we=P2^7;
sbit fm=P2^3;
float wendu;
uint warn_l1=270;
uint warn_l2=250;
uint warn_h1=300;
uint warn_h2=320;
sbit led0=P1^0;
sbit led1=P1^1;
sbit led2=P1^2;
sbit led3=P1^3;
char code table []={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,
0x3f+0x80,0x06+0x80,0x5b+0x80,0x4f+0x80,0x66+0x80,0x6d+0x80,0x7d+0x80,0x07+0x80,0x7f+0x80,0x6f+0x80};
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void fuwei(void)
{
uint i;
wd=0;
i=103;
while(i>0)i--;
wd=1;
i=4;
while(i>0)i--;
}
bit yigezijie()
{
uint i;
bit dat;
wd=0;
i++;i++;
wd=1;
i++;
i=8;
while(i--);
return (dat);
}
uchar yigezifu()
{
uint a,dat;
dat=0;
for(a=0;a<8;a++)
{
a=yigezijie();
dat=(a<<7)|(dat>>1);
}
}
void duyigezijie(uchar dat)
{
uchar a,i;
bit xie;
for(a=0;a<8;a++)
{
xie=dat&0x01;
dat>>1;
if(xie)
{
wd=0;
i++;i++;
wd=1;
i=8;
while(i--);
}
else
{
wd=1;
i=8;
while(i--);
wd=0;
i++;i++;
}
}
}
void zhuanhua()
{
fuwei();
delay(1);
duyigezijie(0xcc);
duyigezijie(0x44);
}
uint duqushuju()
{
uchar a,b;
fuwei();
delay(1);
duyigezijie(0xcc);
duyigezijie(0xbe);
a=yigezifu();
b=yigezifu();
wendu=(a+b*256)*0.625;
return wendu;
}
void xianshishuju(uchar a,uchar b)
{
uchar c;
c=~((0x01)<<a);
we=1;
P0=c;
we=0;
P0=0xff;
du=1;
P0=table
;
du=0;
}
void shujudefenpei(uchar t)
{
uchar shi,ge,shii;
shi=t/100;
xianshishuju(0,shi);
ge=t/100/10;
xianshishuju(0,shi+10);
shii=t%10;
xianshishuju(0,shii);
}
void panduanwendu()
{
if(wendu>warn_h2)
{
P1=0xfe;
shujudefenpei(duqushuju());
}
else if(wendu<warn_h2&&wendu>warn_h1)
{
P1=0xfd;
shujudefenpei(duqushuju());
}
else if(wendu>warn_l1&&wendu<warn_h1)
{
P1=0xfb;
shujudefenpei(duqushuju());
}
else if(wendu<warn_l2)
{
P1=0xf7;
shujudefenpei(duqushuju());
}
}
void chuankouchushihua()
{
TMOD=0X20;
PCON=0X00;
SCON=0X50;
TH1=0XFD;
TL1=0XFD;
TR1=1;
}
void comm(char *parr)
{
do
{
SBUF=*parr++;
while(!TI);
TI=0;
} while(*parr);
}
void main()
{
uchar buff[4],i;
du=0;
we=0;
chuankouchushihua();
while(1);
{
zhuanhua();
for(i=10;i>0;i++)
{
shujudefenpei(duqushuju());
}
shujudefenpei(wendu);
printf(buff,"%f",wendu);
for(i=10;i>0;i++)
{
shujudefenpei(duqushuju());
}
comm(buff);
for(i=10;i>0;i++)
{
shujudefenpei(duqushuju());
}
}
}
此帖出自
小平头技术问答
一周热门 更多>