当前位置:网站首页>DC motor speed regulation system based on 51 single chip microcomputer (use of L298)
DC motor speed regulation system based on 51 single chip microcomputer (use of L298)
2022-07-29 08:11:00 【Half life fireworks I blurred】
The design requirements
A key control start / stop it
One key controls the forward and reverse rotation
Two keys control the end of deceleration
The first digit of the four digit nixie tube shows positive and negative 、1 Indicates forward rotation 、0 Indicates inversion , The last three digits show the speed value
use AT89C51 Single chip microcomputer , And DC motor driver L298
L298 Of IN1、IN2 control OUT1、OUT2 Output high and low level
IN3、IN4 control OUT3、OUT4 Output high and low level
Make the two ends of the motor have a voltage difference
Two DC motors can be connected externally .
ENA、ENB Enable the high level of two motor control ports to be effective .
The module used has digital tube display 、 Press to get 、 Timer 0.
Nixie tube display part
#include <REGX52.H>
#include "Delay.h"
sbit we2=P2^1;
sbit we3=P2^2;
sbit we4=P2^3;
void Nixie(Number)
{
switch(Number) // Bit code output
{
case 0:
we2=0;
P0=0x3f; // Segment code output
Delay(1); // Show for a period of time
we2=1;
we3=0;
P0=0x3f; // Segment code output
Delay(1); // Show for a period of time
we3=1;
we4=0;
P0=0x3f;Delay(1);we4=1; break; // Segment code output
case 1:
we2=0;
P0=0x3f; // Segment code output
Delay(1); // Show for a period of time
we2=1;
we3=0;
P0=0x5b; // Segment code output
Delay(1); // Show for a period of time
we3=1;
we4=0;
P0=0x6d;Delay(1);we4=1;
break;
case 2:
we2=0;
P0=0x3f; // Segment code output
Delay(1); // Show for a period of time
we2=1;
we3=0;
P0=0x6d; // Segment code output
Delay(1); // Show for a period of time
we3=1;
we4=0;
P0=0x3f;Delay(1);we4=1;break; // Segment code output
case 3:
we2=0;
P0=0x3f; // Segment code output
Delay(1); // Show for a period of time
we2=1;
we3=0;
P0=0x07; // Segment code output
Delay(1); // Show for a period of time
we3=1;
we4=0;
P0=0x6d;Delay(1);we4=1;break; // Segment code output
case 4:
we2=0;
P0=0x06; // Segment code output
Delay(1); // Show for a period of time
we2=1;
we3=0;
P0=0x3f; // Segment code output
Delay(1); // Show for a period of time
we3=1;
we4=0;
P0=0x3f;Delay(1);we4=1;break; // Segment code output
}
}
Press the key to get the part
#include <REGX52.H>
#include "Delay.h"
unsigned char Key()// Key shake elimination and release detection
{
unsigned char KeyNumber=0;
if(P1_0==0){Delay(20);while(P1_0==0);Delay(20);KeyNumber=1;}// Get key value
if(P1_2==0){Delay(20);while(P1_2==0);Delay(20);KeyNumber=3;}
if(P1_3==0){Delay(20);while(P1_3==0);Delay(20);KeyNumber=4;}
return KeyNumber;
}
Timer configuration section
#include <REGX52.H>
void Timer0_Init(void)
{
TMOD &= 0xF0; // Configure timer mode
TMOD |= 0x01; // Set the timer 0 Pattern
TL0 = 0x06; // Set initial value of timing 250us Create an interrupt
TH0 = 0xFF; // Set initial value of timing
TF0 = 0; // eliminate TF0 sign
TR0 = 1; // Timer 0 Start timing
ET0=1;
EA=1;
PT0=0;
}
Main function and interrupt service function
#include <REGX52.H>
#include "Delay.h"
#include "Key.h"
#include "Nixie.h"
#include "Timer0.h"
sbit IN1=P2^4;
sbit IN2=P2^5;
sbit EN=P3^7;
sbit we1=P2^0;
unsigned char Counter,Compare=0;
unsigned char KeyNum;
unsigned int x=0,Speed=0;
void main()
{
Timer0_Init();
while(1)
{
if(P1_1==0){Delay(20);while(P1_1==0);Delay(20);x++;if(x==2){x=0;}}
KeyNum=Key();
if(KeyNum==3)
{
Speed++;
if(Speed==1){Compare=25;} // Set the comparison value , change PWM Duty cycle
if(Speed==2){Compare=50;}
if(Speed==3){Compare=75;}
if(Speed==4){Compare=100;}
}
if(KeyNum==4)
{
Speed--;
if(Speed==3){Compare=75;}// Set the comparison value , change PWM Duty cycle
if(Speed==2){Compare=50;}
if(Speed==1){Compare=25;}
if(Speed==0){Compare=0;}
}
we1=0;// Turn on the tab
if(x==1)
{
P0=0x3f; // Segment code output
Delay(1); // Show for a period of time
we1=1;
}
else
{
P0=0x06; // Segment code output
Delay(1); // Show for a period of time
we1=1;
}
Nixie(Speed);
}
}
void Timer0_Routine() interrupt 1
{
TL0 = 0x06; // Reload value setting 250us
TH0 = 0xFF;
Counter++;
if(Counter==100); // The variation range of the count value is limited to 0~99
{
Counter=0;
}
if(Counter<Compare) // The count value is less than the comparison value
{
if(KeyNum==1)
{
EN=~EN;
}
if(x==1)
{
IN1=0;
IN2=1;
}
else
{
IN1=1;
IN2=0;
}
}
else// Set when the count value is greater than the comparison value
{
IN1=1;
IN2=1;
// IN1=0;
// IN2=0;
}
}
Here I want to thank someone at a certain station UP It's his video that makes me learn SCM
边栏推荐
- 【学术相关】为什么很多国内学者的AI的论文复现不了?
- CDM - code division multiplexing (easy to understand)
- 亚马逊测评自养号是什么,卖家应该怎么做?
- Use the cloud code to crack the problem of authentication code encountered during login
- torch.nn.functional.one_hot()
- Qt/PyQt 窗口类型与窗口标志
- [academic related] why can't many domestic scholars' AI papers be reproduced?
- [cryoelectron microscope] relion4.0 pipeline command summary (self use)
- 125kHz wake-up function 2.4GHz single transmitter chip-si24r2h
- Stm32ff030 replaces domestic MCU dp32g030
猜你喜欢
亚马逊测评自养号是什么,卖家应该怎么做?
Some tools, plug-ins and software links are shared with you~
MySQL rownum implementation
C language data type
Alibaba political commissar system - Chapter 4: political commissars are built on companies
Official tutorial redshift 01 basic theoretical knowledge and basic characteristics learning
Unity Shader学习(六)实现雷达扫描效果
[beauty of software engineering - column notes] 21 | architecture design: can ordinary programmers also implement complex systems?
V-Ray 5 acescg workflow settings
阿里巴巴政委体系-第一章、政委建在连队上
随机推荐
下推分析的限制
Character shader exercise
Some thoughts on growing into an architect
Research on autojs wechat: the final product of wechat automatic information sending robot (effective demonstration)
Compatible with cc1101/cmt2300-dp4301 sub-1g wireless transceiver chip
亚马逊测评自养号是什么,卖家应该怎么做?
Simplefoc parameter adjustment 2- speed and position control
Unicode私人使用区域(Private Use Areas)
NFC two-way communication 13.56MHz contactless reader chip -- si512 replaces pn512
torch.nn.functional.one_ hot()
Solving linear programming problems based on MATLAB
Rotation in model space and rotation in world space
[note] the art of research - (tell a good story and argument)
阿里巴巴政委体系-第一章、政委建在连队上
[skill accumulation] common expressions when writing emails
[beauty of software engineering - column notes] 22 | how to do a good job in technology selection for the project?
TCP——滑动窗口
Inclination monitoring solution of Internet of things
Unity beginner 3 - enemy movement control and setting of blood loss area (2D)
Simplefoc+platformio stepping on the path of the pit