#include<reg51.h>
char led[]={0x01,0x02,0x04,0x08};
void delay(unsigned int
time){
unsigned int j = 0;
for(;time>0;time--)
for(j=0;j<125;j++);
}
char key(); //按键处理(汇编),在.asm文件中
void main(){
bit dir=0,run=0;
char i;
while(1){
switch (key()){
case 0x0e:run=1;break;
case 0x0d:run=0;break;
case 0x0b:dir=1;break;
case 0x07:dir=0;break;
}
if (run)
if(dir) //自上而下流动
for(i=0;i<=3;i++){
P2=led[i];
delay(200);
}
else //自下而上流动
for(i=4;i>=1;i--){
P2=led[i - 1];
delay(200);
}
else P2=0; //灯全灭
}
}
#pragma ASM
PUBLIC KEY
DE SEGMENT CODE
RSEG DE
KEY: MOV A,P0
ANL A,#0FH
MOV B,A
CJNE A,#0FH,KEYOUT
MOV R7,#0
KEYOUT: MOV R7,B
RET
END
#pragma ASM
一周热门 更多>