1. Interruption
(1) External interruption
Open the general interrupt EA, select external interrupt EX0 or EX1, because IE is addressable, so directly operate on EX0 or EX1, then set IT0 (in TCOD) to level trigger or jump edge trigger (power-on default register 0, level trigger mode), then write the interrupt processing function to determine the number after interrupt according to the priority in the table below
(2) Timer interrupt
TMOD is the working mode register of the timer/counter.
TCON is the control register, which controls the start and stop of T0T1 and sets the overflow flag
If the working mode 01 is selected, TH TL is 16 bits
2^16=65536
(65536-N)/256 is equivalent to a bucket that can hold 65536, scooping out N units of water, and then adding 1 unit of water every 1us, and finally taking 5000us=50ms
Next is the detailed explanation of TCON
//Use the timer to replace the delay subfunction in the previous lesson
#include #define uchar unsigned char #define uint unsigned int sbit dula=P2^6; sbit temperature=P2^7; flying number; uchar code table[]={ 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71}; void Time0_delay(); void main() { temperature=1; P0=0xc0; temperature=0; while(1) { for(num=0;num<16;num++) { game=1; P0=table[num]; game=0; Time0_delay(); } } } void Time0_delay() { unsigned int i; TMOD&=0xF0;//有效避免打乱高四位 TMOD|=0X01; //Final TMOD= ABCD 0001 for(i=0;i<20;i++) { TH0=(65536-50000)/256; TL0=(65536-50000)%256; TR0=1; //Start the timer while(!TF0); //delay 50ms TF0=0; // Overflow bit cleared TR0=0; //turn off the timer //Repeat 20 times for 1s } } 3. Code //Comprehensive use of interrupts and timers #include #define uint unsigned int #define uchar unsigned char sbit dula=P2^6; sbit temperature=P2^7; sbit d1=P1^0; fly num,tt; uchar code table[]={ 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71}; void main() { num=0; tt=0; TMOD=0x01; //Set timer 0 to working mode 1 //Assign initial value TH0=(65536-50000)/256; TL0=(65536-50000)%256; EA=1; //Open the general interrupt ET0=1; // Enable the interrupt of timer 0 TR0=1; //Start timer 0, it will keep running as long as it is turned on temperature=1; P0=0xfe; //First digital tube temperature=0; dula=1; P0=0x3f; //To avoid garbled code, assign the initial value 0 game=0; while(1) { //20 times is 1s, perform 1 if if(tt==20) { tt=0; num++; if(num==16) num=0;//clear!!! game=1; P0=table[num]; game=0; } } } /*void delay(uint z) { fly x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); }*/ void exter0()interrupt 1 { TH0=(65536-50000)/256; TL0=(65536-50000)%256; tt++; } 4. Summary
Previous article:Hands-on teaching of 51 single-chip microcomputer | Section 4 Dynamic digital tube, use 6-bit digital tube to make a clock
Next article:Step-by-step teaching of 51 single-chip microcomputer lesson 3 | reset circuit, digital tube static display
- 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
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- The fifth pitfall of domestic FPGA chips: "No devices found" reappears
- What should I do if I can't find an LCD screen of the right size?
- Allwinner heterogeneous multi-core AI intelligent vision V853 development board evaluation + openwrt firmware packaging pack report mbr error solution
- TI TMS320F28335 program SVPWM source program
- 【Smart Kitchen】Environmental Sensor PCB Design
- What is the frequency domain and why is it so important for RF design, analysis and test?
- Unboxing - ESP32-S2 and ESP32-S3 Development Boards + Modules
- Is children's programming a waste of money?
- Last day! Comment to win | Have you ever fallen into the trap of measuring power ripple in the video?
- [ESP32-Korvo Review] (3) Compilation of ESP-Skainet Project