Experiment 9: keyboard scanning and nixie tube display experiment
1. Experimental purpose
-
Learn the basic principles of keyboard scanning.
-
Master the method of scanning the keyboard through parallel interface chip and displaying numbers in multi digit nixie tube.
2. Experimental content
Write a program to realize the following functions: there is no display of nixie tube at the beginning; When the keyboard is pressed for the first time, the corresponding hexadecimal number is displayed on the rightmost nixie tube; After each press of the keyboard, all the currently displayed numbers will be moved to the left by one digit (the leftmost number will be moved out of the nixie tube), and the number just typed will be displayed on the rightmost side of the nixie tube.
3. Experimental principle
For the circuit of keyboard and nixie tube, please refer to figure 3-8-1 in Experiment 8. The numbers corresponding to the keyboard are 0 ~ 9 and A ~ F from left to right and from top to bottom. Bit code interface (X1 ~ X6) not only can select to light a specific nixie tube, but also serves as the column scanning interface of 4x4 keyboard. Therefore, the parallel interface chip 8255 needs to be used in the experiment, taking into account keyboard scanning and nixie tube display control.
4. Experimental records
- Keyboard scanning: here, you can observe the signal change when the key is pressed and not pressed through the method of X port output signal and Y port input signal, judge and obtain the information of the pressed key among the 16 keys. It should be noted that the X port is still used as the bit selection signal output port of the nixie tube, which may lead to the abnormal use of the nixie tube. Therefore, it is necessary to output the correct segment selection signal to the nixie tube at the same time to reduce unnecessary additional phenomena.
- Key mutual exclusion: according to the experimental requirements: [event] press the key, the [action] nixie tube moves all numbers to the left, and the latest number is displayed at the right end. Because the key pressing generates not an instantaneous signal, but a continuous signal, which will cycle trigger events and lead to the repeated execution of "action", it is necessary to add a mutually exclusive operation when the key is pressed. Before the key pops up, the pressing of other keys will temporarily lose the effect.
- Address offset: the data in Data Segment is stored in memory space according to continuous addresses, so the offset address of one variable can be used to index other variables.
A8255 EQU 0640H ;8255 of IOY The wiring addresses are A,B,C Port and control port B8255 EQU 0642H C8255 EQU 0644H M8255 EQU 0646H DATA SEGMENT TAB: ;TAB Table for recording 0 ~ F Segment selection DB 3FH,06H,5BH,4FH DB 66H,6DH,7DH,07H DB 7FH,6FH,77H,7CH DB 39H,5EH,79H,71H T1 DB 00H ;Ti The table is used to record the segment selection codes of 6 nixie tubes T2 DB 00H T3 DB 00H T4 DB 00H T5 DB 00H T6 DB 00H FLAG DB 00H ;FLAG Variables are used for mutually exclusive operations DATA ENDS
CODE SEGMENT ASSUME CS:CODE,DS:DATA START: MOV AX,DATA ;Import DATA MOV DS,AX MOV AX,00H ;register A Clear LEA BX,TAB ;record TAB Table header address MOV DX,M8255 ;Set 8255 to A,B Port output, C Port input MOV AL,81H OUT DX,AL MAIN: MOV AL,11110111B ;Columns to be scanned, output 0 MOV CX,04H ;A total of 4 columns need to be scanned M1: MOV DX,A8255 OUT DX,AL ;from X Port output train selection signal SHR AL,1 ;Shift right one bit OR AL,11110000B PUSH AX ;Save column selection signal PUSH CX ;Save cycle count MOV DX,C8255 IN AL,DX ;from Y Port input keyboard feedback signal AND AL,0FH ;Y Port 8255 C The lower four bits of the port remove redundant information CMP AL,0FH ;If the lower four digits are 1111, it indicates that no key is pressed JE M2 CALL SHOW ;Didn't jump M2,It indicates that a key is pressed JMP M3 ;Skip if a key is pressed M2(Mutex count) stage M2: CMP FLAG,00H ;Maintain mutually exclusive signals, FLAG=MAX(0,FLAG-1) JE M3 ;FLAG=0 It means that no key is pressed in the four columns, FLAG The initial value is 4 DEC FLAG ;When each column is scanned and no key is pressed, FLAG Self subtraction once M3: CALL CLEAR ;Display the contents of nixie tube POP CX ;Take out the cycle count first POP AX ;Then take out the column selection signal CALL DELAY ;Slightly delayed LOOP M1 JMP MAIN SHOW: NOT AL ;NOT Reverse (from here, through) Y Input information at the port to judge the pressed key) AND AX,0FH ;AND Take the lower 4 digits (see "about key judgment" in point 4 below for details) CMP AL,01H ;0001 JE D1 CMP AL,02H ;0010 JE D2 CMP AL,04H ;0100 JE D3 CMP AL,08H ;1000 JE D4 D1: MOV AL,04H JMP D5 D2: MOV AL,08H JMP D5 D3: MOV AL,0CH JMP D5 D4: MOV AL,10H JMP D5 D5: ADD AL,CL SUB AL,05H MOV SI,AX ;Here, the pressed key is converted into a unique index value CMP FLAG,00H ;Whether there is mutual exclusion. Non-0 means there is mutual exclusion JNE DFI LEA BX,TAB ;hold TAB First address of BX MOV AL,T5 ;take T5 Put the value of T6 MOV T6,AL MOV AL,T4 ;take T4 Put the value of T5 MOV T5,AL MOV AL,T3 ;take T3 Put the value of T4 MOV T4,AL MOV AL,T2 ;take T2 Put the value of T3 MOV T3,AL MOV AL,T1 ;take T1 Put the value of T2 MOV T2,AL MOV AX,[BX+SI] ;Put the key index value into T1 MOV T1,AL ;T1 It's the right most nixie tube CALL DELAY DFI: MOV FLAG,04H ;FLAG Initial value setting RET CLEAR: LEA BX,T1 ;with T1 First address, index T2~T6 MOV AL,11011111B MOV SI,00H MOV CX,06H ;Nixie tube display, the same as experiment 8 MC2: MOV DX,A8255 OUT DX,AL SHR AL,1 OR AL,11000000B PUSH AX ;preservation AX Value of MOV DX,B8255 MOV AL,[BX+SI] OUT DX,AL POP AX ;take out AX Value of INC SI ;Address offset auto increment CALL DELAY LOOP MC2 RET DELAY: PUSH BX MOV BX, 03FFH DEL: DEC BX JNZ DEL POP BX RET CODE ENDS END START
- About key judgment: briefly explain the logic. The information input from port Y is stored in the AL register. If the lower 4 bits are 1111, it means that there is no key pressed, otherwise 0 means that there is a key pressed at this position; CL register stores the cycle count of keyboard column scanning, counting 4 times from 04H to 01H. For example, when CL counts to m and the nth bit of the lower 4 bits of AL appears 0, it is judged that a key is pressed, and its position information is about 5-m columns and N rows. Then, through many experiments and logical sorting, write conditional branch statements that can convert the relevant information of M and n into the index value of 0 ~ F. (due to different operations such as wiring, the conditional branch statements of bloggers are for reference only)
5. Extended experiment
No, no code