其对应的C使用如下:
#include
sbit p20=P2^0;
sbit p21=P2^1;
sbit p22=P2^2;
sbit p23=P2^3;
void delay(unsigned int z)
{
while(z–);
}
void main()
{
P2=0x00;
while(1)
{
p20=1;
P0=0XA4;
delay(500);
p20=0;
p21=1;
P0=0XC0;
delay(500);
p21=0;
p22=1;
P0=0XF9;
delay(500);
p22=0;
p23=1;
P0=0XA4;
delay(500);
p23=0;
}
}
sbit p20=P2^0;
sbit p21=P2^1;
sbit p22=P2^2;
sbit p23=P2^3;
void delay(unsigned int z)
{
while(z–);
}
void main()
{
P2=0x00;
while(1)
{
p20=1;
P0=0XA4;
delay(500);
p20=0;
p21=1;
P0=0XC0;
delay(500);
p21=0;
p22=1;
P0=0XF9;
delay(500);
p22=0;
p23=1;
P0=0XA4;
delay(500);
p23=0;
}
}
其对应的汇编语言如下:
ORG 0000H
MOV P2,#00H
LOOP:SETB P2.0
MOV P0,#0XA4
ACALL DELAY
CLR P2.0
SETB P2.1
MOV P0,#0XC0
ACALL DELAY
CLR P2.1
SETB P2.2
MOV P0,#0XF9
ACALL DELAY
CLR P2.2
SETB P2.3
MOV P0,#0XA4
ACALL DELAY
CLR P2.3
AJMP LOOP
DELAY:MOV R7,#255
DJNZ R7,$
RET
END
MOV P2,#00H
LOOP:SETB P2.0
MOV P0,#0XA4
ACALL DELAY
CLR P2.0
SETB P2.1
MOV P0,#0XC0
ACALL DELAY
CLR P2.1
SETB P2.2
MOV P0,#0XF9
ACALL DELAY
CLR P2.2
SETB P2.3
MOV P0,#0XA4
ACALL DELAY
CLR P2.3
AJMP LOOP
DELAY:MOV R7,#255
DJNZ R7,$
RET
END