我正在学习 8051 汇编编程。我在我的书中读到“为了使端口成为输入端口,端口必须通过将 1 写入其所有位来进行编程。” 但这不是错的吗?
如果我将所有位设置为 1,并想在输入1010
时输入,我将按下连接到第 2 引脚和第 4 引脚的按钮以输入 1010,但端口将读取所有 1。我在 Keil uVision Simulation 上试过,发现了这个问题。
这是一个问题还是我误解了它?
org 00h
Reset:
mov P0,#00h
mov P1,#00h
mov P2,#00h
mov P3,#00h
TakeInput:
jb P2.0,Addition// in assembler simulation, this condition is true if I set P2 to #0ffh, which is not required. The user should set this bit for making this condition true
sjmp TakeInput
Addition:
移动 A,P0 添加 A,P1
mov P3,A
acall Delay
ajmp Reset
Delay:
mov R0,#1
here:
mov R1,#1
again:
djnz R1,again
djnz R0,here
ret
end
如果我不将所有端口重置为 0,则默认情况下依赖于端口值的跳转指令变为 true。