WOSEN LIGHTING TECHNOLOGY LIMITED

WOSEN LIGHTING TECHNOLOGY LIMITED

Home> Blog> Independent key illuminates LED light program design

Independent key illuminates LED light program design

March 03, 2023

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

Contact Us

Author:

Ms. Mandy

Phone/WhatsApp:

+8613425434349

Popular Products
You may also like
Related Information
LEAD sincerely released the LED high bay light famous for

On April 22, network activity named "FAST 2015 -! OPEN DAY" was launched by a brand LED high-power outdoor lighting manufacturer- Shenzhen Lead Optoelectronics Technology Co., Ltd.(Chinese name is...

Hublot watch brand ambassadors worldwide "Lightning" Bolt light the light of hope The new Kyoto store interpretation of the fusion of culture

Recently, the world's leading watch brand Hublot and brand ambassador, legendary track and field athlete Usain Bolt hand in hand into Kyoto, the ancient capital of Japan, with passion to ignite...

Cree Introduces XLamp MK-R LED Light Efficiency up to 200lm/W

After two years of breakthrough in the laboratory's light efficiency of 200 lm/W, Cree has finally produced the series of LED chips with 200 lumens per watt at the end of 2012, and officially...

Related Categories

Email to this supplier

Subject:
Email:
Message:

Your message must be betwwen 20-8000 characters

  • Send Inquiry

Copyright © 2024 WOSEN LIGHTING TECHNOLOGY LIMITED All rights reserved. Privacy Policy

We will contact you immediately

Fill in more information so that we can get in touch with you faster

Privacy statement: Your privacy is very important to Us. Our company promises not to disclose your personal information to any external company with out your explicit permission.

Send