void delay(unsigned int n)
{
while(n--)
}
void main()
{
char i
unsigned char led[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}
while(1)
{
for(i=0i<8i++)
{
P1=led[i]//LED接在P1口
delay(10000)
}
for(i=0i<8i++)
{
P1=led[8-i]
delay(10000)
}
}
}
#include <reg51.h>int flag = 0
int tag = 0
void InitTimer0(void)
{
TMOD = 0x01
TH0 = 0x0C8 //计数14286: 20Hz = 50ms50/7*2*1000
TL0 = 0x32
EA = 1
ET0 = 1
TR0 = 1
}
void main(void)
{
InitTimer0()
P1.0 = 1
while(1)
{
if(tag==1)
{
P1.1 = ~P1.1
tag = 0
}
}
void Timer0Interrupt(void) interrupt 1
{
if(flag==0)
{
TH0 = 0x74
TL0 = 0x7E
flag = 1
}
else
{
TH0 = 0x0C8
TL0 = 0x32
flag = 0
}
tag = 1
}
#include <reg51.h>void delay(unsigned int n)
{
while(n--)
}
void main()
{
char i
//可以编好想要怎么流水的灯位的状态
unsigned char led[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}
while(1)
{
for(i=0i<8i++)
{
P1=led[i] //LED接在P1口
delay(10000)
}
for(i=0i<8i++)
{
P1=led[8-i]
delay(10000)
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)