單片機(jī)流水燈三個(gè)點(diǎn)亮方向
二、縱向點(diǎn)亮(點(diǎn)亮次序由P0.0~P1.0~P2.0~P3.0再到P0.1~P1.1以此類推)
include reg52.h //此處使用的為89S52的芯片
void delay(unsigned int second)
{
unsigned int i,j; //定義為unsigned防止負(fù)數(shù),習(xí)慣問(wèn)題
for(i=0;isecond;i++)
{
for(j=0;j200000;j++);
}
}
void main(void)
{
unsigned i;
while(1)
{
for(i=0;i8;i++)
{
P0=0x01i;
delay(100);
P0=0;
P1=0x01i;
delay(100);
P1=0;
P2=0x01i;
delay(100);
P2=0;
P3=0x01i;
delay(100);
P3=0:
}
}
}
評(píng)論