延时函数每次的值不一样,每次都得重新调用,很烦
所以,我们需要给他设置为可以实现任何ms的调用(0~~65535)
首先复制1ms的延时函数代码
void Delay(unsigned int xms) //@11.0592MHz
{
unsigned char i, j;
while(xms)
{
_nop_();
i = 2;
j = 199;
do
{
while (--j);
} while (--i);
xms--;
}
}
传参,即可
改变后的代码为
#include <REGX51.H>
#include <INTRINS.H>
void Delay(unsigned int xms) //@11.0592MHz
{
unsigned char i, j;
while(xms)
{
_nop_();
i = 2;
j = 199;
do
{
while (--j);
} while (--i);
xms--;
}
}
void main()
{
while(1)
{
P2 = 0xFE;
Delay(100);
P2 = 0xFD;
Delay(100);
P2 = 0xFB;
Delay(100);
P2 = 0xF7;
Delay(100);
P2 = 0xEF;
Delay(100);
P2 = 0xDF;
Delay(100);
P2 = 0xBF;
Delay(100);
P2 = 0x7F;
Delay(100);
}
}
版权声明:本文为CSDN博主「qq_40179113」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_40179113/article/details/122189337
延时函数每次的值不一样,每次都得重新调用,很烦
所以,我们需要给他设置为可以实现任何ms的调用(0~~65535)
首先复制1ms的延时函数代码
void Delay(unsigned int xms) //@11.0592MHz
{
unsigned char i, j;
while(xms)
{
_nop_();
i = 2;
j = 199;
do
{
while (--j);
} while (--i);
xms--;
}
}
传参,即可
改变后的代码为
#include <REGX51.H>
#include <INTRINS.H>
void Delay(unsigned int xms) //@11.0592MHz
{
unsigned char i, j;
while(xms)
{
_nop_();
i = 2;
j = 199;
do
{
while (--j);
} while (--i);
xms--;
}
}
void main()
{
while(1)
{
P2 = 0xFE;
Delay(100);
P2 = 0xFD;
Delay(100);
P2 = 0xFB;
Delay(100);
P2 = 0xF7;
Delay(100);
P2 = 0xEF;
Delay(100);
P2 = 0xDF;
Delay(100);
P2 = 0xBF;
Delay(100);
P2 = 0x7F;
Delay(100);
}
}
版权声明:本文为CSDN博主「qq_40179113」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_40179113/article/details/122189337
暂无评论