问题描述
MTS-88.C和I / O板-08有8个(八)7段显示器和船上的20键垫。该显示器由7- SEG.1编号至7- SEG.8和分别连接到端口B的PB7到PB0线。上显示一个7段字符显示一个字节已被写入到端口B的MSB 4位为7段显示的地址和LSB 4位的数据。所以,如果我们写58 H至端口B,则第六届七段显示屏将显示数据8。
MTS-88.C and I/O BOARD -08 has 8 (Eight) 7-segment displays and 20 key-pads on board. The displays are numbered from 7-SEG.1 to 7-SEG.8 and are connected to Port B’s PB7 to PB0 lines respectively. To display a character on a 7-segment display a byte has to be written to port B. The MSB 4 bits are the address of the 7-segment display and LSB 4 bits are the data. So if we write 58 H to port B then the 6th 7-segment display will show data 8.
20键垫从P01到P20的编号和被布置成5列和4行。最右边的列被连接到PB0而最左边的列被连接到PB4。最上面的行连接到PA0而最下面的行连接到PA3。为了检测关键preSS,第一列必须通过写端口B.接着一个字节激活,端口A应该读。的有效值分别为行1,2,3 1,第2,第4和第8和4。
20 key-pads are numbered from P01 to P20 and are arranged in 5 columns and 4 rows. Rightmost column is connected to PB0 while leftmost column is connected to PB4. Topmost row is connected to PA0 while bottom-most row is connected to PA3. For detecting a key press, first a column must be activated by writing a byte to port B. Next, port A should be read. The valid values are 1, 2, 4 and 8 for row 1, 2, 3 and 4 respectively.
实验是读取键盘和显示pssed密钥ID的$ P $指定的7段显示器上。在这个实验中,我还没有理解大会code下面我已经展示了一些行。我做了,我不明白这些行旁边的注释。
The experiment is to read the keypad and display the pressed key id on the specified 7-segment display. In this experiment, I haven't understood some lines in the assembly code I have shown below. I have made comments beside those lines which I haven't understood.
MEMORY ADDRESS ASSEMBLY CODE
0000:0476 MOV AL,90
0000:0478 OUT 13,AL
0000:047A MOV DL,00
0000:047C MOV CX,0004H //why storing 4 here
0000:047F MOV AL,0F
0000:0481 MOV BL,CL
0000:0483 SHL BL,01 //why left shift for 4 times
0000:0485 SHL BL,01
0000:0487 SHL BL,01
0000:0489 SHL BL,01
0000:048B OR AL,BL //why doing OR operation here
0000:048D OUT 11,AL
0000:048F IN AL,10
0000:0491 MOV BL,01
0000:0493 TEST AL,BL //what is testing here
0000:0495 JE O4A7 //when we are jumping(what is the condition)
0000:0497 INC DL // what are we storing in DL
0000:0499 CMP DL,09
0000:049C JG 047A //why are we comparing DL with 9
0000:049E SHL BL,01
0000:04A0 TEST BL,10 //what is being tested here
0000:04A3 JE 0493
0000:04A5 LOOP O47F
0000:04A7 MOV AL,DL
0000:04A9 OUT 11,AL
0000:04AB PUSH CX
0000:04AC MOV CX,500
0000:04AF NOP //why is this operation needed
0000:04B0 LOOP 04AF
0000:04B2 POP CX
0000:04B3 JMP 047A
实际上被与我有上面标明?那些行做
What is actually being done with those lines I have marked above?
推荐答案
我百思不得其解显示屏和键盘如何使用端口B 我猜有一些检测低4位逻辑为 1
这将是无效的一个数字来显示,然后将其切换到键盘模式。
I am puzzled how both the display and the keyboard uses port B. I guess there is some logic which detects the low 4 bits being 1
which would be invalid for a digit to display and then it switches into keyboard mode.
TEST AL,BL //这里是什么测试
它通过测试PA0-PA3的4低位,看看哪一个设置。这是关键pressed的行号。需要注意的是 BL
曾在行被初始化为1 0491
,它是左移就行 049E
在一个循环。如此这般,通过1,2,4和8所要求
It's testing through the 4 low bits of PA0-PA3 to see which one is set. This is the row number of the key pressed. Note that BL
has been initialized to 1 at line 0491
and it is shifted left on line 049E
in a loop. So it goes through 1, 2, 4 and 8 as required.
JE O4A7 //当我们跳(条件是什么)
显然,按键使用负逻辑,那就是你会得到一个0位,如果关键是pssed $ P $。所以条件正在寻找该位0。
Apparently the keys use negative logic, that is you will get a 0 bit if a key is pressed. So the condition is looking for that 0 bit.
NOP //为什么这个操作需要
这只是一个延迟循环的一部分,使其更长的时间。
That's just part of a delay loop to make it longer.
INC DL //什么是我们存储DL
JG 047A //为什么我们比较DL 9
JG 047A //why are we comparing DL with 9
我觉得的code只适用于0-9因为那些可以重新通过一个单一的数字psented $ P $。因此, DL
是数字计数器和JG是作为终止条件。
I think the code only works for keys 0-9 because those can be represented by a single digit. So DL
is the digit counter and the JG is for the end condition.
更新:鉴于新的信息,我也可以说:
Update: given the new information, I can also say:
MOV CX,0004H //为什么存储4此处
CX
是列计数器,它是从4倒计时为0。
CX
is the column counter, it is counting down from 4 to 0.
//为什么左移
由于图显示您需要的前4位的列索引,这个做到这一点。
Since the diagram shows you need the column index in the top 4 bits, this does that.
或AL,BL //为什么这样做或操作此处
您需要输出 4F
, 3F
, 2F
, 1F
, 0F
端口B的前4位已经被设置为正确的列索引,还剩下什么是低4位设置为 1
。由于 AL
装入了 0F
,这是实现
You need to output 4F
, 3F
, 2F
, 1F
, 0F
to port B. The top 4 bits are already set to the correct column index, what's left is to set the low 4 bits to 1
. Since AL
has been loaded with 0F
, this achieves that.
的算法如下:
start:
key = 0;
for(column = 4; column != 0; column--)
{
portB = (column << 4) | 0x0f;
in = portA;
for(row = 1; row != 0x10; row <<= 1)
{
if ((in & row) == 0)
{
portB = key;
goto start;
}
if (++key == 10) goto start;
}
}
goto start;
这篇关于读一个键盘,并使用微处理器显示它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!