这是程序
#include<reg51.h>
unsigned char runner[]=
{0x02,0x06,0x04,0x0C,0x08,0x09,0x01,0x03};
bit open=0,close=0;
void delay(unsigned int time);
key()interrupt 0{
switch(P0&0x0f){
case 0x0e:open=1;break;
case 0x0d:close=1;break;
case 0x0b:open=0,close=0;break;
}}
key1()interrupt 1{
switch(P0&0x0f){
case 0x07:open=1;break;
case 0x0f:close=1;break;
}}
void delay(unsigned int time){
unsigned int j=0;
for(;time>0;time--)
for(j=0;j<125;j++);
}
void main(){
int i;
IT0=1;EX0=1;EA=1;
while(1){
if(open)
if(!close)
for(i=0;i<=7;i++)
{P2=runner[i];
delay(200);
}
else if(close)
if(!open)
for(i=7;i>=0;i--)
{P2=runner[i];
delay(200);
}
else P2=0xff;
}}
|