Reading matrix keyboard based on single chip, using corresponding key value

Publisher:jiaohe1Latest update time:2012-09-24 Source: 21ic Keywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/*****************************************************
007.ASM

Wiring: P0 port connects to digital tube,
P2 port connects to matrix keyboard
Use timer interrupt, if there is no operation for a period of time, the digital tube will enter the self-circulation display
2010.09.05
**********************************************************/
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP INT_T0
ORG 0020H
MAIN: ; Main program
MOV SP,#50H
MOV DPTR,#LED_DATA ; Get the first address of the table
MOV TMOD,#01H ; Set the working mode of timer T0
MOV TH0,#15H ; Write the initial value of timing
MOV TL0,#9FH
MOV P2,#0FFH ; Assign the initial value of P2 port
MOV R4,#00H ; Assign the initial value of timing count
SETB 00H ; 00H is the key value change flag
SETB TR0 ; Start timer T0
MOV IE,#82H ; Open interrupt
LCALL SHOW ;Digital tube initialization
loop: ;Main loop
LCALL KEY_READ ;Read keyboard
JBC 00H, LOOP0 ;Judge whether any key is pressed, if yes, refresh output and clear timing count
CJNE R4, #0C8H, LOOP ;If no key is pressed, judge whether the timing time is reached, if yes, enter digital tube loop output
LCALL SHOW1 ;If not, return to the main loop and rescan keyboard
SJMP LOOP
LOOP0:
LCALL SHOW
MOV R4, #00H
SJMP LOOP ;Output refresh completed, return to the main loop and rescan keyboard

/*键盘扫描程序*/
KEY_READ:
CLR P2.6    ;P2.6输出低
JB P2.0,N0_0
MOV R0,#01H
LCALL DELAY
JB P2.0,N0_0
JNB P2.0,$
MOV R5,#04H
SETB 00H
SETB P2.6
LJMP NEAT
N0_0:
JB P2.1,N0_1
MOV R0,#01H
LCALL DELAY
JB P2.1,N0_1
MOV R5,#03H
JNB P2.1,$
SETB 00H
SETB P2.6
LJMP NEAT
N0_1:
JB P2.2,N0_2
MOV R0,#01H
LCALL DELAY
JB P2.2,N0_2
JNB P2.2,$
MOV R5,#02H
SETB 00H
SETB P2.6
LJMP NEAT
N0_2:
JB P2.3,N1_0
MOV R0,#01H
LCALL DELAY
JB P2.3,N1_0
JNB P2.3,$
MOV R5,#01H
SETB 00H
SETB P2.6
LJMP NEAT
N1_0:
SETB P2.6
CLR P2.5
JB P2.0,N1_1
MOV R0,#01H
LCALL DELAY
JB P2.0,N1_1
JNB P2.0,$
MOV R5,#08H
SETB 00H
SETB P2.5
LJMP NEAT
N1_1:
JB P2.1,N1_2
MOV R0,#01H
LCALL DELAY
JB P2.1,N1_2
JNB P2.1,$
MOV R5,#07H
SETB 00H
SETB P2.5
LJMP NEAT
N1_2:
JB P2.2,N1_3
MOV R0,#01H
LCALL DELAY
JB P2.2,N1_3
JNB P2.2,$
MOV R5,#06H
SETB 00H
SETB P2.5
LJMP NEAT
N1_3:
JB P2.3,N2_0
MOV R0,#01H
LCALL DELAY
JB P2.3,N2_0
JNB P2.3,$
MOV R5,#05H
SETB 00H
SETB P2.5
LJMP NEAT
N2_0:
SETB P2.5
CLR P2.4
JB P2.0,N2_1
MOV R0,#01H
LCALL DELAY
JB P2.0,N2_1
JNB P2.0,$
MOV R5,#0CH
SETB 00H
SETB P2.4
LJMP NEAT
N2_1:
JB P2.1,N2_2
MOV R0,#01H
LCALL DELAY
JB P2.1,N2_2
JNB P2.1,$
MOV R5,#0BH
SETB 00H
SETB P2.4
LJMP NEAT
N2_2:
JB P2.2,N2_3
MOV R0,#01H
LCALL DELAY
JB P2.2,N2_3
JNB P2.2,$
MOV R5,#0AH
SETB 00H
SETB P2.4
LJMP NEAT
N2_3:
JB P2.3,NEAT
MOV R0,#01H
LCALL DELAY
JB P2.3,NEAT
JNB P2.3,$
MOV R5,#09H
SETB 00H
SETB P2.4
LJMP NEAT
NEAT:
SETB P2.4
RET

/*Display subroutine*/
SHOW:
MOV A,R5
MOVC A,@A+DPTR
MOV P0,A
RET

/*Loop display subroutine*/

SHOW1:      ;
MOV R3,#00H
LOOP1:
MOV A,R3
MOVC A,@A+DPTR
MOV P0,A
MOV R0,#35H
LCALL DELAY
INC R3
LCALL KEY_READ
JB 00H,RETUN1
CJNE R3,#10H,LOOP1
MOV R3,#00H
SJMP LOOP1
RETUN1:
RET

/*Delay subroutine*/

DELAY:
D0: MOV R2,#0FH
D1: MOV R1,#0BFH
D2: DJNZ R1,D2
DJNZ R2,D1
DJNZ R0,D0
RET

/*Timer interrupt T0 processing subroutine*/


INT_T0:
CLR EA
PUSH ACC
INC R4
MOV TH0,#15H
MOV TL0,#9FH
POP ACC
SETB EA
RETI

/*Digital tube display code, 0~F*/

LED_DATA:
DB 03H,9FH,25H,0DH,99H,49H,41H,1FH
DB 01H,09H,11H,0C1H,63H,85H,61H,71H

END

Keywords:MCU Reference address:Reading matrix keyboard based on single chip, using corresponding key value

Previous article:Design of electronic speed and mileage anti-theft alarm based on 51 single chip microcomputer
Next article:8-bit digital tube display electronic clock C51 single chip computer program

Recommended ReadingLatest update time:2024-11-16 21:43

Analysis of the differences between Arduino/Raspberry Pi/MCU/ARM
Arduino Arduino is an open source hardware prototyping platform supported by an open source software environment. It was originally an open source project of an Italian team. In the early days, single-chip microcomputer development needed to operate at the register level. This team encapsulated these registers into fu
[Microcontroller]
Analysis of the differences between Arduino/Raspberry Pi/MCU/ARM
8-bit MCUs in the IoT: Simplifying advanced architecture interfaces with traditional chips
In the current frenzy of connecting everything from blenders to toothbrushes to the cloud, the IoT space is being controlled by low-cost integrated 32-bit microcontroller RF modules that provide small form factor solutions for a small number of sensor inputs. The communication protocol stacks for Wi-Fi®, NB IoT, and
[Internet of Things]
8-bit MCUs in the IoT: Simplifying advanced architecture interfaces with traditional chips
Introduction to 51 MCU - (New) Simple Digital Clock
Design requirements The hours (two digits), minutes (two digits), and seconds (two digits) should be displayed correctly and stably, and the digital tube should not flicker. The hour and minute information can be adjusted by pressing buttons, making it convenient for users to calibrate the time. Add an alarm funct
[Microcontroller]
Introduction to 51 MCU - (New) Simple Digital Clock
DRAM read/write control process of dynamic data buffer controlled by single chip microcomputer
  The program segment for reading one byte of data is as follows:      When reading data, T1 is set to 1 first, and the subsequent RD signal sends the row address to the address line AB, and makes D. The trigger latch Tl, Q, becomes low level , making RAS valid (low level) to achieve row selection; then set TO to 1,
[Microcontroller]
DRAM read/write control process of dynamic data buffer controlled by single chip microcomputer
[MCU] md5 signature algorithm
#include string.h #include "md5.h" #define F(x, y, z) ((x & y) | (~x & z)) #define G(x, y, z) ((x & z) | (y & ~z)) #define H(x, y, z) (x ^ y ^ z) #define I(x, y, z) (y ^ (x | ~z)) #define ROTATE_LEFT(x, n) ((x n) | (x (32 - n))) #define FF(a, b, c, d, x, s, ac)      {                                      a
[Microcontroller]
Share a 51 single-chip DC motor speed control source program
To help novices quickly master the system design of 51 single-chip microcomputer simulating PWM wave for DC motor speed regulation, the single-chip microcomputer source program is as follows: /*******************************************************************/ /* Program name: PWM DC motor speed regulation*/ /* Cry
[Microcontroller]
LCD display and PIC16F877 microcontroller connection
1. Introduction Liquid crystal display is more and more widely used in pocket instruments and low-power application systems due to its advantages of micro power consumption, small size, rich display content, ultra-thin and light weight. The PIC series of microcontrollers produced by Microchip in the United Stat
[Microcontroller]
LCD display and PIC16F877 microcontroller connection
Solar-LED Street Light Solution Based on STM32 MCU
As fossil energy is decreasing and the problem of global warming caused by excessive greenhouse gas emissions is becoming more and more important, people are actively developing various types of renewable energy on the one hand, and advocating green environmental protection technologies for energy conservation and e
[Power Management]
Solar-LED Street Light Solution Based on STM32 MCU
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号