T1 is timing mode, timing 65.536ms, the LED corresponding to P2.0 flashes once, T0 is counting mode, the counting pulse is input from P3.4 pin with a button, one press, one count, so the initial count value is 0FFFFh, no press, an overflow occurs, the LED corresponding to P2.5 flashes, and the digital tube adds 1 to the display.
1. Timer/Counter Terminal Mode
org 0000h
ljmp bb; Jump to the main program entry bb
org 000bh; Timer 0 interrupt response starts here
cjne r2,#9d,xx
mov r2,#00h
ljmp xx11
org 001bh; Timer 1 interrupt response starts here
ljmp xxx
mov tmod,#05h ;05h=0000 0101B Set T1 timing T0 counting mode, 0 timing, 1 counting
; 00 is 13-bit binary counting mode 0, the upper 4 bits control T1
; 01 is 16-bit binary counting mode 1, the lower 4 bits control T0
mov dptr,#0300h ;store the table entry address
mov r2,#00h
setb et0 ;same effect as setb 0afh
setb ea ;same as setb 0abh
setb et1 ;same as setb 0a9h
setb tr1
mov th0,#0ffh ;The upper 8 bits of the initial count value of counter 0
mov tl0,#0fdh ;The lower 8 bits of the initial count value of counter 0 (the initial count value for the first time)
sjmp $ ;When the program is executed, it will wait for the statement in place. When there is no interrupt request,
;it will count in place at this position and jump to the interrupt entry to execute the interrupt when there is a request
xx: inc r2
xx11: mov th0,#0ffh ;The upper 8 bits of the initial count value of counter 0
mov tl0,#0fdh ;The lower 8 bits of the initial count value of counter 0 (the initial count value for the second time and after)
mov a,r2
movc a,@a+dptr
cpl p2.5
mov p1,a
reti
mov tl1,#00h ; the lower 8 bits of the initial count value of counter 1
cpl p2.0
reti
db 3fh, 06h, 5bh, 4fh, 66h, 6dh, 7dh, 07h, 7fh, 6fh
end
2. Timer/Counter Query Mode
org 0000h
ljmp bb ; jump to main program entry bb
; Set T1 timing mode to work in counting mode 0, set T0 counting mode
to work in counting mode 1
clr et0 ;turn off timer/counter 0 interrupt
setb ea ;same as setb 0abh, turn on the general interrupt switch
setb et1 ;same as setb 0a9h, turn on timer/counter 1 interrupt
setb tr0
setb tr1
mov th0,#0ffh ;high 8 bits of the initial count value of counter 0
mov tl0,#0ffh ;low 8 bits of the initial count value of counter 0 (initial value for the first start of counting)
CX: JBC TF0, xx ;query the overflow flag of timer/counter 0, if there is overflow, jump to xx to execute
JBC TF1, xxx ;query the overflow flag of timer/counter 1, if there is overflow, jump to xxx to execute
sjmp CX ;no overflow, jump to CX to continue querying
;overflow occurs when THi and TLi count fully and exceed FFFFH, TFi is automatically set to 1, interrupts and queries are
responded to based on whether this flag is 1.
xx: mov th0,#0ffh ;high 8 bits of counter 0 count initial value
mov tl0,#0ffh ;low 8 bits of counter 0 count initial value (start counting initial value after the second time)
cjne r2,#10d,xx11
mov r2,#00h
xx11: mov a,r2
movc a,@a+dptr ;look up the table and use seven-segment code to display the count number
cpl p2.5 ;and make the LED on P2.5 have a flashing effect
mov p1,a ;display the digital effect and output from P1 port
inc r2 ;add 1 to count
ret
mov tl1,#00h ; the low 8 bits of the initial count value of counter 1
cpl p2.0 ; t0 timing mode, when the timing is reached, P2.0 is inverted, and the LED achieves a flashing effect
ret
db 3fh,06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6fh
end
Previous article:About the use of 51 single chip microcomputer serial port
Next article:Multifunctional electronic clock based on AT89S52 and HD7279A
- 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
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- [Awards awarded] Grab the post! Download the TWS headset white paper, write a wonderful review, and win a JD card!
- Constant voltage circuit and constant current circuit composed of operational amplifier and triode
- [RVB2601 Creative Application Development] Record the startup process of the hello world system
- How to initialize the key port of the power button in C language
- About the use and description of idconfig
- [CC1352P Review] The beginning of a little frustration
- A Brief Discussion on the State Machine of the Single-Chip Microcomputer
- MSP430 MCU Theoretical Knowledge Points
- Share a panoramic view of the 5G industry
- Electronic hourglass based on physical model