;-------------------------------------------------------
;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
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
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Free application: ST sensor kit SensorTile.box worth 350 yuan
- EEWorld Circuit Diagram Channel has a new version and is now online, come and experience it now!
- Reduction Operator Introduction
- [SAMR21 New Gameplay] 32. CPU-related functions
- WiFi 7 specs, features and release date
- 【LuatOS-ESP32】Create a new hello world project
- C2000 Power-on Boot Mode Analysis
- Espressif ESP32-S2-Kaluga-1 Review Summary
- EEWORLD University Hall----Electromagnetic Compatibility Principles and Design
- MSP430 realizes access card function (RFID) through RC522