This single chip microcomputer is STC89C52RC, this program is applied to step motor--28BYJ, a small stepper motor, with a power supply voltage of DC5V. It can be directly connected to the single chip microcomputer and driven by the UL2003 driver chip. The digital tube is a common cathode interface, which controls the start/stop, forward and reverse rotation, acceleration and deceleration of the stepper motor, and has a running and conversion status display.
It is a good routine for beginners.
Physical map:
The simulation schematic is as follows
The microcontroller source program is as follows:
/*This microcontroller is STC89C52RC, this program is applied to step motor--28BYJ, a small stepper motor,
The power supply voltage is DC5V, which can be directly connected to the microcontroller and driven by the UL2003 driver chip. The digital tube is a common cathode interface. */
#include #define uchar unsigned char //data macro definition #define uint unsigned int #define A P10 // #define _A P11 //Stepper motor pulse interface #define B P12 // #define _B P13 //Stepper motor pulse interface uchar su_du=0; //speed bit fang_xiang=0; //direction bit qi_dong=0; //Start flag /************************************************************************/ #include sbit DU = P2^6; //digital tube segment selection sbit WE = P2^7; //digital tube segment selection //Common cathode digital tube segment selection table 0-9 uchar code shu_ma[]= {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F,}; /************************************************************************/ /*==================================== Function: delay(uint z) Parameter: z delay setting in milliseconds, value range 0-65535 Return value: None Description: 12T/Fosc11.0592M millisecond delay =======================================*/ void delay(uint z) { uint x,y; for(x = z; x > 0; x--) for(y = 114; y > 0 ; y--); } /*==================================== Function: display(uchar i) Parameter: i displays the value, the value range is 0-255 Return value: None Description: Three-digit common cathode digital tube dynamic display =======================================*/ void display(uchar i) //data processing { uchar bai, shi, ge; // bai = i / 100; //236 / 100 = 2 // shi = i % 100 / 10; // 236 % 100 / 10 = 3 ge = i; // % 10; // 236 % 10 = 6 /* First digit of digital tube P0 = 0XFF; // Clear broken code WE = 1; //Open the bit select latch P0 = 0XFE; //1111 1110 WE = 0; // latch bit select data DU = 1; //Open the segment select latch P0 = shu_ma[bai];// DU = 0; // latch segment selection data delay(5); //The second digital tube P0 = 0XFF; // Clear broken code WE = 1; //Open the bit select latch P0 = 0XFD; //1111 1101 WE = 0; // latch bit select data DU = 1; //Open the segment select latch P0 = shu_ma[shi]; // DU = 0; // latch segment selection data delay(5);*/ /********* The third digital tube*/ P0 = 0XFF; // Clear broken code WE = 1; //Open the bit select latch P0 = 0XFB; //1111 1011 WE = 0; // latch bit select data DU = 1; //Open the segment select latch P0 = shu_ma[ge]; // DU = 0; // latch segment selection data delay(5); } void yanshi2(uint a) //delay program { while(a--); } uchar an_jian() //Key detection, P3.0, P3.1, P3.2, P3.3 are connected to 4 keys respectively { if((P3&0x0f)!=0x0f)//As long as one key of P3 is pressed, the key value will be returned after a delay. { yanshi2(20000); if((P3&0x0f)!=0x0f) { return P3&0x0f; } } return P3&0x0f; } void yanshi() //Stepper motor delay time { uint sd1 = 0; sd1=8000+5753*(10-su_du); // The larger the su_du value, the shorter the period and the higher the frequency while(sd1--) { if((P3&0x0f)!=0x0f)return; //Judge whether a key is pressed in the delay, and return to the main function directly if it is pressed } } void bu_jin() //Each time the stepper motor is called, it moves one step in the specified direction { static char j=1; //Set the starting speed to 1. if(fang_xiang) //Judge the direction bit, if it is 1, cycle in positive phase sequence, { j++; if(j==5)j=1; } else { j--; if(j==0)j=4; //Otherwise, loop in reverse order } switch(j) //Select different voltage combinations according to the number of beats { case 1: A=1;B=1;_A=0;_B=0;yanshi(); //ab 1100 break; case 2: A=0;B=1;_A=1;_B=0;yanshi(); //a~b 0110 break; case 3: A=0;B=0;_A=1;_B=1;yanshi(); //a~b~0011 break; case 4: A=1;B=0;_A=0;_B=1;yanshi(); //ab~ 1001 break; } } void main() { P14=0; //Direction sign P15=0; //Start flag while(1) { switch(an_jian()) //key processing { case 0x0e: //The first button is pressed to invert the button status and start/stop qi_dong=!qi_dong; P15=qi_dong; //status indication break; case 0x0d: //The second button is pressed, the speed increases if(su_du<9) su_du++; //speed increase break; case 0x0b: //The third button is pressed, the speed decreases if(su_du>0) su_du--; //speed reduction break; case 0x07: //The fourth button is pressed to invert the button state and change direction fang_xiang=!fang_xiang; P34=fang_xiang; //Direction indicator light break; } if(qi_dong) //Start button is 1 { bu_jin(); //Stepper motor } else P1=0X0F; //Stop state, all pulse output ports stop outputting display(su_du); //digital tube display function ……………………
Previous article:Final version of the single-chip four-story elevator control system design (including simulation + report + program source code)
Next article:Single chip fully automatic washing machine program + simulation + schematic design debugging and analysis
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Theory and Implementation of Narrow-Band IF Sampling Based on DSP_C54X
- [TI recommended course] #Boost and buck-boost DCDC converters help wireless charging design#
- The microcontroller has its own EEPROM. Is it necessary to add an external EEPROM? Small-volume and high-capacity EEPROMs are more expensive!
- I am facing a problem during the debian burning process of the Sipeed LicheeRV 86 development board?
- FIFO problem of vivado2018.1
- Regarding the peripheral circuit design of the LCD segment code screen, please provide relevant development information. Thank you.
- How big a power line is needed for a 250KW submersible pump?
- STM32f030 development code
- 【GD32L233C-START Review】4. Porting RT-Thread to GD32L233
- Analog input and output buffers