编写一段关于延时的函数,主要利用for循环,代码如下:
void delay_ms(unsigned int ms)
{undefined
unsigned int i
unsigned char j
for(i=0i
{undefined
for(j=0j<200j++)
for(j=0j<102j++)
}
}
其中ms是输入参数,如果输入1,就是要求程序延时1ms。
j变量是调整程序运行的时间参数。调整j的数值,使1次循环的时间在1ms。
将此程序编译通过,然后利用软件仿真,调整时间。
pause(n)表示延迟n秒再进行,其中n必须是正数。因此延迟5秒的命令是pause(5)。官方解释:pause(n)
pauses
executionfor
n
seconds
before
continuing,
where
n
isany
nonnegative
real
number.
Pausing
must
be
enabled
for
this
to
takeeffect.
一般延迟用的比较少,我只是在浏览图片的时候用过,每隔3秒钟打开下一张图片。
t=0:50e-3:piw = 1
ua = @(x) sin(w*x)
dt = 1/200
ub = @(x) (ua(x)*cos(w*dt)-ua(t-dt))/sin(w*dt)
plot(t, ua(t), t, ub(t))
legend ua ub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)