[Resource Download] The download address is as follows:
https://docs.qq.com/doc/DTlRSd01BZXNpRUxl
51 motor control system design-L298N-key-potentiometer
This design is composed of STC89C52 single-chip circuit + L298N motor drive circuit + button circuit + potentiometer speed control circuit + power supply circuit.
1. The speed of motor 1 can be adjusted in real time through the potentiometer.
2. The forward and reverse rotation of motor 2 can be controlled by pressing the button. That is, when the button 1 is pressed, the motor 2 rotates forward. Press again, motor 2 reverses. Press again, motor 2 stops.
3. Press button 2 to set the forward speed of motor 3: press button 2 once, motor 3 rotates at low speed, press it again, motor 3 rotates at medium speed, press it again, motor 3 rotates at high speed. (The specific speed is determined by Tongwang Technology)
#include<reg52.h> //包含头文件,一般情况不需要改动,头文件包含特殊功能寄存器的定义
#include<stdio.h>
#include "delay.h"
sbit key1 =P2^0;
sbit key2 =P2^1;
unsigned long time_20ms=0; //定时器计数
sbit IN1=P1^1; //小车驱动引脚
sbit IN2=P1^2;
sbit IN3=P1^3;
sbit IN4=P1^4;
sbit ENA=P1^0;
sbit ENB=P1^5;
unsigned char pwmRigh=1; //pwm调整
unsigned char pwmLeft=1;
unsigned char Flag1 = 0;//运行标志
unsigned char Flag2 = 0;//运行标志
unsigned char rekey = 0; //按键按下
void Init_Timer0(void);//
void main (void)