MCU four-wire stepper motor driver function:
When SW1 is pressed, the stepper motor rotates forward, and when SW2 is pressed, the stepper motor rotates reversely. The rotation speed and rotation angle of each pulse can be adjusted arbitrarily according to the source code.
The program reference source code is as follows:
/C language program:/
#include #define uchar unsigned char #define uint unsigned int uchar table_begin; uint maichong; //pulse uchar zhuansu; //speed uchar flag; //direction sbit key_fuwei=P3^0; //Reset key sbit key_z=P3^1; //Forward key sbit key_f=P3^2; //Reverse key sbit key_jia=P3^3; //Accelerator key sbit key_jian=P3^6; //deceleration key sbit A1=P2^0; sbit A2=P2^1; sbit A3=P2^2; sbit A4=P2^3; void display(); void delayms(xms); void delay(uchar x) {undefined uchar i,j; //delay for(i=0;i } void fuwei(void) //reset {undefined flag=2; zhuansu=0; } /*void Display(void) //display {undefined unsigned char b1, b2; b1=zhuansu/10; b2=zhuansu%10; if(flag == 0) //0 P0=0x71; //Display F else P0=0x79; A1=0; delayms(3); A1=1; P0=0x40; A2=0; //Display-- delayms(3); A2=1; P0=table2[b1]; A3=0; //Display tens digit delayms(3); A3=1; P0=table2[b2]; A4=0; delayms(3); //display the units digit A4=1; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 } */ void display() {undefined uchar b1,b2,b3,b4; if(flag0) P0=0x71; //Display F else P0=0x79; if(flag1) P0=0x7c; //display b else P0=0x71; b1=10; b2=0x3f; b3=zhuansu/10; b4=zhuansu%10; //P0=table2; A1=0; //P2.0 delay(1); A1=1; P0=b2; A2=0; //P2.1 delay(1); A2=1; P0=table2[b3]; A3=0; //P2.3 delay(1); A3=1; P0=table2[b4]; A4=0; //P2.4 delay(1); A4=1; } void key() //Key scan {undefined if(key_fuwei0) { delay(5); if(key_fuwei0) fuwei(); } if(key_z0) { delay(5); if(key_z0) {undefined flag=0; zhuansu=10; while(key_z0); } } if(key_f0) {undefined delay(5); if(key_f0) { flag=1; zhuansu=10; while(key_f0); } } if(key_jia0) { delay(5); if(key_jia0) {undefined zhuansu++; if(zhuansu21) zhuansu=20; while(key_jia0); } } if(key_jian0) { delay(5); if(key_jian0) {undefined zhuansu–; if(zhuansu<=0) zhuansu=0; while(key_jian==0); } } } void dispose() //Pulse function {undefined switch (zhuansu) {undefined case 0: flag=2; break; case 1: maichong=300; break; case 2: maichong=295; break; case 3: maichong=290; break; case 4: maichong=280; break; case 5: maichong=260; break; case 6: maichong=240; break; case 7: maichong=200; break; case 8: maichong=180; break; case 9: maichong=160; break; case 10: maichong=120; break; case 11: maichong=80; break; case 12: maichong=70; break; case 13: maichong=60; break; case 14: maichong=40; break; case 15: maichong=35; break; case 16: maichong=30; break; case 17: maichong=25; break; case 18: maichong=20; break; case 19: maichong=15; break; case 20: maichong=10; break; } if(flag0) table_begin=0; else if(flag1) table_begin=4; } void zhuandong(void) {undefined uint i,j; if(zhuansu>0&&zhuansu<=20) {undefined for(j=0+table_begin;j<4+table_begin;j++) {undefined P1=table1[j]; for(i=0;i } } } …………………… …
Previous article:51 MCU 12864 large LCD screen Tetris
Next article:MCU drives DS1302 clock + 1602 LCD
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- Europe's three largest chip giants re-examine their supply chains
- Breaking through the intelligent competition, Changan Automobile opens the "God's perspective"
- The world's first fully digital chassis, looking forward to the debut of the U7 PHEV and EV versions
- Design of automotive LIN communication simulator based on Renesas MCU
- When will solid-state batteries become popular?
- Adding solid-state batteries, CATL wants to continue to be the "King of Ning"
- The agency predicts that my country's public electric vehicle charging piles will reach 3.6 million this year, accounting for nearly 70% of the world
- U.S. senators urge NHTSA to issue new vehicle safety rules
- Giants step up investment, accelerating the application of solid-state batteries
- Guangzhou Auto Show: End-to-end competition accelerates, autonomous driving fully impacts luxury...
- Basic principles and application methods of power supply noise filters
- 7" Touch Screen Monitor Stand for Raspberry Pi SmartiPi Touch 2
- What does transparent transmission in communication networks mean?
- Flexible platform for networking automotive electronic systems
- Up to $180,000! Apple temporarily issues large bonuses to prevent employees from leaving Meta
- [Rawpixel RVB2601 development board trial experience] 5. Key interrupt test
- Xunwei IMX6Q development board QT system Modbus transplantation and use (I)
- Is there any chip that can convert analog signal (potentiometer and DC voltage) into PWM dimming signal?
- Oscilloscope Current
- Infrared thermometer