图4.3.2
6.方法一(汇编源程序)
ORG 00H
START: MOV A,P1
ANL A,#0F0H
RR A
RR A
RR A
RR A
XOR A,#0F0H
MOV P1,A
SJMP START
END
7.方法一(C语言源程序)
#include
unsigned char temp;
void main(void)
{
while(1)
{
temp=P1>>4;
temp=temp | 0xf0;
P1=temp;
}
}
8.方法二(汇编源程序)
ORG 00H
START: JB P1.4,NEXT1
CLR P1.0
SJMP NEX1
NEXT1: SETB P1.0
NEX1: JB P1.5,NEXT2
CLR P1.1
SJMP NEX2
NEXT2: SETB P1.1
NEX2: JB P1.6,NEXT3
CLR P1.2
SJMP NEX3
NEXT3: SETB P1.2
NEX3: JB P1.7,NEXT4
CLR P1.3
SJMP NEX4
NEXT4: SETB P1.3
NEX4: SJMP START
END
9.方法二(C语言源程序)
#include
void main(void)
{
while(1)
{
if(P1_4==0)
{
P1_0=0;
}
else
{
P1_0=1;
}
if(P1_5==0)
{
P1_1=0;
}
else
{
P1_1=1;
}
if(P1_6==0)
{
P1_2=0;
}
else
{
P1_2=1;
}
if(P1_7==0)
{
P1_3=0;
}
else
{
P1_3=1;
}
}
}