#include
#define uint unsigned int
#define uchar unsigned char
sbit k1=P3^2;
sbit k2=P3^3;
sbit bee=P1^2;
volatile PWM,num;
void delay(float z)
{
flying i;
while(z--)
{
for(i=120;i>0;i--);
}
}
void spk()
{
bee=0;
delay(100);
bee=1;
delay(100);
}
void init_t0()
{
TMOD=0X01;
TH0=255;
TL0=256-PWM;
EA=1;
ET0=1;
TR0=1;
}
void key_scan()
{
while(k1==0)
{
if(PWM!=0XFF)
{
PWM++;
delay(10);
}
else
spk();
}
while(k2==0)
{
if(PWM!=0X01)
{
PWM--;
delay(10);
}
else
spk();
}
}
void main()
{
PWM=0X7f;
P2=0XFF;
init_t0();
while(1)
key_scan();
}
void t0() interrupt 1
{
num++;
TR0=0;
if(num%2==1)
{
P2=0;
TH0=0XFF;
TL0=256-PWM;
TR0=1;
}
if(num%2==0)
{
P2=0XFF;
TH0=0XFF;
TL0=PWM;
TR0=1;
}
}
Previous article:ADC0804 Applications
Next article:LCD1602 display program with mobile screen
Recommended ReadingLatest update time:2024-11-16 19:46
STM32 Timer PWM_Output
The pulse width modulation mode can generate a signal with a frequency determined by the TIMx_ARR register and a duty cycle determined by the TIMx_CCRx register.
The following is an example of PWM mode 1. The PWM signal reference OCxREF is high when TIMx_CNT
Library function STM32F10x_StdPeriph_Lib_V3.3.0\Proje
[Microcontroller]
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- 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
MoreDaily News
- 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
Guess you like
- Award-winning domestic chip live broadcast: Xianji 800MHz RISC-V MCU high-energy show, more than just controlling 4 servo motors, a lot of practical information
- EEWORLD University Hall----Live Replay: Explore the Black Technology Behind Smart Door Locks with Infineon
- I have basic knowledge of embedded C programming and almost no knowledge of digital electronics. How long will it take to self-study FPGA to Ethernet communication?
- [Ended] Buy now: Free shipping for new users of e-Network is about to end, post your order and leave a message to get a surprise~
- Chip plagiarism, fined 4 million yuan!
- TIOBE August 2022 Ranking
- Reading Notes of the Good Book "Electronic Engineer Self-study Handbook" 02-Keil uVision4 & STC
- I received the book on the basics of power supply design and I feel it is necessary to share it
- IEC61000-4-5 coupling mode
- Brushless servo, no Hall drive, electric vehicle controller (with Hall sine wave)