您当前的位置:五五电子网电子知识单片机-工控设备AVR单片机SHT11温湿度传感器AVR单片机程序 正文
SHT11温湿度传感器AVR单片机程序

SHT11温湿度传感器AVR单片机程序

点击数:7951 次   录入时间:03-04 11:55:44   整理:http://www.55dianzi.com   AVR单片机
            shtxx_humi = shtxx_read_byte(1);
            shtxx_humi = (shtxx_humi<<8) + shtxx_read_byte(1);            
            shtxx_crc = shtxx_read_byte(0);        
            break;
        default:
            break;
    }

    return error;
}

void shtxx_calc(void)
{
    uint32 rh_line = 0;
    //所有湿度常量放大10000000
    const uint32 C1 = 40000000;
    const uint32 C2 = 405000;
    const uint32 C3 = 28;
    const uint32 T1 = 100000;
    const uint32 T2 = 8000;    
    
    //温度常量放大100
    t_c = shtxx_temp - 4000;    //结果除以100
    
    rh_line = C2*shtxx_humi - C3*shtxx_humi*shtxx_humi - C1;
    rh_true = (t_c/100-25)*(T1+T2*shtxx_humi) + rh_line;
    
    if (rh_true>1000000000) rh_true = 1000000000; //cut if the value is outside of
    if (rh_true<1000000) rh_true = 1000000; //the physICal possible range
}

void hex_bcd(uint32 hex32)
{
    MEMSet(bcd32, ’\0’, 10);
    while (hex32 >= 1000000000)        //
    {
        bcd32[9]++;
        hex32 = hex32 - 1000000000;
    }      
           
    while (hex32 >= 100000000)        //
    {
        bcd32[8]++;
        hex32 = hex32 - 100000000;
    }
    
    while (hex32 >= 10000000)        //
    {
        bcd32[7]++;
        hex32 = hex32 - 10000000;
    }
    
    while (hex32 >= 1000000)        //
    {
        bcd32[6]++;
        hex32 = hex32 - 1000000;
    }
    
    while (hex32 >= 100000)            //
    {
        bcd32[5]++;
        hex32 = hex32 - 100000;
    }
    
    while (hex32 >= 10000)            //
    {
        bcd32[4]++;
        hex32 = hex32 - 10000;
    }    
    
    while (hex32 >= 1000)            //
    {
        bcd32[3]++;
        hex32 = hex32 - 1000;
    }    
    
    while (hex32 >= 100)            //
    {
        bcd32[2]++;
        hex32 = hex32 - 100;
    }    
    
    while (hex32 >= 10)                //
    {
        bcd32[1]++;
        hex32 = hex32 - 10;
    }
    
    bcd32[0] = hex32;
}

void shtxx_disp(void)
{
    if (!shtxx_measure(SHTXX_MODE_TEMP))
    {
        shtxx_calc();
        hex_bcd(t_c);
        LCD_print_str(2, 1, "温度: ");
        
        if(bcd32[4] != 0)
            lcd_write_dat(bcd32[4]+0x30);
        lcd_write_dat(bcd32[3]+0x30);
        lcd_write_dat(bcd32[2]+0x30);
        lcd_write_dat(’.’);
        lcd_write_dat(bcd32[1]+0x30);
        lcd_write_dat(bcd32[0]+0x30);
    }
    if (!shtxx_measure(SHTXX_MODE_HUMI))
    {
        shtxx_calc();
        hex_bcd(rh_true);
        lcd_print_str(3, 1, "湿度: ");
        
        if(bcd32[9] != 0)
            lcd_write_dat(bcd32[9]+0x30);
        lcd_write_dat(bcd32[8]+0x30);
        lcd_write_dat(bcd32[7]+0x30);
        lcd_write_dat(’.’);
        lcd_write_dat(bcd32[6]+0x30);

上一页  [1] [2] [3]  下一页


本文关键字:传感器  单片机程序  AVR单片机单片机-工控设备 - AVR单片机