MQ3酒精传感器通过ADC0804转换后,显示无法试试改变
时间:10-02
整理:3721RD
点击:
需要复位或者重新上电
#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
#include"12864.h"
sbit we=P2^7;
sbit du=P2^6;
sbit wr=P3^6;
sbit rd=P3^7;
sbit d1=P1^3;
unsigned int val;
void xian_zi() //显示字符
{
set_xy(3,0);
string("浓度: mg/L");
}
void xian_shu2(uint num) //显示距离
{
set_xy(3,2);
string(":");
wr_data(num%1000/100+0x30);
set_xy(3,3);
string(".");
wr_data(num%100/10+0x30);
set_xy(3,4);
wr_data(num%10+0x30);
string("m");
}
void bao_jing4()
{
set_xy(4,0);
string("逗比,还开车");
}
unsigned char AD()
{
uchar a;
rd=1;
wr=1;
_nop_();
P1=0xff;
_nop_();
wr=0;
_nop_();
wr=1;
_nop_();
rd=0;
_nop_();
val=P1;
rd=1;
// xian_shu(val);
return val;
}
void ti_shi()
{
if(val>=10)
{
d1=0;
delay(200);
d1=1;
delay(200);
bao_jing4();
}
}
void main()
{
lcd_init();
P0=0x7f;
xian_zi();
while(1)
{
xian_shu2(AD());
ti_shi();
}
}
/***********12864显示******************/#ifndef __12864_H__#define __12864_H__#include <reg52.H>#define K P0sbit EN=P3^4;sbit RS=P3^5;sbit RW=P3^6;sbit PSB=P3^7;void delay(uint z){ uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--);}void wr_com(uchar com) //写指令{ EN=0; RS=0; RW=0; delay(1); K=com; EN=1; EN=0;}void wr_data(uchar date) //写数据{ EN=0; RS=1; RW=0; delay(1); K=date; EN=1; EN=0;}void set_xy(uchar X,Y) //坐标{ uchar pla; if(X==1) { X=0x80; } if(X==2) { X=0x90; } if(X==3) { X=0x88; } if(X==4) { X=0x98; } pla=X+Y; wr_com(pla);}void string(uchar *P){ while(*P!='\0') { wr_data(*P); P++; }}void lcd_init(){ PSB=1; delay(30); wr_com(0x38); delay(10); wr_com(0x0c); delay(10); wr_com(0x01); delay(10);}#endif
#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
#include"12864.h"
sbit we=P2^7;
sbit du=P2^6;
sbit wr=P3^6;
sbit rd=P3^7;
sbit d1=P1^3;
unsigned int val;
void xian_zi() //显示字符
{
set_xy(3,0);
string("浓度: mg/L");
}
void xian_shu2(uint num) //显示距离
{
set_xy(3,2);
string(":");
wr_data(num%1000/100+0x30);
set_xy(3,3);
string(".");
wr_data(num%100/10+0x30);
set_xy(3,4);
wr_data(num%10+0x30);
string("m");
}
void bao_jing4()
{
set_xy(4,0);
string("逗比,还开车");
}
unsigned char AD()
{
uchar a;
rd=1;
wr=1;
_nop_();
P1=0xff;
_nop_();
wr=0;
_nop_();
wr=1;
_nop_();
rd=0;
_nop_();
val=P1;
rd=1;
// xian_shu(val);
return val;
}
void ti_shi()
{
if(val>=10)
{
d1=0;
delay(200);
d1=1;
delay(200);
bao_jing4();
}
}
void main()
{
lcd_init();
P0=0x7f;
xian_zi();
while(1)
{
xian_shu2(AD());
ti_shi();
}
}
/***********12864显示******************/#ifndef __12864_H__#define __12864_H__#include <reg52.H>#define K P0sbit EN=P3^4;sbit RS=P3^5;sbit RW=P3^6;sbit PSB=P3^7;void delay(uint z){ uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--);}void wr_com(uchar com) //写指令{ EN=0; RS=0; RW=0; delay(1); K=com; EN=1; EN=0;}void wr_data(uchar date) //写数据{ EN=0; RS=1; RW=0; delay(1); K=date; EN=1; EN=0;}void set_xy(uchar X,Y) //坐标{ uchar pla; if(X==1) { X=0x80; } if(X==2) { X=0x90; } if(X==3) { X=0x88; } if(X==4) { X=0x98; } pla=X+Y; wr_com(pla);}void string(uchar *P){ while(*P!='\0') { wr_data(*P); P++; }}void lcd_init(){ PSB=1; delay(30); wr_com(0x38); delay(10); wr_com(0x0c); delay(10); wr_com(0x01); delay(10);}#endif
小编无法改变你确定ad已经工作了吗?如果工作,mq-3要加上下拉电阻奥。
我以为是MQ-3 。