1. Circuit diagram
Figure 4.16.1
2. System board hardware connection
(1. Connect P1.0-P1.3 in the "MCU System" area to L1-L4 in the "Eight-way LED Indicator Module" area with wires.
3. Programming content
(1. Since the interrupt method is used, the interrupt source must have its interrupt entry address. For the timer/counter T0, the interrupt entry address is 000BH, so a long jump instruction is added to the interrupt entry to execute the interrupt service program. The format of writing the assembly source program is as follows:
ORG00H
LJMPSTART
ORG0BH ;Timer/Counter T0 interrupt entry address
LJMP INT_T0
START: NOP ; Main program starts
.
.
INT_T0: PUSH ACC; Timer/Counter T0 interrupt service routine
PUSH PSW
.
.
POP PSW
POP ACC
RETI ;Interrupt service routine returns
END
(2. Timing for 2 seconds, using 16-bit timing of 50ms, a total of 40 times of timing can reach 2 seconds, an interrupt is generated every 50ms, and the 40 times of timing are completed in the interrupt service program. Similarly, for a timing of 0.2 seconds, 4 times are required to reach 0.2 seconds. For the interrupt program, the interrupt must be disconnected in the main program.
(3. Since each 2-second timer expires, L1-L4 flash alternately. Use ID to identify. When ID = 0, L1 flashes; when ID = 1, L2 flashes; when ID = 2, L3 flashes; when ID = 3, L4 flashes
4. Flowchart
T0 interrupt service program block diagram
Main program block diagram
Figure 4.16.2
5. Assembly source program
TCOUNT2S EQU 30H
TCNT02S EQU 31H
ID EQU 32H
ORG 00H
LJMP START
ORG 0BH
LJMP INT_T0
START: MOV TCOUNT2S,#00H
MOV TCNT02S,#00H
MOV ID,#00H
MOV TMOD,#01H
MOV TH0,#(65536-50000) / 256
MOV TL0,#(65536-50000) MOD 256
SETB TR0
SETB ET0
SETB EA
SJMP$
INT_T0: MOV TH0,#(65536-50000) / 256
MOV TL0,#(65536-50000) MOD 256
INC TCOUNT2S
MOV A,TCOUNT2S
CJNE A,#40,NEXT
MOV TCOUNT2S,#00H
INC ID
MOV A,ID
CJNE A,#04H,NEXT
MOV ID,#00H
NEXT: INC TCNT02S
MOV A,TCNT02S
CJNE A,#4,DONE
MOV TCNT02S,#00H
MOV A,ID
CJNE A,#00H,SID1
CPL P1.0
SJMP DONE
SID1: CJNE A,#01H,SID2
CPL P1.1
SJMP DONE
SID2: CJNE A,#02H,SID3
CPL P1.2
SJMP DONE
SID3: CJNE A,#03H,SID4
CPL P1.3
SID4: SJMP DONE
DONE: RETI
END
6. C language source program
#include unsigned char tcount2s; unsigned char tcount02s; unsigned char ID; void main(void) { TMOD=0x01; TH0=(65536-50000)/256; TL0=(65536-50000)%6; TR0=1; ET0=1; EA=1; while(1); } void t0(void) interrupt 1 using 0 { tcount2s++; if(tcount2s==40) { tcount2s=0; ID++; if(ID==4) { ID=0; } } tcount02s++; if(tcount02s==4) { tcount02s=0; switch(ID) { case 0: P1_0=~P1_0; break; case 1: P1_1=~P1_1; break; case 2: P1_2=~P1_2; break; case 3: P1_3=~P1_3; break; } }
Previous article:Resistance-temperature measurement system of carbon black composite conductive material based on 51 single chip microcomputer
Next article:Circuit module design of intelligent transformer temperature monitoring instrument
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
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
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Can UST_OTG1 be used with a USB flash drive?
- Altium Designer 20.0.9.164
- "Introduction to Arduino Interactive Design with Perfect Illustrations" - Getting Started with Microcontrollers from Scratch
- TI wM-Bus 169MHz RF Subsystem with Receiver for Smart Gas and Water Meters
- Delay calculation by cross-correlation method
- i.MX6ULL Embedded Linux Development 4-Root File System Construction
- 【NUCLEO-L552ZE Review】-1: Start from TrustZone
- What types of anti-wear hydraulic oil are there? What are their characteristics?
- [STM32WB55 Review] What are the differences between dual-core MCUs?
- Reducing Power MOSFET Losses (Hardware)