单片机实验程序
1个回答
关注
展开全部
#include //头文件sbit led1 = P1^0; //定义8个LED灯sbit led2 = P1^1;sbit led3 = P1^2;sbit led4 = P1^3;sbit led5 = P1^4;sbit led6 = P1^5;sbit led7 = P1^6;sbit led8 = P1^7;void Delay(unsigned int i) //延时函数{ unsigned int x,y; for(x=i;x>0;x--) for(y=10;y>0;y--);}void main(){ while(1) //死循环 { led1 = ~led1; //交替闪烁 Delay(500); //延时500毫秒 led2 = ~led2; Delay(500); led3 = ~led3; Delay(500); led4 = ~led4; Delay(500); led5 = ~led5; Delay(500); led6 = ~led6; Delay(500); led7 = ~led7; Delay(500); led8 = ~led8; Delay(500); }}
咨询记录 · 回答于2023-04-09
单片机实验程序
用延时写一个程序代码,要求和p1口连接的八个LED灯交替闪烁
可以吗
#include //头文件sbit led1 = P1^0; //定义8个LED灯sbit led2 = P1^1;sbit led3 = P1^2;sbit led4 = P1^3;sbit led5 = P1^4;sbit led6 = P1^5;sbit led7 = P1^6;sbit led8 = P1^7;void Delay(unsigned int i) //延时函数{ unsigned int x,y; for(x=i;x>0;x--) for(y=10;y>0;y--);}void main(){ while(1) //死循环 { led1 = ~led1; //交替闪烁 Delay(500); //延时500毫秒 led2 = ~led2; Delay(500); led3 = ~led3; Delay(500); led4 = ~led4; Delay(500); led5 = ~led5; Delay(500); led6 = ~led6; Delay(500); led7 = ~led7; Delay(500); led8 = ~led8; Delay(500); }}