/*****************************************************
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
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
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- 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
- MSP430 standby power consumption problem
- How feasible is it for the United States to skip 5G and go directly to 6G?
- [TI recommended course] #TI? Application of interface chips in automotive products#
- 【Gravity:AS7341 Review】+Bought some colored paper for testing
- 008
- Showing Goods (7) - Open Source Development Board
- New version of IAR installation problems and solutions
- Disassembling I-Mu/Huanxiang Huanxiang Yangmeituqi Bluetooth Speaker
- arm assembly instructions WFI and WFE
- CCS new project and library file loading