4707 views|0 replies

1379

Posts

0

Resources
The OP
 

One-touch multi-function button recognition technology [Copy link]

1. Experimental tasks

As shown in the previous test schematic, switch SP1 is connected to the P3.7/RD pin, and four LEDs are connected to the P1 port of the AT89S51 microcontroller. When the power is on, the LED connected to the P1.0 pin of L1 is flashing. Every time the switch SP1 is pressed, the LED connected to the P1.1 pin of L2 is flashing. When the switch SP1 is pressed again, the LED connected to the P1.2 pin of L3 is flashing. When the switch SP1 is pressed again, the LED connected to the P1.3 pin of L4 is flashing. When the switch SP1 is pressed again, it is the turn of L1 to flash, and so on.

2. Circuit diagram

Same as the previous test schematic

3. Hardware connection on the system board

Same setup as the previous test

4. Programming methods

(1. Origin of design idea
In our daily life, we can easily tell that this one is Zhang San, that one is Li Si, and the other one is Wang Wu; that is because everyone has a different name, so we can recognize them quickly. Similarly, for each different function to be identified by a button, we use a different ID number to identify each different functional module. In this way, the value of the ID is different every time the button is pressed, so the microcontroller can easily identify the identity of different functions.
(2. Design method
From the above requirements, we can see that the flashing time of the light-emitting diodes L1 to L4 at each moment is controlled by the switch SP1. We define different ID numbers for the flashing time periods of L1 to L4. When L1 is flashing, ID = 0; when L2 is flashing, ID = 1; when L3 is flashing, ID = 2; when L4 is flashing, ID = 3; obviously, as long as different ID numbers are given each time the switch K1 is pressed, we can complete the above task. The following is a block diagram of the program design.

5. Flowchart

 

6. Assembly source program
ID EQU 30H
SP1 BIT P3.7
L1 BIT P1.0
L2 BIT P1.1
L3 BIT P1.2
L4 BIT P1.3
ORG 0
MOV ID,#00H
START: JB K1,REL
LCALL DELAY10MS
JB K1,REL
INC ID
MOV A,ID
CJNE A,#04,REL
MOV ID,#00H
REL: JNB K 1,$
MOV A,ID
CJNE A,#00H,IS0
CPL L1
LCALL DELAY
SJMP START
IS0: CJNE A,#01H,IS1
CPL L2
LCALL DELAY
SJMP START IS1: CJNE
A,#02H,IS2
CPL L3
LCALL DELAY
SJMP START
IS2: CJNE A,#03H,IS3
CPL L4
LCALL DELAY
SJMP START
IS3: LJMP START
DELAY10MS: MOV R6,#20
LOOP1: MOV R7,#248
DJNZ R7,$
DJNZ R6,LOOP1
RET
DELAY: MOV R5,#20
LOOP2: LCALL DELAY10MS
DJNZ R5,LOOP2
RET
END

This post is from MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list