51单片机流水灯无法生成hex文件

刚刚开始学习51单片机流水灯无法生成hex文件,恳请各位朋友们帮忙看下问题在哪


#include <reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar temp;
void delay(uint z)
{
  uint x,y;
  for(x=z;x>0;x--)
for(y=114;y>0;y--);
}
void main()
{
   temp=0xfe;
   P1=temp;
   while(1)
   temp=_crol_(temp,1);
   P1=temp;
   delay(150);
}

下面是这么报的:
Rebuild target 'Target 1'
compiling lsd.c...
lsd.c(18): warning C294: unreachable code
linking...
*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
    SEGMENT: ?PR?_DELAY?LSD
Program Size: data=10.0 xdata=0 code=66
".\Objects\lsd" - 0 Error(s), 2 Warning(s).
Build Time Elapsed:  00:00:00

output选项里,要勾选输出hex文件,这个选项默认是没有勾选的。
代码只是有警告,没有错误,而且只是某个函数没被调用的警告,不影响程序运行,不影响生产hex文件。

while(1)
   temp=_crol_(temp,1);

这个陷入死循环了

【以下回答由 GPT 生成】

根据报错信息和代码分析,问题出在代码中while循环后的部分。在while循环后的部分,缺少了花括号,导致while循环只执行了temp=crol(temp,1)这一条语句,而后面的P1=temp和delay(150)这两条语句被误认为是while循环外的语句,所以会报warning C294: unreachable code的警告。

#include <reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar temp;
void delay(uint z)
{
  uint x,y;
  for(x=z;x>0;x--)
    for(y=114;y>0;y--);
}
void main()
{
   temp=0xfe;
   P1=temp;
   while(1)
   {
     temp=_crol_(temp,1);
     P1=temp;
     delay(150);
   }
}

经过修改后,再重新编译生成.hex文件即可。



【相关推荐】



如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^