如何在这个单片机流水灯程序里再加上控制奇数灯亮后偶数灯亮?
#include<reg51.h>#defineLEDP1voiddelay(int);main(){unsignedchari;LED=0xfe;while(1){fo...
#include <reg51.h>#define LED P1void delay(int); main (){unsigned char i; LED=0xfe ; while(1) {for(i=0;i<7;i++) {delay(100); LED=(LED<<1)|0X01; } for (i=0;i<7;i++) {delay(100); LED=(LED>>1)|0x80; } }}void delay (int x){int i,j; for (i=0;i<x;i++) for(j=0;j<=600;j++);}
展开
1个回答
2020-10-06
展开全部
#include <reg51.h>
#define LED P1
void delay(int);
main()
{
unsigned char i;
LED = 0xfe;
while (1)
{
for (i = 0; i < 7; i++)
{
delay(100);
LED = (LED << 1) | 0X01;
}
for (i = 0; i < 7; i++)
{
delay(100);
LED = (LED >> 1) | 0x80;
}
for (i = 1; i < 7; i += 2)
{
delay(100);
LED = (LED >> 1) | 0x80;
}
for (i = 0; i < 7; i += 2)
{
delay(100);
LED = (LED >> 1) | 0x80;
}
}
}
void delay(int x)
{
int i, j;
for (i = 0; i < x; i++)
for (j = 0; j <= 600; j++)
;
}
#define LED P1
void delay(int);
main()
{
unsigned char i;
LED = 0xfe;
while (1)
{
for (i = 0; i < 7; i++)
{
delay(100);
LED = (LED << 1) | 0X01;
}
for (i = 0; i < 7; i++)
{
delay(100);
LED = (LED >> 1) | 0x80;
}
for (i = 1; i < 7; i += 2)
{
delay(100);
LED = (LED >> 1) | 0x80;
}
for (i = 0; i < 7; i += 2)
{
delay(100);
LED = (LED >> 1) | 0x80;
}
}
}
void delay(int x)
{
int i, j;
for (i = 0; i < x; i++)
for (j = 0; j <= 600; j++)
;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询