This is a PWM speed control program for DC motors with AT89C51 MCU. The program can be directly used in AT89C52, AT89S51, AT89S51, STC89C51, STC89C52 MCUs. The MCU crystal uses 11.0592M. The DC motor is controlled by L298 integrated circuit. The frequency of the generated PWM is about 91Hz. The pins of L298 have been marked in the program. You can draw the schematic diagram by yourself. I won't give it here. The following is the source program.
#include[reg52.h> //Please replace ' [ ' with "<", the same below. Otherwise, an error will occur during compilation.
#include [intrins.h> //
#define uchar unsigned char
#define uint unsigned int
sbit en1=P2^0;
sbit en2=P2^1;
sbit s1=P2^2;
sbit s2=P2^3;
sbit s3=P2^4;
sbit s4=P2^5;
fly t=0;
fly m1=0;
uchar m2=0;
float tmp1,tmp2;
void motor(uchar index, char speed)
{
if(speed>=-100 && speed<=100)
{
if(index==1)
{
m1=abs(speed);
if(speed<0)
{
s1=0;
s2=1;
}
else
{
s1=1;
s2=0;
}
}
if(index==2)
{
m2=abs(speed);
if(speed<0)
{
s3=0;
s4=1;
}
else
{
s3=1;
s4=0;
}
}
}
}
void delay(uint j)
{
for(j;j>0;j--);
}
void main()
{
char i;
TMOD=0x02;
TH0=0x9B;
TL0=0x9B;
EA=1;
ET0=1;
TR0=1;
while(1)
{
for(i=0;i<=100;i++)
{
motor(1,i);
motor(2,i);
delay(5000);
}
for(i=100;i>0;i--)
{
motor(1,i);
motor(2,i);
delay(5000);
}
for(i=0;i<=100;i++)
{
motor(1,-i);
motor(2,-i);
delay(5000);
}
for(i=100;i>0;i--)
{
motor(1,-i);
motor(2,-i);
delay(5000);
}
}
}
void timer0() interrupt 1
{
if(t==0)
{
tmp1=m1;
tmp2=m2;
}
if(t
if(t
t++;
if(t>=100) t=0;
}
Previous article:Simulation of Motor Speed Measurement System Based on AT89C51 Single Chip Microcomputer
Next article:51 single chip microcomputer automatic bell C language program
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- ADS Simulation of Microstrip Filter
- Intel has set up a special website to promote that its own chips are superior to Apple M1. Who do you stand with?
- Can the input voltage Vi of a logic device be higher than the supply voltage Vcc?
- [Hua Diao DIY] Fast food box cover, a very low-cost experimental platform for building robot walking
- 【GD32L233C-START Review】2. Super Mario Run
- Application of GaN in RF Electronics
- Does GD32F350 have open-drain mode?
- [Me and Arteli] + Finding new highlights by looking for domestic chips
- EEWORLD University Hall----Application of TI? Interface Chips in Automotive Products
- EEWORLD University ---- IoT Moment: Protocol Standards Driving the Development of IoT