The independent button type directly uses the I/O line to form a single button circuit. Its characteristic type each button occupies an I/O line, and the operation of each button does not affect the status of other I/O lines. The independent button circuit has flexible configuration and simple software structure, but each button must occupy one I/O port line. Therefore, when there are many buttons, the I/O port line is wasted and should not be used.
Independent button software often uses a query structure. Firstly, the input status of the I/O line is not checked with the bit. If the input of a certain I/O line is low, it can be confirmed that the corresponding button of the I/O line has been pressed, and then Turn to the function handler for this key.
The ideal waveform of a separate keyboard is held low when pressed down, and actually jitter occurs during the rising and falling edges (ie, a small amount of time when the button is pressed and the key is off). There are two ways to debounce, one is through hardware: a capacitor on the circuit; the other is software debounce, adding 10ms delay based on experience.
program:
006.asm
Read the button on the independent keyboard and light the corresponding LED. If there is no button for a while, just cycle the LED.
Wiring: P0 port is connected to eight LEDs
P2 port with eight independent buttons
Timer T0 timing, interrupt mode
************************************************** *************************/
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP INT_T0
ORG 0100H
MAIN: ; main program entry
MOV SP, #50H; set stack
MOV TMOD, #01H ; Set the timing mode
MOV TH0, #15H ;
MOV TL0, #9FH
CLR 20H.0 ; initialization button flag
MOV R2, #0FFH ; Initialization key value
MOV R3, #01H ; Initialize the initial flashing value
MOV R4, #00H ; Initialization timing initial value
SETB TR0; start timer
MOV IE, #82H; open interrupt
LOOP:
LCALL KEY_READ; scan keyboard
L1: JB 20H.0, LIGH; with key input, it will light the corresponding LED
JBC 20H.0, LOOP
MOV A, R4
CJNE A, #0C8H, LOOP; otherwise it is judged whether the timing is up, and the timing is up, the LED is illuminated in eight steps.
LCALL LEED
LJMP L1
/*Lights the corresponding LED*/
LIGH:
MOV A, R2; take the key value
MOV P0, A ; output
RET
/* Cycle lights LED*/
LEED:
MOV A, R3
LOOP1:
CPL A
MOV P0, A
LCALL KEY_READ
JB 20H.0, RETUN0
MOV R0, #0FFH
LCALL DELAY
MOV A, R3
RL A
MOV R3, A
CJNE A, #80H, LOOP1
LOOP2:
CPL A
MOV P0, A
LCALL KEY_READ
JB 20H.0, RETUN0
MOV R0, #0FFH
LCALL DELAY
MOV A, R3
RR A
MOV R3, A
CJNE A, #01H, LOOP2
SJMP LOOP1
RETUN0:
RET
/*Keyboard Scanner*/
KEY_READ:
CLR EA; off timing interrupt when scanning the keyboard
MOV A, P2
CJNE A, #0FFH, DE
LJMP RETUN
DE: MOV R0, #8AH
LCALL DELAY
MOV A, P2
CJNE A, #0FFH, DE0
LJMP RETUN
DE0: MOV R2, A
SETB 20H.0
MOV R4, #00H
DE1: MOV A, P2
CJNE A, #0FFH, DE1
RETUN:
SETB EA
RET
/* interrupt subroutine*/
INT_T0:
CLR EA
PUSH ACC
MOV TH0, #15H ; re-timed initial value
MOV TL0, #9FH
INC R4
POP ACC
SETB EA
RETI
/* Delay subroutine*/
DELAY:
D1: MOV R1, #0FFH
D0: DJNZ R1, D0
DJNZ R0, D1
RET
China leading manufacturers and suppliers of DC Support Capacitors,DC Capacitor, and we are specialize in Electrolytic capacitor,High Voltage Capacitor, etc.DCMJ DC Support Capacitors
DCMJ DC Support Capacitors,Capacitors High Voltage,Dc-link Filter Capacitor,Dc Film Capacitors
YANGZHOU POSITIONING TECH CO., LTD. , https://www.pst-thyristor.com