There are many methods, here is one for you, you can debug it, you can use different crystals to calculate the initial value of the timer, if you understand the timer part, it is very easy to adjust
#include
sbit p1_0=P1^0;
int i; //global variable
void timing(void) //the crystal is 3.6864M
{
TMOD|=0x01; //timer T0, working mode 1
TH0=0xC3;
TL0=0xC7; //these two registers store the starting value of the counter, these two values are accumulated to overflow, it is exactly 50ms
ET0=1; //enable T0 interrupt to overflow
EA=1; //enable total interrupt
TF0=0; //clear overflow bit
TR0=1; //enable T0
}
/********timing interrupt function************/
void time0_int () interrupt 1 //timing interrupt function
{
TH0=0xC3;
TL0=0xC7;
i++;
}
main()
{
i=0;
timing();
while(;)
{
if(i==20)
{
p1_0=~p1_0; //p1.0 port status flip
i=0;
}
}
}
Previous article:iic standard code (real universal code 1161)
Next article:Counter of single chip microcomputer C51
Recommended ReadingLatest update time:2024-11-16 19:30
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- How to read electrical control circuit diagrams (Classic best-selling books on electronics and electrical engineering) (Zheng Fengyi)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
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
- micropython update: 2021.4
- The battery voltage is pulled down
- Is there any abnormal sound from the common mode inductor?
- There's a problem with the project
- bq27411-g1 (single-cell fuel gauge) bq27541 (single-cell fuel gauge) bq27546-g1 (single-cell fuel gauge)
- Playing with circuits (2) - Killing LM5175
- A post in the Audiophile Academy. I just want to ask why there is no loop phase shift when a resistor is added before the decoupling capacitor.
- TI teaches you how to overcome the three common problems in high-speed amplifier design
- Is it suitable to learn Java right after graduating from university?
- [Social Recruitment] Senior Comprehensive STA R&D Engineer