新手 想要调用子程序实现延时功能 总是报错找不到问题
#include <reg52.h>
#include <math.h>
#define uint unsigned uint
#define uchar unsigned uchar
sbit D0=P0^0;
void Delay1ms()
{
uint a;
uint b;
for(a=200;a>0;a--)
{
for(b=500;b>0;b--)
{
};
};
}
void main()
{
while(1)
{
D0=0;
Delay1ms();
D0=1;
Delay1ms();
};
}
keil中编译后报错
compiling lesson1.c...
lesson1.c(8): error C141: syntax error near 'a'
lesson1.c(9): error C231: 'uint': redefinition
lesson1.c(9): error C141: syntax error near 'b'
lesson1.c - 3 Error(s), 0 Warning(s).
不知道应该如何修改 求教。
#include <reg52.h>
#include <math.h>
#define uint unsigned int
#define uchar unsigned char
sbit D0=P0^0;
void Delay1ms()
{
uint a;
uint b;
for(a=200;a>0;a--)
{
for(b=500;b>0;b--);
}
}
void main()
{
while(1)
{
D0=0;
Delay1ms();
D0=1;
Delay1ms();
}
你现在试下! 朋友你得先学学C语言啊,
#include<reg52.h>
/*----------------------*/
void DelayMs(unsigned char t)
{
while(--t)
{
Delayus(250);
Delayus(250);
}
}
void Delayus(unsigned char m)
{
while(m--);
}
void main()
{
while(1)
{
DelayMs(5);
D0=0;
DelayMs(200);
D0=1;
DelayMs(200);
}
这样别写的代码效率要高!
后来搞好了 谢谢哈
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar temp=0xfe;
void Delay1ms()
{
uint a;
uint b;
for(a=200;a>0;a--)
{
for(b=100;b>0;b--)
{
};
};
}
void main()
{
while(1)
{
P0=temp;
temp=_crol_(temp,1);
Delay1ms();
};
}
这个循环左移我编译也有错
compiling lesson1.c...
lesson1.c(23): warning C206: '_crol_': missing function-prototype
lesson1.c(23): error C267: '_crol_': requires ANSI-style prototype
lesson1.c - 1 Error(s), 1 Warning(s).
缺少声明 加上这段就行了 #include <math.h>
解决了
忘记加头文件
打扰。