找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1638|回復: 2
收起左側

這個程序就是報DTSY.C(55): error C171: 'break': missing enclosing loop

[復制鏈接]
ID:1111118 發(fā)表于 2024-2-18 21:09 | 顯示全部樓層 |閱讀模式
#include "reg52.h"
#include "MATH.h"
typedef unsigned int u16;       
typedef unsigned char u8;
typedef unsigned long u32;
typedef int uf16;       
typedef char uf8;
typedef long uf32;
sbit KEY1=P3^1;
sbit KEY2=P3^0;
sbit KEY3=P3^2;
sbit KEY4=P3^3;
sbit up=P2^0;
sbit down=P2^1;
#define KEY1_PRESS        1
#define KEY2_PRESS        2
#define KEY3_PRESS        3
#define KEY4_PRESS        4
#define KEY_UNPRESS        0
u8 current=0;
u8 call=0;
u8 key=0;
u8 Floordifference=0;       
void delay_10us(u32 ten_us)
{
        while(ten_us--);       
}
u8 key_scan(u8 mode)
{
        static u8 key=1;

        if(mode)key=1;
        if(key==1&&(KEY1==0||KEY2==0||KEY3==0||KEY4==0))
        {
                delay_10us(1000);
                key=0;
                if(KEY1==0)
                        return KEY1_PRESS;
                else if(KEY2==0)
                        return KEY2_PRESS;
                else if(KEY3==0)
                        return KEY3_PRESS;
                else if(KEY4==0)
                        return KEY4_PRESS;       
        }
        else if(KEY1==1&&KEY2==1&&KEY3==1&&KEY4==1)       
        {
                key=1;
                return KEY_UNPRESS;                               
        }
        return KEY_UNPRESS;               
}
void exit()
{
break;
}
void assignment()
{
         while(1)
        {       
                        key=key_scan(0);
                        if(key==KEY1_PRESS)
                        {
                                call=KEY1_PRESS;
                        }
                        else if(key==KEY2_PRESS)
                        {
                                call=KEY2_PRESS;
                        }
                        else if(key==KEY3_PRESS)
                        {
                                call=KEY3_PRESS;
                    }
                        else if(key==KEY4_PRESS)
                        {
                                call=KEY4_PRESS;
                        }
                        else if(KEY1==0||KEY2==0||KEY3==0||KEY4==0)
                        {
                                exit();
                        }
        }
}
void lift()
{
        assignment();
        if(current<call)
        {
            Floordifference=call-current;
                current=call;
                down=0;
                delay_10us(abs(Floordifference)*5000);
        }
        if(current>call)
        {
            Floordifference=current-call;
                current=call;
                up=0;
                delay_10us(Floordifference*5000);
        }               
}
void main()
{
lift();
大家看一下。

回復

使用道具 舉報

ID:1088185 發(fā)表于 2024-2-19 00:39 | 顯示全部樓層
Break 不能這樣用, Break原則上是個goto 的語句, 在函數(shù)里再goto 就錯了
你可以用 #define exit()  break
回復

使用道具 舉報

ID:883242 發(fā)表于 2024-2-19 06:13 | 顯示全部樓層
把while(1)改成while(!(KEY1||KEY2||KEY3||KEY4)),并把while(1)內層對應語句刪掉,exit()相關語句也可以刪掉。
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表