//Experimental routine Prawn (DX-51) learning board timer 0, 1 usage routine
#include #include //MCU51 embedded professional emulator occupies 3 bytes of program space 0x003b, 0x003c, 0c003d, //Use the code array declaration to prevent the compiler from locating the function in the program space where this three bytes are located. unsigned char code DX58[3] _at_ 0x003b; unsigned char count; unsigned char direction; unsigned char delay1; unsigned char delay2; void timer0(void) interrupt 1 using 0 { TL0=0x06; TH0=delay2; /* Timer 0 interrupt*/ if (++delay1 > 4){ delay1 = 0; if (++count > 7) count = 0; P1 |= 0x0ff; P1 &= ~(0x01 << count); } /* Timer 0 interrupt*/ } void timer1(void) interrupt 3 using 0 { TL1=0x06; TH1=0x00; /* Timer 1 interrupt*/ if (direction){ if (++delay2 == 128)direction = 0; } else { if (--delay2 == 0)direction = 1; } /* Timer 1 interrupt*/ } // Timer function demonstration program // P01, P02, P03, P04 pins are connected to the light-emitting diodes led1, led2, led3, led4 // Connect the resistor on each LED string to the 5V power supply and run this demonstration program // You will see the light-emitting diodes light up and go out in sequence, which is more beautiful than the colorful lights on the street. // There are too many. If you don’t believe me, try it. void main(void){ ET0 = 1; /* Allow timer 0 interrupt*/ ET1 = 1; /* Allow timer 1 interrupt*/ TMOD = 0x11; /* Timer working mode selection*/ TL0 = 0x06; TH0 = 0x00; /* Assign initial value to timer*/ TL1 = 0x06; TH1 = 0x00; /* Assign initial value to timer*/ TR0 = 1; /* Start timer*/ TR1 = 1; /* Start timer*/ EA = 1; /* Turn on total interrupt */ delay2 = 0; direction = 1; while(1){ _nop_ (); /* delay for hardware */ } }
Previous article:51 microcontroller external interrupt processing source program
Next article:Timer function demonstration program
Recommended ReadingLatest update time:2024-11-16 13:42
- Popular Resources
- Popular amplifiers
- Network Operating System (Edited by Li Zhixi)
- Microgrid Stability Analysis and Control Microgrid Modeling Stability Analysis and Control to Improve Power Distribution and Power Flow Control (
- MATLAB and FPGA implementation of wireless communication
- Introduction to Internet of Things Engineering 2nd Edition (Gongyi Wu)
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
- Working principle of electronic tags
- Sell some idle SSDs Samsung 850 and 860evo
- Grab and run! EPOS implementation in unmanned retail stores
- Ask
- I would like to ask why this compensation circuit can achieve advance compensation.
- Please recommend a single chip analog to PWM solution
- Made in China 103CBT6 chip
- Servo motor noise and instability analysis
- CC3200 module first article - wlan_ap routine test
- How to self-test the fault of resistor parallel circuit?