|
板子是自己焊接的,1602調(diào)試可用,圖片中與四根杜邦線相連的器件就是MQ-7,芯片與ADC0832的0通道連接,單片機(jī)進(jìn)行數(shù)據(jù)處理后將數(shù)據(jù)顯示在液晶屏1602上。程序是直接燒入在芯片中,所以下載器只接了正負(fù)極,給板子供電。
問題是MQ-7可以檢測(cè)氣體,但是數(shù)據(jù)傳不到單片機(jī),無法進(jìn)一步處理,是硬件問題還是軟件問題呢,請(qǐng)給出具體解決辦法吧,非常感謝了,以下是所有程序
主函數(shù)部分
- #include <reg52.h>
- #include <intrins.h>
- #include <math.h>
- #include <stdio.h>
- #include "ad08.h"
- #include "l1602.h"
- #define uint unsigned int
- #define uchar unsigned char
- uchar qt;
- void LCD_init(void);
- unsigned int Adc0832(unsigned char channel);
- void LCD_disp_char(uchar x,uchar y,uchar dat);//??????????????,X(0-15),y(1-2)
- void LCD_disp_str(uchar x,uchar y,uchar *str);
- void main()
- {
- LCD_init();
-
- while(1)
- {
- qt=Adc0832(0);
- qt = qt*19.607843; //轉(zhuǎn)換為實(shí)際電壓便于顯示
- qt=qt/1000%10;
- LCD_disp_str(9,0,"Q:");
- LCD_disp_char(11,0,qt/100+0x30);
- LCD_disp_char(12,0,qt%100/10+0x30);
- LCD_disp_char(13,0,qt%100%10+0x30);
- LCD_disp_str(14,0,"p");
- }
- }
復(fù)制代碼 ADC0832部分
- #include <reg52.h>
- #include <intrins.h>
- #include <math.h>
- #include <stdio.h>
- #include "ad08.h"
- unsigned int Adc0832(unsigned char channel)
- {
- uchar i=0;
- uchar j;
- long dat=0;
- uchar ndat=0;
- uchar Vot=0;
- if(channel==0)channel=2;
- if(channel==1)channel=3;
- ADDI=1;
- _nop_();
- _nop_();
- ADCS=0;//??CS?
- _nop_();
- _nop_();
- ADCLK=1;//??CLK?
- _nop_();
- _nop_();
- ADCLK=0;//拉低CLK端,形成下降沿1
- _nop_();
- _nop_();
- ADCLK=0;
- _nop_();
- _nop_();
- ADCLK=1;//??CLK?
- ADDI=channel&0x1;
- _nop_();
- _nop_();
- ADCLK=0;//拉低CLK端,形成下降沿2
- _nop_();
- _nop_();
- ADCLK=1;//??CLK?
- ADDI=(channel>>1)&0x1;
- _nop_();
- _nop_();
- ADCLK=0;//拉低CLK端,形成下降沿3
- ADDI=1;//控制命令結(jié)束
- _nop_();
- _nop_();
- dat=0;
- for(i=0;i<8;i++)
- {
- dat|=ADDO;//接收數(shù)據(jù)
- ADCLK=1;
- _nop_();
- _nop_();
- ADCLK=0;//形成一次時(shí)鐘脈沖
- _nop_();
- _nop_();
- dat<<=1;
- if(i==7)dat|=ADDO;
- }
- for(i=0;i<8;i++)
- {
- j=0;
- j=j|ADDO;//接收數(shù)據(jù)
- ADCLK=1;
- _nop_();
- _nop_();
- ADCLK=0;//形成一次時(shí)鐘脈沖
- _nop_();
- _nop_();
- j=j<<7;
- ndat=ndat|j;
- if(i<7)ndat>>=1;
- }
- ADCS=1;//??CS?
- ADCLK=0;//??CLK?
- ADDO=1;//拉高數(shù)據(jù)端,回到初始狀態(tài)
- dat<<=8;
- dat|=ndat;
- return(dat); //return ad data
- }
復(fù)制代碼
ADC0832頭文件
- #ifndef _L08_H
- #define _L08_H
- #include <reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit ADCS =P1^2; //ADC0832 使能口
- sbit ADCLK =P1^3; //ADC0832 時(shí)鐘口
- sbit ADDI =P1^4; //ADC0832 數(shù)據(jù)口
- sbit ADDO =P1^4;
- unsigned int Adc0832(unsigned char channel);
- #endif
復(fù)制代碼
液晶1602部分
- #include <reg52.h>
- #include <intrins.h>
- #include <math.h>
- #include <stdio.h>
- #include "l1602.h"
- #define uchar unsigned char
- #define uint unsigned int
-
- void delay_n10us(uint n) //延時(shí)
- {
- uint i;
- for(i=n;i>0;i--)
- {
- nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
- }
- }
- void LCD_init(void)
- {
- delay_n10us(10);
- LCD_write_command(0x38);//??8???,2?,5x7
- delay_n10us(10); LCD_write_command(0x0c);//???,???,???
- delay_n10us(10); LCD_write_command(0x06);//??????,?????
- delay_n10us(10); LCD_write_command(0x01);//??????
- delay_n10us(100); //????,????,???n?10us
- }
- void LCD_write_command(uchar dat)
- {
- delay_n10us(10);
- LCD_RS=0; //??
- LCD_RW=0; //??
- LCD_E=1; //??
- LCD_DB=dat; delay_n10us(10); //????,??LCD1602?,?for??1???????????
- LCD_E=0; delay_n10us(10); //????,??LCD1602?,?for??1???????????
- }
- void LCD_write_data(uchar dat)
- {
- delay_n10us(10);
- LCD_RS=1; //??
- LCD_RW=0; //??
- LCD_E=1; //??
- LCD_DB=dat; delay_n10us(10);
- LCD_E=0; delay_n10us(10);
- }
- void LCD_disp_char(uchar x,uchar y,uchar dat)
- {
- uchar address;
- if(y==0)
- address=0x80+x;
- else
- address=0xc0+x;
- LCD_write_command(address);
- LCD_write_data(dat);
- }
- void LCD_disp_str(uchar x,uchar y,uchar *str)
- {
- uchar address;
- if(y==0)
- address=0x80+x;
- else
- address=0xc0+x;
- LCD_write_command(address);
- while(*str!='\0')
- {
- LCD_write_data(*str);
- str++;
- }
- }
復(fù)制代碼
液晶頭文件
- #ifndef _L1602_H
- #define _L1602_H
- #include <reg52.h>
- #define LCD_DB P0
- #define uchar unsigned char
- sbit LCD_RS=P2^7;
- sbit LCD_RW=P2^6;
- sbit LCD_E=P2^5;
- void LCD_init(void); //?????
- void LCD_write_command(uchar command); //?????
- void LCD_write_data(uchar dat); //?????
- void LCD_disp_char(uchar x,uchar y,uchar dat);//??????????????,X(0-15),y(1-2)
- void LCD_disp_str(uchar x,uchar y,uchar *str); //LCD1602???????
- #endif
復(fù)制代碼
請(qǐng)大家?guī)兔鉀Q以下吧,比較著急用呢,多謝了
|
-
|