The requirement is to use timer T0 mode 1 to generate a 10ms timing, and output a square wave with a period of 20ms on the P1.0 pin, using the interrupt mode, and set the system clock frequency to 12MHz.
Let's talk about the program first, as follows
The above program uses the interrupt method to generate interrupts. It takes a certain amount of time for the counter to add 1 each time. The timer timing is obtained by the accumulation of this time. 89C51 has four register units TH0, TL0, TH1, TL1 to store count values. Each register is 8 bits, and there is also a register TMOD to set the working mode. Each mode has a different counting range and different functions. I will talk about this issue later when I have time.
The timer is controlled by setting the relevant registers, mainly TCON and TMOD
TCON is a control register, which contains many interrupt flags. By setting it, the interrupt of the microcontroller can be controlled. The microcontroller can know whether an interrupt has occurred in the system through it.
TMOD is the working mode register, which can control the working mode of the microcontroller. It can control the trigger mode of the microcontroller and the switching of C/T.
Because the idea of this article is to use interrupt control, it is also necessary to set the interrupt control bit IE
Here we will introduce the joint debugging of KEIL software and PROTEUS software.
Let's take a look at the keil software first
This software is free and very easy to use. It supports C language programming and assembly programming. We chose assembly programming. Before compiling, we need to build a project.
When compiling, please note that this software will eventually generate a hex file to support simulation, so click the button on the left of target, as shown below
After opening, the following interface will appear. Select the output tab and tick the box next to create hex file.
If there are no errors in the program, a hex file will be generated under the project folder. OK, the program work is completed.
Next, we will move on to the design of the microcontroller hardware circuit (in practice, hardware should come first and software later, but this article forgets to consider this point)
This is the circuit diagram in the proteus environment, which is a very good simulation software (note that the oscillation frequency of the crystal oscillator should be set to 12MHz)
My circuit is to output a pulse signal at port P1.0. The following is a simulation
The effect is very good, and I feel a sense of accomplishment.
Through this design, we can find that the interrupt of the MCU is generated after the MCU counts fully. Then the counter is an accurate timing function in this process. When an interrupt occurs, it is necessary to enter the interrupt service program. This program is written by ourselves. In order to ensure continuous output of pulses, it is necessary to assign an initial value to the counter in this program and invert P1.0. OK, let's take a break.
Previous article:Serial port communication problem between MCUs
Next article:The use of single chip computer scattered transfer table program
- 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
- Embedded System Design and Examples.pdf
- [GD32L233C-START Review] Development environment construction and download test
- Gallium nitride substrate production technology and equipment
- Safety temperature standards for main components of switching power supplies
- Auxiliary trainer for plank and push-up exercises
- MicroPython will add serial port interrupt function
- MOS tube
- C6678 on-chip storage space allocation mechanism
- Game: Help Blinka get out of various difficulties
- The difference between IAR and Keil development tools