8個發(fā)光管由上至下間隔1s流動,其中每個管亮500ms,滅500ms,亮?xí)r蜂鳴器響,滅時關(guān)閉蜂鳴器,一直重復(fù)下去。
C++ Code
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
31
32
33
34
#include
#include
#defineucharunsignedchar
ucharx,temp;
sbitbuzzer=P2^3;
voiddelayms(ucharz);
voidmain()
{
temp=0xfe;
while(1)
{
for(x=8;x>0;x--)
{
P1=temp;
buzzer=0;
delayms(500);
P1=0xff;
buzzer=1;
delayms(500);
temp=_crol_(temp,1);
}
}
}
voiddelayms(ucharz)//延時函數(shù)
{
ucharx,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}