当前位置:网站首页>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

边栏推荐
- [experience] relevant configuration of remote connection to intranet server through springboard machine
- Character shader exercise
- Simplefoc parameter adjustment 1-torque control
- Compatible with cc1101/cmt2300-dp4301 sub-1g wireless transceiver chip
- Mysql rownum 实现
- CentOS deploy PostgreSQL 13
- Huawei wireless device configuration uses WDS technology to deploy WLAN services
- 125kHz wake-up function 2.4GHz single transmitter chip-si24r2h
- Low cost 2.4GHz wireless transceiver chip -- ci24r1
- Limitations of push down analysis
猜你喜欢
![[lecture notes] how to do in-depth learning in poor data?](/img/7d/5767c078600bd88b7d2146069f4f40.jpg)
[lecture notes] how to do in-depth learning in poor data?

A problem encountered in SQL interview

阿里巴巴政委体系-第四章、政委建在连队上

Dynamic thresholds buffer management in a shared buffer packet switch paper summary

Random lottery turntable wechat applet project source code
![[freeze electron microscope] analysis of the source code of the subtomogram alignment function of relion4.0 (for self use)](/img/fe/0efdd151f9661d5cd06a79b7266754.png)
[freeze electron microscope] analysis of the source code of the subtomogram alignment function of relion4.0 (for self use)

TCP——滑动窗口

Simplefoc parameter adjustment 2- speed and position control
![[beauty of software engineering - column notes] 26 | continuous delivery: how to release new versions to the production environment at any time?](/img/65/79f876b62fa3db421e5038a2445b83.png)
[beauty of software engineering - column notes] 26 | continuous delivery: how to release new versions to the production environment at any time?

Tb6600+stm32f407 test
随机推荐
2.4G band wireless transceiver chip si24r1 summary answer
[密码学实验] 0x00 安装NTL库
C language interview preparation I (about understanding Department)
Simple calculator wechat applet project source code
torch.nn.functional.one_hot()
TCP——滑动窗口
Dp1332e multi protocol highly integrated contactless read-write chip
[robomaster] control RM motor from scratch (2) -can communication principle and electric regulation communication protocol
Dynamically load data
Redshift 2.6.41 for maya2018 watermark removal
STM32 MDK (keil5) contents mismatch error summary
Stm8s003 domestic substitute for dp32g003 32-bit microcontroller chip
Official tutorial redshift 01 basic theoretical knowledge and basic characteristics learning
Crawl expression bag
[beauty of software engineering - column notes] "one question and one answer" issue 2 | 30 common software development problem-solving strategies
[cryoelectron microscope | paper reading] a feature guided, focused 3D signal permutation method for subtogram averaging
[beauty of software engineering - column notes] 28 | what is the core competitiveness of software engineers? (next)
Inclination monitoring solution of Internet of things
数字人民币时代隐私更安全
Qt/pyqt window type and window flag