This is a doorbell program set by a microcontroller timer, with source code and documentation. The doorbell designed with the timer is described as follows: When the button is pressed, the buzzer emits a ding-dong doorbell sound.
program
/* After downloading the program, pressing button K1 will trigger the buzzer doorbell to ring "Ding Dong" */
#include typedef unsigned char u8; typedef unsigned int u16; sbit beep=P1^5; sbit k1=P3^1; u8 ding,dong,flag,stop; u16 n; void delay(u16 i) { while(i--); } void time0init() //Timer 0 initialization { TMOD=0X01; //Timer 0 mode 1 TH0=0Xff; TL0=0X06; //timing 250us //TR0=1; EA=1; ET0=1; } void biaohaoinit() // Initialize each label { ding=0; //ding sound counting flag dong=0; //dong sound counting mark n=0; //0.5s timing mark flag=0; stop=0; //end mark } void main() { time0init(); biaohaoinit(); while(1) { if(k1==0) // Check if the button is pressed { delay(1000); //debounce if(k1==0) { TR0=1; //Turn on timer 0 while(!stop); } } } } void time0() interrupt 1 { n++; TH0=0Xff; TL0=0X06; //250us if(n==2000) //Timer 0.5s, ding for 0.5 seconds, dong for 0.5 seconds { n=0; if(flag==0) { flag=~flag; } else { flag=0; stop=1; TR0=0; //Turn off timer 0 } } if(flag==0) { //The doorbell sound can be changed by changing the timing count time ding++; //ding if(ding==1) { ding=0; beep=~beep; } } else { dong++; if(dong==2) //dong { dong=0; beep=~beep; } } }
Previous article:51 MCU reads and writes RC522 card (LCD12864) RFID development program and schematic diagram
Next article:MCU programming practice infrared interrupt timing 12864 step by step explanation
Recommended ReadingLatest update time:2024-11-16 13:29
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
- [NXP Rapid IoT Review] W1 First Impressions
- I would like to ask about the problem of SPWM wave passing through a low-pass filter
- EEWORLD University Hall--Follow Grant Imahara to learn the latest robotics technology and concepts
- 【RPi PICO】Calculate Mandelbrot
- Understanding of time-sharing processing in operating systems
- MSP432 learning experience: system tick timer
- [GD32L233C-START Review] - IV. GD32 drives MAX7219 digital tube display
- [New Year's Festival Competition] + Our Northeastern Nagata
- EEWORLD University Hall----Data Structure Shanghai Jiaotong University
- Garbage disposer single-phase AC motor purchase plan