我这个是8 个流水灯的,汇编的。除了你要的2 种花样外,还有另2 种花样。你可以参考
;4花样流水灯 2010.05.11
AN EQU P3.0
ORG 0000H
AJMP MAIN
ORG 0003H
AJMP EX0INT
ORG 0030H
MAIN: SETB EA
SETB EX0
SETB IT0
ACALL DISP
AJMP MAIN
EX0INT: INC R0
CJNE R0,#5,RTI
MOV R0,#1
RTI: RETI
DISP: MOV R1,#8
LED1: CJNE R0,#1,LED2
AJMP LED10
LED2: CJNE R0,#2,LED3
AJMP LED20
LED3: CJNE R0,#3,LED4
AJMP LED30
LED4: CJNE R0,#4,LEDRT
AJMP LED40
LEDRT: RET
LED10: MOV A,#0FFH
MOV P1,A
ACALL DLY200
MOV A,#0FEH
LED101: MOV P1,A
ACALL DLY200
RL A
DJNZ R1,LED101
AJMP DISP
LED20: ;MOV R1,#8
MOV A,#0FFH
MOV P1,A
ACALL DLY200
MOV A,#7FH
LED201: MOV P1,A
ACALL DLY200
RR A
DJNZ R1,LED201
AJMP DISP
LED30: MOV DPTR,#TAB
MOV A,R1
DEC A
LED301: MOVC A,@A+DPTR
MOV P1,A
LCALL DLY200
MOV A,R1
DJNZ R1,LED301
AJMP DISP
LED40: MOV DPTR,#TAB
MOV A,R1
DEC A
LED401: MOVC A,@A+DPTR
CPL A
MOV P1,A
LCALL DLY200
MOV A,R1
DJNZ R1,LED401
AJMP DISP
DLY200: ;延时200ms
MOV R4,#04H
DL01:
MOV R3,#74H
DL00:
MOV R2,#0D6H
DJNZ R2,$
DJNZ R3,DL00
DJNZ R4,DL01
NOP
RET
TAB: DB 00000000B
DB 00011000B
DB 00111100B
DB 01111110B
DB 11111111B
DB 01111110B
DB 00111100B
DB 00011000B
END
太简单了,从网上一搜一大把
以下程序是经过验证的放心使用
#include
#define uint unsigned int
sbit s1=P2^0;
int m;
void delay(uint z);
void main()
{
m=0;
while(1)
{
if(s1==0)
{
delay(5);
if(s1==0)
{
m++;
if(m==3)
m=1;
if(m==1)
{
P0=0xfe;
delay(500);
P0=0xfd;
delay(500);
P0=0xfb;
delay(500);
P0=0xf7;
delay(500);
}
if(m==2)
{
P0=0xf7;
delay(500);
P0=0xfb;
delay(500);
P0=0xfd;
delay(500);
P0=0xfe;
delay(500);
}
}
}
}
}
void delay(uint z)
{
int x,y;
for(x=110;x>0;x--)
for(y=z;y>0;y--);
}