本帖最后由 airwill 于 2014-3-26 06:53 编辑
我已经不用 51 好多年, 不过也没有关系, 找Keil C51 编译一下,
这段是用 unsigned char 生成的代码.
; FUNCTION main (BEGIN)
; SOURCE LINE # 4
; SOURCE LINE # 5
; SOURCE LINE # 6
0000 758920 MOV TMOD,#020H
; SOURCE LINE # 7
0003 758DFD MOV TH1,#0FDH
; SOURCE LINE # 8
0006 758BFD MOV TL1,#0FDH
; SOURCE LINE # 9
0009 D2AB SETB ET1
; SOURCE LINE # 10
000B D28E SETB TR1
; SOURCE LINE # 11
000D D29C SETB REN
; SOURCE LINE # 12
000F C29F CLR SM0
; SOURCE LINE # 13
0011 D29E SETB SM1
; SOURCE LINE # 14
0013 D2AF SETB EA
; SOURCE LINE # 15
0015 D2AC SETB ES
0017 ?C0001:
; SOURCE LINE # 16
; SOURCE LINE # 17
; SOURCE LINE # 18
0017 E500 R MOV A,flag
0019 B401FB CJNE A,#01H,?C0001
; SOURCE LINE # 19
; SOURCE LINE # 20
001C E4 CLR A
001D F500 R MOV flag,A
; SOURCE LINE # 21
001F 850099 R MOV SBUF,a
; SOURCE LINE # 22
0022 C299 CLR TI
; SOURCE LINE # 23
; SOURCE LINE # 24
0024 80F1 SJMP ?C0001
; FUNCTION main (END)
; FUNCTION ser (BEGIN)
; SOURCE LINE # 26
; SOURCE LINE # 28
0000 C298 CLR RI
; SOURCE LINE # 29
0002 859990 MOV P1,SBUF
; SOURCE LINE # 30
0005 750001 R MOV flag,#01H
; SOURCE LINE # 31
0008 859900 R MOV a,SBUF
; SOURCE LINE # 32
000B 32 RETI
; FUNCTION ser (END)
这段是用 unsigned int 生成的代码.
; FUNCTION main (BEGIN)
; SOURCE LINE # 5
; SOURCE LINE # 6
; SOURCE LINE # 7
0000 758920 MOV TMOD,#020H
; SOURCE LINE # 8
0003 758DFD MOV TH1,#0FDH
; SOURCE LINE # 9
0006 758BFD MOV TL1,#0FDH
; SOURCE LINE # 10
0009 D2AB SETB ET1
; SOURCE LINE # 11
000B D28E SETB TR1
; SOURCE LINE # 12
000D D29C SETB REN
; SOURCE LINE # 13
000F C29F CLR SM0
; SOURCE LINE # 14
0011 D29E SETB SM1
; SOURCE LINE # 15
0013 D2AF SETB EA
; SOURCE LINE # 16
0015 D2AC SETB ES
0017 ?C0001:
; SOURCE LINE # 17
; SOURCE LINE # 18
; SOURCE LINE # 19
0017 E500 R MOV A,flag+01H
0019 6401 XRL A,#01H
001B 4500 R ORL A,flag
001D 70F8 JNZ ?C0001
; SOURCE LINE # 20
; SOURCE LINE # 21
001F F500 R MOV flag,A
0021 F500 R MOV flag+01H,A
; SOURCE LINE # 22
0023 850099 R MOV SBUF,a
; SOURCE LINE # 23
0026 C299 CLR TI
; SOURCE LINE # 24
; SOURCE LINE # 25
0028 80ED SJMP ?C0001
; FUNCTION main (END)
; FUNCTION ser (BEGIN)
; SOURCE LINE # 27
; SOURCE LINE # 29
0000 C298 CLR RI
; SOURCE LINE # 30
0002 859990 MOV P1,SBUF
; SOURCE LINE # 31
0005 750000 R MOV flag,#00H
0008 750001 R MOV flag+01H,#01H
; SOURCE LINE # 32
000B 859900 R MOV a,SBUF
; SOURCE LINE # 33
000E 32 RETI
; FUNCTION ser (END)
我看没有问题. 看看你的代码和编译器的结果
另外,是不是你在中断里两次读 SBUF 引起的问题
|