current position:Home>Stc89c52rc controls the stepping motor, and the program card is in the first line of main,
Stc89c52rc controls the stepping motor, and the program card is in the first line of main,
2022-02-04 16:50:18 【CSDN Q & A】
The procedure is as follows :
#include<reg52.h>#define uint unsigned int#define uchar unsigned charsbit maicong=P2^5;// Motor pulse output , Initial low level sbit fangxiang=P2^6;// Motor direction output , Low level after initialization sbit EN=P2^7;// Motor enable , Initial high level sbit XWKG=P2^4;// Initial position confirmation port , Low level active , call ZIJIAN Subroutines sbit k0=P1^0;// start-up , call START Subroutines sbit k1=P1^1;// stop it , call TINGZHI Subroutines sbit k2=P1^2;// Speed up , call SUDUZ Subroutines sbit k3=P1^3;// Speed down , call SUDUJ Subroutines sbit k4=P1^4;// Step size plus , call BUCHANGZ Subroutines sbit k5=P1^5;// Step minus , call BUCHANGJ Subroutines uint tt=200;// If you need ??uint step=1100;// ditto uint num=18;void keyscan();// Keyboard scanner , Program completion void delayms(uint ms);// Millisecond variable delay program void delayus(uint us);// Microsecond variable delay program , Used for low-level output delay , The frequency is adjusted by changing the low level .void delay(uint us);// Microsecond delay program , Used for pulse high-level output delay void baidong();//void ZIJIAN();// Program completion void START();// Corresponding k0void TINGZHI();// Corresponding k1void SUDUZ();// Corresponding k2void SUDUJ();// Corresponding k3void BUCHANGZ();// Corresponding k4void BUCHANGJ();// Corresponding k5void JIUQIANYISHEN();// Corresponding k6void main(void){ _ maicong = 0;_ fangxiang = 1; IT1 = 1; //set INT1 int type (1:Falling only 0:Low level) EX1 = 1; //enable INT1 interrupt EA = 1; //open global interrupt switch ZIJIAN(); while(1);// Wait for the key command , here PWM=0;DIR=0.}/* Lower level external interrupt 2, Responsible for key operation , Start now 、 stop it 、 Acceleration and deceleration 、 Step addition and subtraction 、 Start of automatic running program */void exint1() interrupt 2 //(location at 0013H){ keyscan(); }void keyscan(){ while(1) { if(k0==0) START(); else if(k1==0) TINGZHI();// stop it , Return to the initial position else if(k2==0) SUDUZ();// Speed increase else if(k3==0) SUDUJ();// Speed down else if(k4==0) BUCHANGZ();// Step size increases else if(k5==0) BUCHANGJ();// Step minus else if(k6==0) JIUQIANYISHEN();// Nine is shallow and one is deep else if(XWKG==0) ZIJIAN();// The initial position switch is on , Motor commutation , turn }}void ZIJIAN() { EN=0;// Motor enable , Can rotate freely fangxiang=1; while(XWKG==0) { maicong=1; delay(1); maicong=0; delayus(tt); } while(XWKG==1) { fangxiang=0; maicong=1; delay(1); maicong=0; delayus(tt);// It is necessary to determine the rotation angle with the limit switch } EN=1;// Motor enable , Cannot rotate freely delayms(50);} void START() { EN=0; step=1100;//50*55 Maximum moving steps , It is possible to trigger the limit switch delayms(50); while(1) { baidong(); }}void TINGZHI(){ while(1); }void SUDUZ(){ tt=tt-5; if(tt<1) tt=1; while(k2==0);}void SUDUJ(){ tt=tt+5; if(tt>255) tt=255; while(k3==0);}void BUCHANGZ(){ step=step+5; if(step>2750) step=2750; while(k4==0);}void BUCHANGJ(){ step=step-5; if(step<50) step=50; while(k5==0);}/* External interrupt 0( highest ), Responsible for interrupting external interrupts 2, That is, the trigger of the limit switch */void exint0() interrupt 0 //(location at 0003H){ while(1);} void baidong() { EN=0;// Motor enable , Can rotate freely while(step--)//step The value range is less than the subdivision value *55 { maicong=1;// initial pwm The output is low level , When you start, it will become high ( Common Yin connection ) delay(1);// Time delay 4 Microsecond , The pulse width is 5 Microsecond maicong=0;// Low level delayus(tt);// Time delay 9 Microsecond , Low level width 10 Microsecond , Adjust this delay value to change the speed } fangxiang=~fangxiang;// Commutation }void delay(uint xus) { uint m; for(m=0;m<xus;++m); }void delayus(uint tt) { uint n; for(n=0;n<tt;++n);// Variable delay program ??? }void delayms(uint xms) { uint x,y; for(x=0;x<xms;++x) for(y=0;y<110;++y); }
Take the answer :
Hello , I am a little assistant who answers every question , So sorry , This time, you have to answer all your questions , The panel of technical experts timed out and did not answer for you
The number of times to answer all questions deducted from this question , Will answer with questions VIP Experience card (1 A chance to answer every question 、 Shopping malls buy physical books and enjoy 95 A discount ) It will be reissued to your account in the form of .
Because all questions must be answered VIP The experience card is only valid for 1 God , When you need it 【 Direct messages 】 Contact me , I'll reissue it for you .
Other answers 2:
PS: Question and answer VIP Annual pass 【 Limited time bonus :IT Technical books are free 】, Learn more >>> https://vip.csdn.net/askvip?utm_source=1146287632
copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/02/202202041650160275.html
The sidebar is recommended
- How about the performance comparison of query acceleration in maxcompute?
- What is the workflow of spark streaming and how is it different from storm?
- What is the application scenario of streaming data writing in maxcompute?
- What are the source databases supported by DTS self built Mysql to synchronize to RDS MySQL?
- What is the process of establishing a connection between an application and a database?
- What are the target databases supported by DTS self built Mysql to synchronize to RDS MySQL?
- What are the differences and connections between the ML and mllib packages of spark?
- What are the benefits of database connection pooling?
- What are the application scenarios of query acceleration in maxcompute?
- What are the prerequisites for DTS self built Mysql to synchronize to RDS MySQL?
guess what you like
-
How does MySQL query statements?
-
What are the similarities and differences between yarn cluster and yarn client?
-
What are the restrictions on the source database of DTS self built MySQL synchronized to RDS MySQL?
-
What is the difference between map and mappartitions?
-
What database server performance analysis methods and commands does MySQL have?
-
What are the other limitations of DTS self built MySQL synchronization to RDS MySQL?
-
What are the advantages of real-time data processing based on maxcompute?
-
What is the difference between MySQL blob and text?
-
What is the description of the special case of DTS self built MySQL synchronizing to RDS MySQL?
-
What types of locks are there in MySQL?
Random recommended
- DTS self built MySQL synchronizes to RDS. What synchronization architectures does MySQL support?
- Android source code analysis Series 1 - activity startup and interface loading, HTML5 mobile terminal development interview
- What are the similarities and differences between worker and excutor?
- Android source code analysis: implementation principle of lrucache caching mechanism, self-evaluation of Android development resume
- MySQL field name batch case conversion, Java work in 2021 may be more difficult to find
- DTS self built MySQL synchronizes to RDS. What SQL operations does MySQL support synchronization?
- MySQL Optimization: Performance Analysis of like and = in where, Java Architect growth express updated to
- What is ECS (Elastic Compute service)?
- What are the differences among the three Android annotation frameworks dagger, hilt and Koin?, Retrofit benefits
- What is the difference between MySQL hash index and B + tree?
- Why ECS?
- What are the permission requirements for DTS self built Mysql to synchronize to RDS MySQL database account?
- What is the difference between MySQL inner connection, left connection and right connection?
- What are the two shared variables provided by spark?
- What does optimizing shard number mean?
- What are the four components of Hadoop?
- DTS self built MySQL is synchronized to RDS MySQL database. What is the method of account creation and authorization?
- What are the main functional components of ECS?
- What are the common billing methods for ECS?
- What is the relationship between serverless and logging?
- How many layers does the MySQL logical architecture diagram have?
- What is the function of shard number?
- Why do we need MapReduce?
- What are the three paradigms of database?
- What are the common developer tools for calling ECS APIs?
- Configuration and description of source database information synchronized from DTS self built Mysql to RDS MySQL?
- What are the trends and challenges of serverless?
- What are the MySQL permission tables?
- What is the process of installing httpd service and PHP in ganglia?
- What is the role of Alibaba cloud toolkit?
- What is the log centralization of serverless applications?
- Configuration and description of target database information synchronized from DTS self built Mysql to RDS MySQL?
- HTML common tag examples
- Laravel statement reports an error. How to solve it?
- Please answer the questions about # C #!
- Use pagination JS paging plug-in paging, get the number of pages, but click the next page without refreshing the data
- C + + keyboard input, sorting, list output
- PCIe TX / RX pin constraint problem
- On the grid position and width of Tkinter
- Android modifies the interface displayed on the white screen through the theme of activity