找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4022|回复: 8
收起左侧

单片机延时循环次数代码出错 error C141: syntax error near 'unsigned'

[复制链接]
ID:833082 发表于 2020-10-22 11:07 | 显示全部楼层 |阅读模式
流水灯想循环几次,现在出错,找不出错误,求大神指点
#include <reg51.h>
#include <intrins.h>
#define uint unsigned int

uint aa;

void delay(uint i)
{
uint j;
uint k;
for(j=i;j>0;j--)
   for(k=110;k>0;k--);
}

void main()
{
aa=0xff;

uint m;
for(m=20,m>0;m--)
  {
while(1)
     {
     P1=aa;
           delay(1000);
     aa=_crol_(aa,1);
     }
  }

}

Build target 'Target 1'
compiling 5.c...
5.C(19): error C141: syntax error near 'unsigned'
5.C(19): error C202: 'm': undefined identifier
5.C(20): error C202: 'm': undefined identifier
5.C(20): error C141: syntax error near ')'
Target not created



回复

使用道具 举报

ID:332444 发表于 2020-10-22 12:55 | 显示全部楼层
这样写循环是无用的,while(1)是无限循环。
回复

使用道具 举报

ID:833082 发表于 2020-10-22 13:02 | 显示全部楼层
xianfajushi 发表于 2020-10-22 12:55
这样写循环是无用的,while(1)是无限循环。

那我只用for循环的话也会出现类似的情况
回复

使用道具 举报

ID:833129 发表于 2020-10-22 13:25 | 显示全部楼层
while(1)
{
aa = _crol_(aa,1);
P1 = aa;
delay(1000);
}
你可以这样写
你写的while(1)循环里边每次都执行P1 = aa;
所以没办法实现移位的效果。
建议想想程序是怎么执行的。
回复

使用道具 举报

ID:712493 发表于 2020-10-22 15:00 | 显示全部楼层
m  没定义
回复

使用道具 举报

ID:387641 发表于 2020-10-22 15:39 | 显示全部楼层
语法错误的uint m放错位置
回复

使用道具 举报

ID:213173 发表于 2020-10-22 20:04 | 显示全部楼层
#include <reg51.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar aa;

void delay(uint i)
{
        uint j,k;
        for(j=i;j>0;j--)
                for(k=110;k>0;k--);
}

void main()
{
        aa=0xfe;
        P1=aa;
        delay(1000);
        while(1)
        {
                aa=_crol_(aa,1);
                P1=aa;
                delay(1000);
        }
}
回复

使用道具 举报

ID:833190 发表于 2020-10-23 19:28 | 显示全部楼层
把while(1)那个循环去掉,for()括号里面的逗号换成分号
回复

使用道具 举报

ID:833739 发表于 2020-10-23 19:38 | 显示全部楼层
不要在for里面放while(1),应该把for放在while(1)里面
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表