51 MCU matrix keyboard driver implementation

Publisher:oplkjjjLatest update time:2020-02-04 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Use this matrix keyboard as microcontroller input, plug it into P1.0~P1.6 of P1 port.

I want to ask, when:

When key 1 is pressed, P0.0 of P0 port outputs high level;

Press the 2 key and P0.1 outputs high level;

Just go up to the 8 key.

There is also a requirement that when a key is pressed, the delay is 5 seconds and other keys are locked, and then the program returns to the starting point after 5 seconds.

;=====================================================

; As follows:

ORG 0000H

START:

MOV P0, #255

MOV P1, #255

CLR P1.0

NOP  

JNB P1.4, K1

JNB P1.5, K2

JNB P1.6, K3

MOV P1, #255

CLR P1.1

NOP  

JNB P1.4, K4

JNB P1.5, K5

JNB P1.6, K6

MOV P1, #255

CLR P1.2

NOP  

JNB P1.4, K7

JNB P1.5, K8

; JNB P1.6, K9

SJMP START

K1: CLR P0.0

SJMP DELAY

K2: CLR P0.1

SJMP DELAY

K3: CLR P0.2

SJMP DELAY

K4: CLR P0.3

SJMP DELAY

K5: CLR P0.4

SJMP DELAY

K6: CLR P0.5

SJMP DELAY

K7: CLR P0.6

SJMP DELAY

K8: CLR P0.7

DELAY:

MOV R5, #10

DJNZ R7, $

DJNZ R6, $ - 2

DJNZ R5, $ - 4

LJMP START

END

If you need to control the output of high level by key, change all CLR in the above program to SETB.

Then: MOV P0, #255

Change to: MOV P0, #0

Reference address:51 MCU matrix keyboard driver implementation

Previous article:51 MCU interrupt architecture_interrupt response process
Next article:Discussion on Controlling AD9854 with 16-bit Single Chip Microcomputer

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号