本帖最后由 626361893 于 2015-6-3 12:35 编辑
下面是我的代码,哪里错了呢。。
#include<reg52.h>
#include<math.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]="CH4 Data";
uchar code table1[]="CH4: PPM";
uchar code shu[]="0123456789 ";
sbit lcdrs=P2^0;
sbit lcdrw=P2^1;
sbit lcden=P2^2;
sbit st=P3^5;
sbit oe=P3^6;
sbit eoc=P3^4;
sbit d1=P2^3;
sbit d2=P2^4;
sbit d3=P2^5;
sbit xa=P3^7;
sbit jch4=P2^6;
void ad0809_ch4();
void anjian();
void display_ch4(uint);
uint num,b,wan,qian,bai,shi,ge;
void delay(uchar z)
{
uchar x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uint com)
{
lcdrs=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_data(uint date)
{
lcdrs=1;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void init()
{ d3=1;
lcdrw=0;
lcden=0;
write_com(0x38);
write_com(0x0e);
write_com(0x06);
write_com(0x01);
write_com(0x80);
}
void main()
{
init();
for(num=0;num<16;num++)
{
write_data(table[num]);
delay(1);
}
write_com(0x80+0x40);
for(num=0;num<16;num++)
{
write_data(table1[num]);
delay(1);
}
while(1)
{
anjian();
}
}
void display_ch4(uint s)
{ wan=s/10000;
qian=s%10000/1000;
bai=s%1000/100;
shi=s%100/10;
ge=s%10;
write_com(0x80+0x45);
write_data(shu[wan]);
write_com(0x80+0x46);
write_data(shu[qian]);
write_com(0x80+0x47);
write_data(shu[bai]);
write_com(0x80+0x48);
write_data(shu[shi]);
write_com(0x80+0x49);
write_data(shu[ge]);
}
void ad0809_ch4()
{
xa=0;
st=0;
st=1;
st=0;
while(!eoc);
oe=1;
b=P1;
oe=0;
b=b*40;
display_ch4(b);
if(b>5000)
{
d1=1;
d2=0;
d3=0;
}
if(b<=5000)
{
d1=0;
d2=1;
d3=1;
}
}
void anjian()
{
if(jch4=0)
{ while(!jch4);
while(1)
{
ad0809_ch4();
}
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>