51单片机标准函数stdlib.h利用rand随机数闪烁led+Proteus仿真
51单片机标准函数stdlib.h利用rand随机数闪烁led+Proteus仿真

- 利用标准函数库当中的rand函数产生随机数,制作led灯闪烁
程序代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| //标准函数stdlib.h应用 #include<reg51.h> //包含51单片机寄存器定义的头文件 #include<stdlib.h> //包含函数isalpha()声明的头文件 /\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* 函数功能:延时约150ms \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/ void delay(void) { unsigned char m,n; for(m=0;m<200;m++) for(n=0;n<250;n++) ; } /\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* 函数功能:主函数 \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/ void main(void) { unsigned char i; while(1) { for(i=0;i<10;i++) //产生10个随机数 { P3=rand()/160; //将产生的随机数缩小160倍后送P3显示 delay(); } } }
|
程序源码和仿真资源
1 2 3
| 链接:https://pan.baidu.com/s/1jMGJQLMGc6XyVa9hJ2NPUQ 提取码:s818
|
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!