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

边栏推荐
- Day 014 2D array exercise
- In an SQL file, a test table and data are defined above, and you can select* from the test table below
- How to draw an excellent architecture diagram
- 阿里巴巴政委体系-第一章、政委建在连队上
- [beauty of software engineering - column notes] 28 | what is the core competitiveness of software engineers? (next)
- Simplefoc parameter adjustment 3-pid parameter setting strategy
- Character shader exercise
- STM32 MDK (keil5) contents mismatch error summary
- Unity beginner 3 - enemy movement control and setting of blood loss area (2D)
- Qt/PyQt 窗口类型与窗口标志
猜你喜欢

Data unit: bit, byte, word, word length
![[beauty of software engineering - column notes] 21 | architecture design: can ordinary programmers also implement complex systems?](/img/db/ef33a111bcb543f9704706049bccc2.png)
[beauty of software engineering - column notes] 21 | architecture design: can ordinary programmers also implement complex systems?

Unicode私人使用区域(Private Use Areas)
![[robomaster] control RM motor from scratch (2) -can communication principle and electric regulation communication protocol](/img/7c/ba52c7bc11d165892d7390ad8ce298.png)
[robomaster] control RM motor from scratch (2) -can communication principle and electric regulation communication protocol

亚马逊测评自养号是什么,卖家应该怎么做?

数仓分层设计及数据同步问题,,220728,,,,

Tcp/ip five layer reference model and corresponding typical devices and IPv6
![[beauty of software engineering - column notes]](/img/b9/43db3fdfe1d9f08035668a66da37e2.png)
[beauty of software engineering - column notes] "one question and one answer" issue 3 | 18 common software development problem-solving strategies
![[beauty of software engineering - column notes] 25 | what methods can improve development efficiency?](/img/c8/c2d45abbf36b898040f9f1cf6274ff.png)
[beauty of software engineering - column notes] 25 | what methods can improve development efficiency?

Redshift 2.6.41 for maya2018 watermark removal
随机推荐
Dp1332e multi protocol highly integrated contactless read-write chip
(Video + graphic) machine learning introduction series - Chapter 5 machine learning practice
Crawl notes
STM32 detection signal frequency
Use the cloud code to crack the problem of authentication code encountered during login
How to draw an excellent architecture diagram
125kHz wake-up function 2.4GHz single transmitter chip-si24r2h
Process and concept of process
An optimal buffer management scheme with dynamic thresholds paper summary
Simplefoc parameter adjustment 2- speed and position control
The difference between torch.tensor and torch.tensor
Simplefoc parameter adjustment 3-pid parameter setting strategy
[beauty of software engineering - column notes] 27 | what is the core competitiveness of software engineers? (top)
STM32 serial port garbled
[beauty of software engineering - column notes] 22 | how to do a good job in technology selection for the project?
Solve the problem that the disk is full due to large files
阿里巴巴政委体系-第三章、阿里政委与文化对接
STM32 MDK (keil5) contents mismatch error summary
Convert source package to RPM package
Ws2812b color lamp driver based on f407zgt6