After entering the program, the program will operate as a two-way marquee; press the k0 key and the program will operate as a left-hand marquee; press the k1 key and the program will operate as a right-hand marquee; press the k2 key and the two bright spots will move from both sides to the middle; press the k3 key and the two bright spots will move from the middle to both sides.
2. Experimental Purpose:
Master the response method of processing multiple key actions in the interrupt program
3. Experimental task analysis:
(Note: When doing this experiment, don't forget to put the JMP0 jumper in the position of 1, 2, and select the diode display unit.)
In the previous two interrupt modes to respond to key actions, we only responded to one key action, which was relatively easy.
In this program, our interrupt program needs to respond to multiple key actions. There are 4 kinds of light changes, which are switched by different keys. So, how should this problem be handled?
We can do it like this: In the main program, we make left and right marquees, which I believe everyone is already familiar with.
In the interrupt service program, we first read the key status, then delay 10ms, and read the key status again. Compare the key status obtained twice. If they are different, it means jitter, and exit the interrupt; otherwise, determine which key is pressed. If it is k0, execute the left marquee; if it is k1, execute the right marquee; if it is k2, execute the bright spot to move to the middle; if it is k3, execute the bright spot to move to both sides.
This idea is generally correct, but there is one thing to note: when we write programs, in the interrupt service program, we should try to simplify the tasks, do not let the interrupt service program do too many complex tasks, and try to put these complex tasks in the middle of the main program to complete.
According to this idea, our approach is as follows:
set 5 flags in the main program, and then constantly query these flags: if it is flag 1, execute the two-way marquee; if it is flag 2, execute the left marquee; if it is flag 3, execute the right marquee, and so on.
In the interrupt service program, we only need to do the following work: de-jitter, key recognition, change the flag, that's it.
In this program, we use the content in register r0 as a flag. When the content in it is 0ffh, execute the left and right marquee program; when it is 00h, execute the left marquee; when it is 01h, execute the right marquee; when it is 02h, execute the two bright spots to move to the middle; when it is 03h, execute the two bright spots to move to both sides.
Now let's take a look at the flowchart of the main program and the interrupt service program:
The following is a program written according to this idea. The structure of this program is slightly complicated, so please pay attention.
4. The experimental procedure is as follows:
org 0000h
ajmp start
org 0013h
ajmp ext1
org 0020h
start: clr p1.5
mov r0,#0ffh; Assign an initial value to r0, r0 is the flag we set,
setb ea ; enable interrupt
setb ex1 ; allow external interrupt 1 to request interrupt
setbit1 ; Set external interrupt 1 jump mode trigger
mov sp,#70h ;Set up the stack
loop0: cjne r0,#0ffh,loop1 ; If the content in r0 is not 0ffh, go to loop1
ajmp main_light ; Otherwise, execute the left and right marquee
loop1: cjne r0,#00h,loop2; if the content in r0 is not 00h, go to loop2
ajmp k0_light ; Otherwise, execute the left marquee
loop2: cjne r0,#01h,loop3 ; if the content in r0 is not 01h, go to loop3
ajmp k1_light ; Otherwise, execute the right marquee
loop3: cjne r0,#02h,loop4; if the content in r0 is not 02h, go to loop4
ajmp k2_light ; Otherwise, execute the double bright spot to move to the middle
loop4: cjne r0,#03h,loop5 ;If the content in r0 is not 03h, return and restart the query
ajmp k3_light ; Otherwise, execute double bright spots to move to both sides
loop5: ajmp loop0 ; return and restart the query
ext1: clr ea ; disable interrupts
push acc ; scene protection
push psw
mov a,p1 ; read key status
anl a,#0fh ; shield the upper four bits
mov 30h,a ; save the keyboard status value in 30h
mov a,p1 ; read the key status again
anl a,#0fh ; shield the upper four bits
cjne a,30h,pass ;If the two key values are not equal, it means jitter, exit interrupt
ajmp k0_check ; if equal, jump to key recognition program
; The following is the key recognition program
k0_check: cjne a,#0dh,k1_check; If k0 is not pressed, check whether k1 is pressed
ajmp k0_manage ; Otherwise, jump to the key processing procedure of k0
k1_check: cjne a,#0eh,k2_check; If k1 is not pressed, check whether k2 is pressed
ajmp k1_manage ; Otherwise, jump to the key processing procedure of k1
k2_check: cjne a,#0bh,k3_check; If k2 is not pressed, check whether k3 is pressed
ajmp k2_manage ; Otherwise, jump to the key processing procedure of k2
k3_check: cjne a,#07h,pass ;If k3 is not pressed, exit interrupt
ajmp k3_manage ; Otherwise, jump to k3's key processing procedure
; The following are the corresponding processing procedures for each key,
k0_manage: mov r0,#00h ; set flag 2
ajmp pass
k1_manage: mov r0,#01h ; set flag 3
ajmp pass
k2_manage: mov r0,#02h ; set flag 4
ajmp pass
k3_manage: mov r0,#03h : set flag 5
ajmp pass
pass: pop psw ; restore the scene
pop acc
setb ea ; enable interrupt
reti ;Interrupt return
main_light: mov r7,#08h ;main_light is the left and right running light program
mov r6,#06h
mov a,#0feh
l_loop: mov r1,a ; Use r1 to save the current bright spot position, so that you can start from this position when changing the light
mov p0,a
lcall del100ms
rl a
djnz r7,l_loop
mov a,#0bfh
r_loop: mov r1,a
mov p0,a
lcall del100ms
rr a
djnz r6,r_loop
ljmp loop0
k0_light: mov a,r1; k0_light is the left-hand marquee program
mov p0,a
lcall del100ms
rl a
mov r1,a
ajmp loop0
k1_light: mov a,r1; k1_light is the right-hand marquee program
mov p0,a
lcall del100ms
rr a
mov r1,a
ajmp loop0
k2_light: mov p0,#7eh; k2_light is a double bright spot to the middle program
lcall del100ms
mov p0,#0bdh
lcall del100ms
mov p0,#0dbh
lcall del100ms
mov p0,#0e7h
lcall del100ms
ajmp loop0
k3_light: mov p0,#0e7h; k3_light is a program for double bright spots to both sides
lcall del100ms
mov p0,#0dbh
lcall del100ms
mov p0,#0bdh
lcall del100ms
mov p0,#7eh
lcall del100ms
ajmp loop0
del10ms: mov r5,#20 ;10ms delay program
del1: mov r4,#0ffh
del2: djnz r4,del2
djnz r5,del1
ret;
del100ms: mov r3,#200 ;100ms delay program
del3: mov r2,#0ffh
del4: djnz r2,del4
djnz r3,del3
ret
end;
Previous article:MCU Learning 15: Timer Application 2 (Mode 2)
Next article:MCU Learning 12: Button Control Marquee (Interrupt)
Recommended ReadingLatest update time:2024-11-23 16:33
- 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)
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- I would like to share my experience on the coordination between PC817 and TL431. I hope to discuss with my peers. [Repost]
- At 10:00 this morning, we invite you to listen to the award-winning live broadcast: ADI's digital active noise reduction headphone solution allows technology to calm us down~
- Common MOS tube models and parameter comparison table
- CC4032------Three serial adders.rar
- TLC1542C/I/M/Q, TLC1543C/I/Q 10-bit switched capacitor successive approximation analog-to-digital converter
- Single board design related
- 2006 Top 50 Best Employers for Chinese University Students
- Discussion on the Link between Test Equipment and Design Tools
- Power supply obstacles + power supply stability
- ST's latest evaluation activity! Get the first-hand experience of the NUCLEO_G431RB development board here