单片机,花样流水灯(用循环结构实现):先下面4个LED灯闪烁3次,再上面4个

2024-12-14 17:18:40
推荐回答(1个)
回答1:

#include
#define uchar unsigned char
uchar num;
sfr led=P0;
sbit speaker=P1^0;
void delay(uchar a)
{
uchar i;
while(a--)for(i=0;i<120;i++);
}
main()
{
uchar i;
while(1)
{
for(i=0;i<3;i++)
{
led=0xf0;
delay(200);
clr speaker;
led=0xff;
delay(200)
setb speaker;
for(i=0;i<3;i++)
{
led=0x0f;
delay(200);
clr speaker;
led=0xff;
delay(200)
setb speaker;
}
for(i=0;i<2;i++)
{
led=0x00;
delay(200);
clr speaker;
led=0xff;
delay(200)
setb speaker;
}
}