原理圖如下(proteus仿真工程文件和51單片機(jī)完整源程序可到本帖附件中下載)
1.png (21.18 KB)
下載附件
2021-6-11 16:08 上傳
部分單片機(jī)源碼:
- #include <reg52.h>
- #include <intrins.h>
- #include <math.h>
- #include <stdio.h>
- #define LCD_DB P0
- sbit LCD_RS=P2^0;
- sbit LCD_RW=P2^1;
- sbit LCD_E=P2^2;
- sbit ADCS =P3^4;
- sbit ADDI =P3^7;
- sbit ADDO =P3^7;
- sbit ADCLK =P3^6;
- sbit SCK = P2^6;
- sbit DATA = P2^7;
- sbit h=P1^0;
- sbit t=P1^1;
- sbit p=P1^2;
- #define noACK 0
- #define ACK 1
- #define STATUS_REG_W 0x06
- #define STATUS_REG_R 0x07
- #define MEASURE_TEMP 0x03
- #define MEASURE_HUMI 0x05
- #define RESET 0x1e
- #define uchar unsigned char
- #define uint unsigned int
- uint temp;
- uchar getdata;
- typedef union
- { unsigned int i;
- float f;
- } value;
- enum {TEMP,HUMI};
- void s_transstart(void);
- void s_connectionreset(void);
- char s_write_byte(unsigned char value);
- char s_read_byte(unsigned char ack);
- char s_measure(unsigned char *p_value, unsigned char *p_checksum, unsigned char mode);
- void calc_dht90(float *p_humidity ,float *p_temperature);
- 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);
- void LCD_disp_str(uchar x,uchar y,uchar *str);
- void delay_n10us(uint n);
- void LCD_init(void)
- {
- delay_n10us(10);
- LCD_write_command(0x38);
- delay_n10us(10);
- LCD_write_command(0x0c);
- delay_n10us(10);
- LCD_write_command(0x06);
- delay_n10us(10);
- LCD_write_command(0x01);
- delay_n10us(1000);
- }
- void LCD_write_command(uchar dat)
- {
- delay_n10us(10);
- LCD_RS=0;
- LCD_RW=0;
- LCD_E=1;
- LCD_DB=dat;
- delay_n10us(10);
- LCD_E=0;
- delay_n10us(10);
- }
- 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==1)
- 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==1)
- address=0x80+x;
- else
- address=0xc0+x;
- LCD_write_command(address);
- while(*str!='\0')
- {
- LCD_write_data(*str);
- str++;
- }
- }
- void delay_n10us(uint n)
- {
- uint i;
- for(i=n;i>0;i--)
- {
- _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
- }
- }
- void s_transstart(void)
- {
- DATA=1; SCK=0;
- _nop_();
- SCK=1;
- _nop_();
- DATA=0;
- _nop_();
- SCK=0;
- _nop_();_nop_();_nop_();
- SCK=1;
- _nop_();
- DATA=1;
- _nop_();
- SCK=0;
- }
- void s_connectionreset(void)
- {
- unsigned char i;
- DATA=1; SCK=0;
- for(i=0;i<9;i++)
- {
- SCK=1;
- SCK=0;
- }
- s_transstart();
- }
- char s_write_byte(unsigned char value)
- {
- unsigned char i,error=0;
- for (i=0x80;i>0;i/=2)
- {
- if (i & value) DATA=1;
- else DATA=0;
- SCK=1;
- _nop_();_nop_();_nop_();
- SCK=0;
- }
- DATA=1;
- SCK=1;
- error=DATA;
- _nop_();_nop_();_nop_();
- SCK=0;
- DATA=1;
- return error;
- }
- char s_read_byte(unsigned char ack)
- {
- unsigned char i,val=0;
- DATA=1;
- for (i=0x80;i>0;i/=2)
- { SCK=1;
- if (DATA) val=(val | i);
- _nop_();_nop_();_nop_();
- SCK=0;
- }
- if(ack==1)DATA=0;
- else DATA=1;
- _nop_();_nop_();_nop_();
- SCK=1;
- _nop_();_nop_();_nop_();
- SCK=0;
- _nop_();_nop_();_nop_();
- DATA=1;
- return val;
- }
- char s_measure(unsigned char *p_value, unsigned char *p_checksum, unsigned char mode)
- {
- unsigned error=0;
- unsigned int i;
- s_transstart();
- switch(mode){
- case TEMP : error+=s_write_byte(MEASURE_TEMP); break;
- case HUMI : error+=s_write_byte(MEASURE_HUMI); break;
- default : break;
- }
- for (i=0;i<65535;i++) if(DATA==0) break;
- if(DATA) error+=1;
- *(p_value) =s_read_byte(ACK);
- *(p_value+1)=s_read_byte(ACK);
- *p_checksum =s_read_byte(noACK);
- return error;
- }
復(fù)制代碼 完整單片機(jī)源碼和proteus文件
氣象參數(shù).rar
(111.09 KB, 售價(jià): 3 E幣)
【必讀】版權(quán)免責(zé)聲明
1、本主題所有言論和內(nèi)容純屬會(huì)員個(gè)人意見(jiàn),與本論壇立場(chǎng)無(wú)關(guān)。2、本站對(duì)所發(fā)內(nèi)容真實(shí)性、客觀性、可用性不做任何保證也不負(fù)任何責(zé)任,網(wǎng)友之間僅出于學(xué)習(xí)目的進(jìn)行交流。3、對(duì)提供的數(shù)字內(nèi)容不擁有任何權(quán)利,其版權(quán)歸原著者擁有。請(qǐng)勿將該數(shù)字內(nèi)容進(jìn)行商業(yè)交易、轉(zhuǎn)載等行為,該內(nèi)容只為學(xué)習(xí)所提供,使用后發(fā)生的一切問(wèn)題與本站無(wú)關(guān)。 4、本網(wǎng)站不保證本站提供的下載資源的準(zhǔn)確性、安全性和完整性;同時(shí)本網(wǎng)站也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的損失或傷害。 5、本網(wǎng)站所有軟件和資料均為網(wǎng)友推薦收集整理而來(lái),僅供學(xué)習(xí)用途使用,請(qǐng)務(wù)必下載后兩小時(shí)內(nèi)刪除,禁止商用。6、如有侵犯你版權(quán)的,請(qǐng)及時(shí)聯(lián)系我們(電子郵箱1370723259@qq.com)指出,本站將立即改正。
|