原理图如下(proteus仿真工程文件和51单片机完整源程序可到本帖附件中下载)
部分单片机源码:
- #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;
- }
复制代码 完整单片机源码和proteus文件
气象参数.rar
(111.09 KB, 售价: 3 E币)
【必读】版权免责声明
1、本主题所有言论和内容纯属会员个人意见,与本论坛立场无关。2、本站对所发内容真实性、客观性、可用性不做任何保证也不负任何责任,网友之间仅出于学习目的进行交流。3、对提供的数字内容不拥有任何权利,其版权归原著者拥有。请勿将该数字内容进行商业交易、转载等行为,该内容只为学习所提供,使用后发生的一切问题与本站无关。 4、本网站不保证本站提供的下载资源的准确性、安全性和完整性;同时本网站也不承担用户因使用这些下载资源对自己和他人造成任何形式的损失或伤害。 5、本网站所有软件和资料均为网友推荐收集整理而来,仅供学习用途使用,请务必下载后两小时内删除,禁止商用。6、如有侵犯你版权的,请及时联系我们(电子邮箱1370723259@qq.com)指出,本站将立即改正。
|