发表于:2008/4/28 20:23:00
#0楼
这是我谢的一个51单片机的程序,选用的是at89c52,原来预想的是p2.0,2.1,2.2,2.3口同时动作,但是调试的时候总是for循环之后的那个I/O口的运动频率高,以这个程序来说就是p2.0口动作频率高,请问这是怎么回事?
#include<reg51.h>
#define uint unsigned int
sbit gate0=P2^0;
sbit gate1=P2^1;
sbit gate2=P2^2;
sbit gate3=P2^3;
void main(void)
{int i,j;
while(1)
{for(i=1000;i>0;i--)
for(j=1000;j>0;j--)
gate0=!gate0;gate1=!gate1;
gate2=!gate2;
gate3=!gate3;
};
}
以下是用keil c51调试时生成的,为什么gate0后面的与其他口不一样?
126: ?C_STARTUP: LJMP STARTUP1
127:
128: RSEG ?C_C51STARTUP
129:
130: STARTUP1:
131:
132: IF IDATALEN <> 0
C:0x0000 020027 LJMP STARTUP1(C:0027)
7: void main(void)
8: {int i,j;
9: while(1)
10: {for(i=1000;i>0;i--)
C:0x0003 7FE8 MOV R7,#0xE8
C:0x0005 7E03 MOV R6,#0x03
11: for(j=1000;j>0;j--)
C:0x0007 7DE8 MOV R5,#0xE8
C:0x0009 7C03 MOV R4,#0x03
12: gate0=!gate0;
C:0x000B B2A0 CPL gate0(0xA0.0)
C:0x000D ED MOV A,R5
C:0x000E 1D DEC R5
C:0x000F 7001 JNZ C:0012
C:0x0011 1C DEC R4
C:0x0012 ED MOV A,R5
C:0x0013 4C ORL A,R4
C:0x0014 70F5 JNZ C:000B
C:0x0016 EF MOV A,R7
C:0x0017 1F DEC R7
C:0x0018 7001 JNZ C:001B
C:0x001A 1E DEC R6
C:0x001B EF MOV A,R7
C:0x001C 4E ORL A,R6
C:0x001D 70E8 JNZ C:0007
13: gate1=!gate1;
C:0x001F B2A1 CPL gate1(0xA0.1)
14: gate2=!gate2;
C:0x0021 B2A2 CPL gate2(0xA0.2)
15: gate3=!gate3;
C:0x0023 B2A3 CPL gate3(0xA0.3)
16: };
C:0x0025 80DC SJMP main(C:0003)
133: MOV R0,#IDATALEN - 1
C:0x0027 787F MOV R0,#0x7F
134: CLR A
C:0x0029 E4 CLR A
135: IDATALOOP: MOV @R0,A
C:0x002A F6 MOV @R0,A
136: DJNZ R0,IDATALOOP
C:0x002B D8FD DJNZ R0,IDATALOOP(C:002A)
185: MOV SP,#?STACK-1
186:
#include<reg51.h>
#define uint unsigned int
sbit gate0=P2^0;
sbit gate1=P2^1;
sbit gate2=P2^2;
sbit gate3=P2^3;
void main(void)
{int i,j;
while(1)
{for(i=1000;i>0;i--)
for(j=1000;j>0;j--)
gate0=!gate0;gate1=!gate1;
gate2=!gate2;
gate3=!gate3;
};
}
以下是用keil c51调试时生成的,为什么gate0后面的与其他口不一样?
126: ?C_STARTUP: LJMP STARTUP1
127:
128: RSEG ?C_C51STARTUP
129:
130: STARTUP1:
131:
132: IF IDATALEN <> 0
C:0x0000 020027 LJMP STARTUP1(C:0027)
7: void main(void)
8: {int i,j;
9: while(1)
10: {for(i=1000;i>0;i--)
C:0x0003 7FE8 MOV R7,#0xE8
C:0x0005 7E03 MOV R6,#0x03
11: for(j=1000;j>0;j--)
C:0x0007 7DE8 MOV R5,#0xE8
C:0x0009 7C03 MOV R4,#0x03
12: gate0=!gate0;
C:0x000B B2A0 CPL gate0(0xA0.0)
C:0x000D ED MOV A,R5
C:0x000E 1D DEC R5
C:0x000F 7001 JNZ C:0012
C:0x0011 1C DEC R4
C:0x0012 ED MOV A,R5
C:0x0013 4C ORL A,R4
C:0x0014 70F5 JNZ C:000B
C:0x0016 EF MOV A,R7
C:0x0017 1F DEC R7
C:0x0018 7001 JNZ C:001B
C:0x001A 1E DEC R6
C:0x001B EF MOV A,R7
C:0x001C 4E ORL A,R6
C:0x001D 70E8 JNZ C:0007
13: gate1=!gate1;
C:0x001F B2A1 CPL gate1(0xA0.1)
14: gate2=!gate2;
C:0x0021 B2A2 CPL gate2(0xA0.2)
15: gate3=!gate3;
C:0x0023 B2A3 CPL gate3(0xA0.3)
16: };
C:0x0025 80DC SJMP main(C:0003)
133: MOV R0,#IDATALEN - 1
C:0x0027 787F MOV R0,#0x7F
134: CLR A
C:0x0029 E4 CLR A
135: IDATALOOP: MOV @R0,A
C:0x002A F6 MOV @R0,A
136: DJNZ R0,IDATALOOP
C:0x002B D8FD DJNZ R0,IDATALOOP(C:002A)
185: MOV SP,#?STACK-1
186: