Function: The stepper motor starts in an accelerated mode, and after the speed reaches the maximum speed specified by the program, it keeps running at a constant speed for a period of time, and then starts to decelerate.
The demo program is run in the same way until the stepper motor stops rotating. The K1 key controls the running of the demo program. D1-D4 on the stepper motor module can indicate the working status.
/******************************************************************/
/* */
/* ME300B MCU Development System Demonstration Program - Stepper Motor Acceleration and Deceleration Running Program */
/* */
/* When the stepper motor starts, the speed gradually accelerates from slow to fast. */
/* Stepper motor runs at a constant speed */
/* Stepper motor gradually decelerates from fast to slow and stops */
/* Website http://www.elecfans.com */
/******************************************************************/
#include
#include
#define uchar unsigned char
#define uint unsigned int
sbit K1=P1^4;
uchar co
//uchar co
uchar rate ;
/**************************************** *********************/
/*
/* Delay
/* 11.0592MHz clock,
/*
/****************** *******************************************/
void delay()
{
uchar k;
uint s;
k = rate;
do
{
for(s = 0; s <500; s++);
}while(--k);
}
/****************** ******************************************/
/*
/*Stepper motor forward rotation
/*
/******************************************** ****************/
void motor_ffw()
{
uchar i;
for (i=0; i<8; i++) //One cycle rotates 30 degrees
{
P1 = FFW[i ]; //Get data
delay(); //Adjust speed
}
}
/************************************************************
*
*Stepper motor operation
*
*********************************************************/
void motor_turn()
{
uchar x;
rate=0x10;
x=0xf0;
do
{
motor_ffw(); //acceleration
rate--;
}while(rate!=0x01);
do
{
motor_ffw(); //Constant speed
x--;
}while(x!=0x01);
do
{
motor_ffw(); //Deceleration
rate++;
}while(rate!=0x10);
}
/************************************************************
*
* Main program
*
**********************************************************/
main()
{
P1=0xf0;
while(1)
{
P1=0xf0;
if(K1==0)
{
motor_turn();
}
}
}
/****************************************************** *******/
Previous article:The volatile keyword in C51
Next article:51 MCU CAN bus communication program
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Low-power Qorvo chips enhance connectivity and reliability for new Luna smart home system
- Highlights of Bluetooth Mesh Technology
- ST NUCLEO-G071RB evaluation serial port printing and LED flashing
- Network port problem
- What is an ISO Connector?
- B-L4S5I-IOT01A development board has WIFI, Bluetooth, NFC, microphone, distance measurement, magnetometer, thermometer and hygrometer.
- [NXP Rapid IoT Review] Study various documents
- cc2640 data processing problem
- Summary of Common/Uncommon IOT Protocols
- There are many "tools" that are not fully understood.