失去zi的蓝 发表于 2015-5-23 15:19:38

小白求助

#define DHT11_PIN 5      // DHT11连接UNO 模拟端口PIN 5
#include<LiquidCrystal.h>
byte read_dht11_dat()
{
        byte i = 0;
        byte result=0;
        for(i=0; i< 8; i++){
                while(!(PINC & _BV(DHT11_PIN)));// wait for 50us
                delayMicroseconds(30);               
                if(PINC & _BV(DHT11_PIN))
                        result |=(1<<(7-i));
            while((PINC & _BV(DHT11_PIN)));// wait '1' finish   
        }
        return result;
}


LiquidCrystal lcd(12,11,5,4,3,2);
void setup()
{
Serial.begin(19200);
lcd.begin(20,2);
   DDRC |= _BV(DHT11_PIN);
   PORTC |= _BV(DHT11_PIN);
}
       
void loop()
{
        byte dht11_dat;
        byte dht11_in;
        byte i;
        // start condition
        // 1. pull-down i/o pin from 18ms
        PORTC &= ~_BV(DHT11_PIN);
        delay(18);
        PORTC |= _BV(DHT11_PIN);
        delayMicroseconds(40);
       
        DDRC &= ~_BV(DHT11_PIN);
        delayMicroseconds(40);
       
        dht11_in = PINC & _BV(DHT11_PIN);
       
        if(dht11_in){
                Serial.println("dht11 start condition 1 not met");
                return;
        }
        delayMicroseconds(80);
       
        dht11_in = PINC & _BV(DHT11_PIN);
       
        if(!dht11_in){
                Serial.println("dht11 start condition 2 not met");
                return;
        }
        delayMicroseconds(80);
        // now ready for data reception
        for (i=0; i<5; i++)
                dht11_dat = read_dht11_dat();
               
        DDRC |= _BV(DHT11_PIN);
        PORTC |= _BV(DHT11_PIN);
       
      byte dht11_check_sum = dht11_dat+dht11_dat+dht11_dat+dht11_dat;
        // check check_sum
        if(dht11_dat!= dht11_check_sum)
        {
                Serial.println("DHT11 checksum error");
        }
          lcd.setCursor(0,0);
       lcd.print("H = ");
       lcd.print(dht11_dat, DEC);
       lcd.print(".");
       lcd.print(dht11_dat, DEC);
       lcd.print("%");
         lcd.setCursor(0,1);
       lcd.print("t = ");
       lcd.print(dht11_dat, DEC);
       lcd.print(".");
       lcd.print(dht11_dat, DEC);
       lcd.print("C");
       
        delay(200);
}
为何程序对了,上传之后   屏幕不显示啊

失去zi的蓝 发表于 2015-5-23 15:21:22

lcd2004的屏幕

Siegfried 发表于 2015-5-23 17:04:02

同楼上
嗯,应该是LED的问题
页: [1]
查看完整版本: 小白求助