TMOD register:
Let’s talk about the TMOD register. This register can choose to turn on timer 0 or 1, and can also decide how the timer works. As shown in the picture:
Code:
#include sbit LED=P2^0; typedef unsigned char u8; typedef unsigned int u16; void time1_init(void) { TMOD|=0x10; //TMOD is a register used to determine the working mode of the timer. The high four bits determine timer 1. Currently, it is working mode 1, which is 16-bit timing counting. TH1=0xfc; //High eight bits of timer TL1=0x18; //lower eight bits of timer ET1=1; //Interrupt enabled EA=1; //Total interrupt is turned on TR1=1; //Enable timer interrupt } void main(void) { time1_init(); //Initialization while(1) { } } void tmie1(void) interrupt 3 //interrupt service function { static u16 i; //No assignment required, automatically initialized to 0 TH1=0xfc; TL1=0x18; i++; if(i==1000) { i=0; LED=!LED; } } operation result: The result is the same as timer 0, it flashes once per second and no picture is sent.
Previous article:51 Microcontroller Basics Dot Matrix LED8X8
Next article:51 Microcontroller Basics: Timer Interrupt (1)
- 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
- Fluke 17b is broken, do you know how to repair it?
- Data first: ST's latest STML5 product development board NUCLEO-L552ZE-Q (Cortex-M33 core)
- FPGA development process.
- RISC-V RVB2601 First Experience
- What voltage is suitable for TL431?
- Principle of pyroelectric infrared sensor
- Importing an old MPLAB IDE V8.9 project into MPLAB X IDE shows 'other' has different root
- [Smartwatch for environmental experts] Part 8: Code migration for personnel going down the mine
- Post count 1234, mark it here
- Open Source ESP32 Color Screen WIFI/BLE Smart Multimeter Production Process (1. Shell and Screen Selection)