1. Simulate the proteus diagram and run it directly:
2. 51 MCU source code, keil development environment:
#include
#define uchar unsigned char
#define uint unsigned int
sbit IN1 = P2^0;
sbit IN2 = P2^1;
sbit PWM = P2^2;
sbit Key1 = P1^7;
sbit Key2 = P1^6;
sbit Key3 = P1^5;
sbit Key4 = P1^4;
sbit Key5 = P1^3;
uint t = 46082;
void delay_ms(uchar t)
{
fly x,y;
for(x = t;x > 0;x--)
for(y = 110;y > 0;y--);
}
void Timer0_Init()
{
TMOD = 0X01;
TH0 = (65536 - 46082)/256;
TL0 = (65536 - 46082)%6;
EA = 1 ;
ET0 = 1;
TR0 = 1;
}
void Positive_Rotation()
{
IN1 = 0;
IN2 = 1;
}
void Reverse_Rotation()
{
IN1 = 1;
IN2 = 0;
}
void Stop_Rotation()
{
IN1 = 1;
IN2 = 1;
}
void Key_Scan()
{
if(Key1 == 0)
{
delay_ms(20);
if(Key1 == 0)
{
Positive_Rotation();
}
}
else if(Key2 == 0)
{
delay_ms(20);
if(Key2 == 0)
{
Reverse_Rotation();
}
}
else if(Key3 == 0)
{
delay_ms(20);
if(Key3 == 0)
{
Stop_Rotation();
}
}
else if(Key4 == 0)
{
delay_ms(20);
if(Key4 == 0)
{
t = t + 100;
if(t > 65000)
t = 65000;
}
}
else if(Key5 == 0)
{
delay_ms(20);
if(Key5 == 0)
{
t = t - 100;
if(t < 500)
t = 500;
}
}
}
void main()
{
Timer0_Init();
while(1)
{
Key_Scan();
}
}
void timer0() interrupt 1
{
TH0 = t/256;
TL0 = t%6;
PWM = ~PWM;
}
Download address of Proteus simulation diagram and source code package file of DC motor control:
Link:https://pan.baidu.com/s/1dbb8EpFazh_FmQ7DWpOfxQ Password: ooee
Previous article:Application of DS1302 clock chip in single chip perpetual calendar
Next article:KEILC51 compilation problem ERRORL104: MULTIPLEPUBLICDEFINITIONS repeated definition
Recommended ReadingLatest update time:2024-11-16 16:03
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- Single-chip microcomputer C language programming and simulation
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Single chip microcomputer control technology (Li Shuping, Wang Yan, Zhu Yu, Zhang Xiaoyun)
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
- C2000 MCU Boot Process Analysis - Taking TMS320F28069 as an Example
- [New Year's Flavor Competition] + Show off your New Year's Eve dinner and experience ice and snow tourism in the north!
- In STM32F103RCT6, I use the state machine method to add buttons, but I don't want the buttons to work in a function.
- [2022 Digi-Key Innovation Design Competition] Revised version of 2-DOF pan-tilt robot control platform
- Selling a brand new STM32F412 development board
- Award-winning review: Sensirion SEK-SVM40 is coming in the new year, easily monitor indoor air quality and test whether it is "good luck"
- [Domestic digital isolation chip replacement] Nanochip MSI series replaces ADI ADUM and TI IOS series isolation chips
- [Xianji HPM6750EVKMINI Review] 2#OLED module and LVGL routine test
- STM32G071 driver for HDC1080
- Fudan Micro FM33LC046N Review + Serial Communication