首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >检测上升和下降温度C

检测上升和下降温度C
EN

Stack Overflow用户
提问于 2020-07-18 02:49:59
回答 1查看 100关注 0票数 0

我正在尝试使用PIC16F877A单片机和两个DS8B20传感器来检测温度的上升和下降。当我试图探测到温度下降时,我会遇到一些问题。下面是我的代码,我想要做什么:

代码语言:javascript
复制
#include "main.h"

void main() {

    //Turn on LCD backlight
    output_high(PIN_D7);

    // Initialize LCD module
    lcd_init();

    float Threshold_Value = 30;  // Temperature threshold value

    while (TRUE) {

        Show_User_Info();
        delay_ms(10);
        Read_Sensors();

        // Starting to read user button values
        User_Buttons();
        delay_ms(20);               // Minimum amount of time to read user button  values

        // Starting to compare user set temperature value and upper sensor temperature  read value.
        Compare_Upper_Temp();
        delay_ms(20);

        //================================

        // Checking, if the MCU pin connected to pump is high. If yes - do the waiting 'animation'
        if (input(PIN_B5)) {

            while(temp > Threshold_Value);
            {
                Bottom_Waiting_Animation();
            }

            // Experimenting....
            // break;
            // continue;
        }

        if (input(PIN_B5)) {
            while(temp < Threshold_Value);
            {
                Bottom_Waiting_Animation();
            }
            // break;
        }

        // If the set temp is less than threshold - turn the pump off.

        if (temp < Threshold_Value) {
            input(PIN_B5) == 0;
        }
    }
}

当泵打开时,我需要等到第二个传感器达到阈值( 30C ),然后我需要“检测”温度从30C开始下降的时间。我上传的这段代码只在一个While(temp > Threshold_Value)循环中起作用。但是当我在它下面插入下一个(temp< Threshold_Value)时,单片机跳跃在未定义的区域并卡住了。这个任务听起来很简单,但是我尝试了很多不同的方法来解决这个问题。也许问题的原因之一可能是多个while循环?

EN

回答 1

Stack Overflow用户

发布于 2020-07-18 03:47:21

不要在while条件后使用分号。

替换

代码语言:javascript
复制
while (condition);
{
    ... looped code ...
}

使用

代码语言:javascript
复制
while (condition)
{
    .... looped code ...
}

这是我喜欢将左大括号放在条件末尾的原因之一(就像您在if语句中所做的那样):它有助于看到令人讨厌的意外分号。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62960138

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档