/*(分享设计)*/
#include <STC89C5xRC.h>
/*这是一个STC89C51单片机流水灯程序*/
sbit led0=P2^0;
sbit led1=P2^1;
sbit led2=P2^2;
sbit led3=P2^3;
sbit led4=P2^4;
sbit led5=P2^5;
sbit led6=P2^6;
sbit led7=P2^7; /*以上代码把IO口寄存器指针定义成变量*/
delay() /* 这里是控制变灯延迟的程序*/
{
unsigned int i,j;
i=j=0;
for(i=0;i<=1000;i++)
{
for(j=0;j<200;j++);
}
}
void main() /*开始真正的表演了*/
{
led0=led1=led2=led3=led4=led5=led6=led7=0;/*指向寄存器变量置零,注意2051单片机是八进制机,没有8和9*/
while(1)
{
led7=0;
led0=1;
delay();
led0=0;
led1=1;
delay();
led1=0;
led2=1;
delay();
led2=0;
led3=1;
delay();
led3=0;
led4=1;
delay();
led4=0;
led5=1;
delay();
led5=0;
led6=1;
delay();
led6=0;
led7=1;
delay();
}
}
|