单片机点亮流水灯。Keil总提示有错

#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int

uchar aa;

void main(){
aa = 0xfe;
uchar i;
while(1){
P1 = aa;
for(i=0;i<8;i++){
P1 = P1>>1;
}
}
}

错误:
2.c(9): error C141: syntax error near 'unsigned'
2.c(9): error C202: 'i': undefined identifier
2.c(12): error C202: 'i': undefined identifier

我写其他程序的时候这么写都对,为什么这一次就错了?是不是unsigned出错?还是变量i位置不对
另外,请大神看一下这么写,流水灯能不能运行。
还有,如何我按下一个按键,就能让流水灯停止。我只求流水灯停止代码!!谢谢啦

可能有一些中文字符,导致上述错误,通过逐个语句注释,逐个排除错误。
上述流水灯代码,中间没有延时,人眼应该分辨不出来。如果不用中断。
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit key= P2^4;

void main(){
uchar i;
uchar aa;
uchar kon;//1 run,0 stop;
uint dly;
aa = 0xfe;

while(1){
P1 = aa;
dly=5000;
if(kon)
{
for(i=0;i<8;i++){
P1 = P1>>1;
while(dly--);
}
if(key==0)
keyon=!keyon;
}

}追问

不能运行啊.....最后的keyon是什么?而且改成kon,根本就不是流水灯

追答

#include
#define uchar unsigned char
#define uint unsigned int
sbit key= P2^4;

void main(){
uchar i;
uchar aa;
uchar kon;//1 run,0 stop;
uint dly;
aa = 0xfe;

while(1){
P1 = aa;
dly=5000;
if(kon)
{
for(i=0;i>1;
while(dly--);
}
if(key==0)
kon=!kon;
while(key==0);//等待按键释放
}

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-05-05
变量i的位置是不对的,你把i的位置放在aa=0xfe前面试试追问

嗯,我自己试了下,确实是放在前面对了。为什么啊?
其他问题你能解答吗?感激不尽......

追答

这个就和开发软件的编译方式有关了,你用的应该keil吧,keil编译时必须先要申明定义好一些函数或变量,否者在编译的时候会报错,这个问题就是和编译软件有关的,影响不大,你以后写程序的时候注意点就好,把所有的变量函数都事先声明和定义好就没问题了
让流水灯停下是可以的,你要按下一个键的话,就涉及到外部中断了,不知道你有去接触这个外部中断么?

追问

我看过中断。你能不能大致写一下?

第2个回答  2015-05-05
关注这个问题

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网