3X4 keyboard 4-bit dynamic shift LED display program

Publisher:光速思考Latest update time:2018-01-14 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

;-------------------------------------------------------
;Program name: 3X4 matrix keyboard 4-bit dynamic shift LED display program*
;Function: Scan the key values ​​of the keyboard and display them on the 4-bit LEDs respectively*
;MCU: STC89C58RD+ supports ISP function*
;P0 port connects to LED segment code p2.4 (first LED chip select)~~p2.0 (fourth chip select)*
;p1.6 p1.5 p1.4 p1.3 *

; p1.2 *
; 3 X 4 matrix p1.1 *
; p1.0 *
;-------------------------------------------------------
org 0000H
mov 30h,#00h ; Clear the 30H unit display buffer unit
mov 31h,#00h ; Clear the 31H ten-digit display buffer unit
mov 32h,#00h ; Clear the 32H hundred-digit display buffer unit
mov 33h,#00h ; Clear the 33H thousand-digit display buffer unit
loop_r0: mov r0,#00h ; LED bit counter initial value
ajmp main ; Jump to main program
org 0030h
;****************************************************************
MAIN: ; Main program

LCALL DISPLAY ; Call display subroutine
LCALL KEY ; Call keyboard subroutine
AJMP MAIN ; Return
;***********************************************************
loop_jishu: inc r0
CJNE R0,#01h,LOOP_02H
mov 30h,r3
ajmp main
ret
loop_02h: CJNE R0,#02h,LOOP_03H
mov 31h,r3
ajmp main
ret
loop_03h: CJNE R0,#03h,LOOP_04H
mov 32h,r3
ajmp main
ret
loop_04h : CJNE R0,#04h,LOOP_r0
mov 33h,r3
ajmp main
ret
CJNE R0,#05h,main
ajmp loop_r0
ret

;****************************************************************
KEY: MOV P1,#0FFH
CLR P1.0;Scan KEY1
JB P1.3,KEY1_4 ;P1.3 is high level , jump out, scan the next I/O port, P1.3 is low level, execute the next sentence
ACALL DELAY10ms ;Delay to eliminate bounce and confirm to press
key1__3: JB P1.3,KEY1_4 ;Confirm to jump out, if not confirm, execute the next sentence
MOV r3,#088H ;*
lcall display
jnb p1.3,key1__3
LJMP loop_jishu
KEY1_4: JB P1.4 ,KEY1_5
ACALL DELAY10ms
KEY1__4: JB P1.4 ,KEY1_5
MOV r3,#0F8H ;7
lcall display
jnb p1.4,key1__4
LJMP loop_jishu
KEY1_5: JB P1.5 ,KEY1_6
ACALL DELAY10ms
JB P1.5 ,KEY1_6
KEY1__5: MOV r3,#99H ;4
lcall display
jnb p1.5,key1__5
LJMP loop_jishu
KEY1_6: JB P1.6 ,next1
ACALL DELAY10ms
JB P1.6,NEXT1
KEY1__6: MOV r3,#0F9H ;1
lcall display
jnb p1.6,key1__6
LJMP loop_jishu
; --------------------------
next1: setb p1.0
CLR P1.1 ;Scan KEY2
J B P1.3 ,KEY2_4
ACALL DELAY10ms
JB P1.3 ,KEY2_4
KEY2__3: MOV r3,#0C0H ;0
lcall display
jnb p1.3,key2__3
LJMP loop_jishu
KEY2_4: JB P1.4 ,KEY2_5
ACALL DELAY10ms
JB P1.4 ,KEY2_5
KEY2__4: MOV r3,#80H ;8
lcall display
jnb p1.4,key2__4
LJMP loop_jishu
KEY2_5: JB P1.5 ,KEY2_6
ACALL DELAY10ms
JB P1.5 ,KEY2_6
KEY2__5: MOV r3,#92H ;5
lcall display
jnb p1.5,key2__5
LJMP loop_jishu
KEY2_6: JB P1.6,next2
ACALL DELAY10ms
JB P1.6,NEXT2
KEY2__6: MOV r3,#0A4H ;2
lcall display
jnb p1.6,key2__6
LJMP loop_jishu
;------------- ------------------
next2: setb p1.1
CLR P1.2 ;Scan KEY3
JB P1.3 ,KEY3_4
ACALL DELAY10ms
JB P1.3 ,KEY3_4
KEY3__3: MOV r3, #83H ;#
lcall display
jnb p1.3,key3__3
LJMP loop_jishu
KEY3_4: JB P1.4,KEY3_5
ACALL DELAY10ms
JB P1.4,KEY3_5
KEY3__4: MOV r3,#90H ;9
lcall display
JNB P1.4,KEY3__4
LJMP loop_jishu
KEY3_5: JB P1.5 ,KEY3_6
ACALL DELAY10ms
JB P1.5 ,KEY3_6
KEY3__5: MOV r3,#82H ;6
lcall display
jnb p1.5,key3__5
LJMP loop_jishu
KEY3_6: JB P1.6 ,next3
ACALL DELAY10ms
JB P1.6 ,NEXT3
KEY3__6: MOV r3,#0B0H ;3
lcall display
jnb p1.6,key3__6
LJMP loop_jishu
next3: setb p1.2
RET
;************************ *****************************************
display: mov p0,#0ffh ; Set P02 port to high level
mov p2,#0ffh
mov r7,#100 ; assign software counter value
to dd1:
mov R2,30h ;Send the value in display buffer 30H to ACC
;movc a,@a+dptr ;Look up the table to get the number to be displayed and send the result of the table lookup to ACC
mov p0,R2 ;Send the number to be displayed to P0 clr
p2.4 ; open the unit display unit
lcall delay100us ; delay 100us
setb p2.4 ; close the unit display unit

mov R2,31h ; send the value in the display buffer 31H to A
;movc A,@a+ dptr ; Look up the table to get the number to be displayed and send the result to ACC
mov p0,R2 ; Send the number to be displayed to P0 port
clr p2.5 ; Open the ten-digit display unit
lcall delay100us ; Delay 100US
setb p2. 5 ; Turn off the ten-digit display unit

mov R2,32h ; Send the value in the display buffer 32H to ACC
; movc a,@a+dptr ;Look up the table to get the number to be displayed and send the result to ACC
mov p0,R2 ;Send the number to be displayed to P0 port
clr p2.6 ;Open the hundreds digit display unit
lcall delay100us ;Delay 100US
setb p2.6 ;Close the hundreds digit display unit

mov R2,33h ;Send the value in the display buffer 33H to ACC
;movc a,@a+dptr ;Look up the table to get the number to be displayed and send the result of the table lookup to ACC
mov p0, R2 ; send the number to be displayed to P0 port
clr p2.7 ; open the thousands display unit
lcall delay100us ; delay 100us
setb p2.7 ; close the thousands display unit
djnz r7,dd1 ; if R7 is not equal to 0, return to DD1
ret ;R7 equals 0 and the subroutine returns
;*********************************************** *****************
delay10ms:
mov r6,#50
tt2:
mov r5,#30
djnz r5,$
djnz r6,tt2
ret
delay100us:
mov r5,#30
djnz r5,$
ret
end


Reference address:3X4 keyboard 4-bit dynamic shift LED display program

Previous article:Programming and usage points of 51 single-chip microcomputer driving 74HC595
Next article:Brief Introduction to Functional Components and Features of C8051F320 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号