First click option for target 'target1' under project
Change the crystal frequency to 11.0592MHz, which is consistent with the crystal frequency on the TX-1C test board
Then click the start/stop debug session button under debug to debug
The delay code is as follows
#include unsigned int i,j; //Unsigned integer variables are allocated two bytes, ranging from (0 to 65535, i.e. 2^16-1) sbit led8=P1^7; //Declare the highest bit of port P1 as led8 void main() { while(1) { led8=0; //Set the highest position of P1 port to 0 for(i=100;i>0;i--) for(j=500;j>0;j--);//It takes time for the MCU to execute the code, and the double-layer for loop plays a role in delaying led8=1; for(i=100;i>0;i--) for(j=500;j>0;j--); } } Click port1 in peripherals You can see the 8-bit status of P1 port, and all I/O ports are 1 Look at the watch1 label in the lower right corner, press F2, enter the two variables i and j, and it will be displayed as 0x00. i and j are not assigned values at the beginning, and the compiler defaults to 0. They are assigned values after entering the for loop. You can see that the sec value in the left register window is 422.09 microseconds, which is the time taken by the program from the start to the yellow arrow. If you run it in a single step, you can see that the check mark in the highest position is gone, indicating that the statement led8=0 has been executed. The eighth diode is lit for 423.18 microseconds, minus 422.09 microseconds, which is 1.09 microseconds, or one machine cycle. Click the reset button to set two breakpoints. When the full speed runs to the breakpoint, it stops. The statement after the breakpoint is the next statement to be executed. Click Run at Full Speed, and you can see that the time becomes 88535.16 microseconds. Subtract the previous 423.18, and the double-layer for loop is about 88111.92 microseconds, that is, the eighth LED flashes every 88 milliseconds. Summarize 1. Clock cycle: The reciprocal of the clock frequency is the reciprocal of the external crystal oscillator. The clock cycle of a 12MHz crystal oscillator is 1/12 microseconds. Machine cycle: A machine cycle consists of 12 clock cycles. 2. In the "New Concept 51 Single Chip Microcomputer Tutorial", the author debugged that when the variable type is unsigned int, the inner for loop is constant at 110. The outer for loop is about the same as the number of milliseconds, such as for(i=1000;i>0;i–)for(j=110;j>0;j–);, which means a delay of 1 second. This is just an approximate time. If you want higher accuracy, use a timer.
Previous article:51 single chip microcomputer realizes the operation of running water lamp
Next article:Microcontroller learning notes - interrupt principle and application
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Principles and Applications of Single Chip Microcomputers and C51 Programming (3rd Edition) (Xie Weicheng, Yang Jiaguo)
- Teach you to learn 51 single chip microcomputer-C language version (Second Edition) (Song Xuefeng)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- MCU ultra-low power consumption ULPMark-CP benchmark ranking
- [NUCLEO-L452RE Review] + FREERTOS (CMSIS-RTOS) Event
- Application guide of small power supply in optical module
- Sign up to win red envelopes and draw development boards | 2021 RT-Thread Developer Conference is waiting for you!
- [RVB2601 Creative Application Development] Unboxing, Development Environment CDK Installation, Demo Test
- [Xianji HPM6750 Review] + Analog SPI TFT display text, sensor data
- Reeds are lush and white dew turns to frost~
- B04B-PASK-1(LF)(SN) Attributes
- Regarding the issue of nrg being both a master and a slave?
- Quartus II USB-Blaster driver installation problems, three special solutions