The microcontroller source program is as follows:
//Digital tube high position------low position
//Four buttons to control the stepper motor: forward, reverse, plus 1, minus 1
//When the power is on, the motor starts, and the digital tube displays the minimum speed gear 1. The plus and minus gears can be displayed through the digital tube. The motor adopts single and double eight-beat mode.
//There are 10 motor speeds in total, and the speed can be adjusted by pressing the button
//When the motor rotates forward, the highest digital tube displays 0, and when it rotates reverse, it displays 1
#include #define uchar unsigned char #define uint unsigned int #define led P0 //digital tube segment selection #define haha P2 sbit s1 = P1^0; sbit s2 = P1^1; sbit s3 = P3^0; sbit s4 = P3^1; sbit s5 = P3^2; //button definition, s1 forward, s2 reverse, s3 plus 1, s4 minus 1 sbit wei3 = P2^3;sbit wei2 = P2^2;sbit wei1 = P2^1;sbit wei0 = P2^0;//digital tube bit selection definition sbit a = P2^7;sbit b = P2^6;sbit c = P2^5;sbit d = P2^4; // Definition of pulse signal input terminal uchar code tab[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff}; // Common anode digital tube drive signal 0---9, no display uchar code time_counter[10][2]={{0xda,0x1c},{0xde,0xe4},{0xe1,0xec},{0xe5,0xd4},{0xe9,0xbc}, //9.7 ----1ms {0xed,0xa4},{0xf1,0x8c},{0xf5,0x74},{0xf9,0x5c},{0xfc,0x18}}; uchar code qudong[8]={0x80,0xc0,0x40,0x60,0x20,0x30,0x10,0x90}; uchar num1 = 0; //Control the excitation signal variable uchar num2 = 8; char k=0; //Addition and subtraction gear control, 1 is the minimum gear char pause=1; //Save the previous speed when paused, the default setting is 1 when powered on bit flag1 = 0; //initial forward, forward and reverse rotation flag uchar buf[4]={0,10,0,0}; //digital tube display cache, forward, no display, no display, display 1 gear, high----low //=================================Timer 0/1 initialization function================================= void T0_T1_init() { TMOD = 0x11; //Timer 0/1 both work in mode 1, 16-bit timing mode TH1 = time_counter[k-1][0]; TL1 = time_counter[k-1][1]; //Timer 1, 10ms timing for stepper motor speed control TR1 = 0; ET1= 1; // Enable timer interrupt EA = 1; // Enable general interrupt } //==================================ms level delay function====================================== void delay1m(uint x) { uint i,j; for(i=0;i } void display() { wei3=1;wei2=1;wei1=1;wei0=0;led = tab[buf[3]];delay1m(1);led=0xff; wei3=1;wei2=1;wei1=0;wei0=1;led = tab[buf[2]];delay1m(1);led=0xff; wei3=1;wei2=0;wei1=1;wei0=1;led = tab[buf[1]];delay1m(1);led=0xff; wei3=0;wei2=1;wei1=1;wei0=1;led = tab[buf[0]];delay1m(1);led=0xff; } //==================================Main function============================================== void main() { T0_T1_init(); buf[1] = 10; // not displayed while(1) { display(); if(s1 == 0) { delay1m(3); if(s1 == 0) { flag1 = 0; //Forward buf[0] = 0; //The highest bit displays 0 // haha = 0x00; // stop } while(!s1) display(); } if(s2 == 0 ) { delay1m(3); if(s2 == 0) { flag1 = 1; // reverse buf[0] = 1; //The highest bit displays 1 // haha = 0x00; // stop } while(!s2) display(); } if(s3 == 0) //speed up 1 level { delay1m(3); if(s3 == 0) { k++; TR1=1; if(k > 10 ) { k = 1; } buf[2]= k/10; buf[3]= k%10; } while(!s3) display(); } if(s4 == 0) //Speed reduction by 1 level { delay1m(3); if(s4 == 0) { k--; TR1=1; if(k <= 0) { k = 10; } buf[2]= k/10; buf[3]= k%10; } while(!s4) display(); } if(s5==0) { delay1m(3); if(s5==0) { if(TR1==1) { pause=k; k=0; TR1=0; a=b=c=d=0; } else if(TR1==0) { k=pause; TR1=1; } buf[2]= k/10; buf[3]= k%10; while(!s5) display(); } } } } //===================================Timer 1 interrupt function, used for pulse frequency control====================================== void time1_interrupt()interrupt 3 { static num1 = 0; static num2 = 0; TH1 = time_counter[k-1][0]; TL1 = time_counter[k-1][1]; //Timer 1, timing 1 is used for stepper motor speed control if(flag1 == 0) //Forward { switch(num1) { case 0:a = 1;b = 0;c = 0;d = 0;break; case 1:a = 1;b = 1;c = 0;d = 0;break; case 2:a = 0;b = 1;c = 0;d = 0;break; case 3:a = 0;b = 1;c = 1;d = 0;break; case 4:a = 0;b = 0;c = 1;d = 0;break; case 5:a = 0;b = 0;c = 1;d = 1;break; case 6:a = 0;b = 0;c = 0;d = 1;break; case 7:a = 1;b = 0;c = 0;d = 1;break; } num1++; if(num1 == 8)num1 = 0; } else //reverse { switch(num2) { case 0:a = 1;b = 0;c = 0;d = 1;break; case 1:a = 0;b = 0;c = 0;d = 1;break; case 2:a = 0;b = 0;c = 1;d = 1;break; case 3:a = 0;b = 0;c = 1;d = 0;break; case 4:a = 0;b = 1;c = 1;d = 0;break; case 5:a = 0;b = 1;c = 0;d = 0;break; case 6:a = 1;b = 1;c = 0;d = 0;break; case 7:a = 1;b = 0;c = 0;d = 0;break; } num2++; if(num2 == 8)num2 = 0; } } 1. This design uses STC89C51/52 (compatible with AT89S51/52, AT89C51/52, optional) microcontroller as the main controller; · 2. The motor uses a DC-5V stepper reduction motor (step angle 5.625°, reduction ratio 1/64); 3. Integrated chip ULN2003 as motor driver; 4. Button functions: Button 1 forward, Button 2 reverse, Button 3 speed up, Button 4 speed down, Pause/Start · 5. The first digit of the LED digital tube displays the forward and reverse rotation of the motor, and the third and fourth digits display the gear number of the motor running speed; 6. Five red LEDs, one for power indication and four for motor speed indication. Partial Program //Digital tube high position------low position //Four buttons to control the stepper motor: forward, reverse, plus 1, minus 1 //When the power is on, the motor starts, and the digital tube displays the minimum speed gear 1. The plus and minus gears can be displayed through the digital tube. The motor adopts single and double eight-beat mode. //There are 10 motor speeds in total, and the speed can be adjusted by pressing the button //When the motor rotates forward, the highest digital tube displays 0, and when it rotates reverse, it displays 1 #include #define uchar unsigned char #define uint unsigned int #define led P0 //digital tube segment selection #define haha P2 sbit s1 = P1^0; sbit s2 = P1^1; sbit s3 = P3^0; sbit s4 = P3^1; sbit s5 = P3^2; //button definition, s1 forward, s2 reverse, s3 plus 1, s4 minus 1 sbit wei3 = P2^3;sbit wei2 = P2^2;sbit wei1 = P2^1;sbit wei0 = P2^0;//digital tube bit selection definition sbit a = P2^7;sbit b = P2^6;sbit c = P2^5;sbit d = P2^4; // Definition of pulse signal input terminal uchar code tab[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff}; // Common anode digital tube drive signal 0---9, no display uchar code time_counter[10][2]={{0xda,0x1c},{0xde,0xe4},{0xe1,0xec},{0xe5,0xd4},{0xe9,0xbc}, //9.7 ----1ms
Previous article:STC MCU + DM134 to realize LED multi-segment control
Next article:Based on 52 single chip microcomputer control encoder display program
- Popular Resources
- Popular amplifiers
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
- 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
- How does the SPI bus work?
- Xiaomi Mi Band 3 Disassembly
- 17 "Ten Thousand Miles" Raspberry Pi Car——VSCode Learning (Compiling and Debugging)
- MOS tube VBE1606\VBN1603 in the design of driving circuit of medical temperature control blanket control system
- Could you please tell me what brand this chip is?
- A few questions about 4G signal indicators. In what range are these values considered good signal quality? In addition, some experts have suggested directly...
- Chip company recruitment: power hardware engineer
- C6000 DSP code online compilation problem
- Research on the information performance advantages of Suruide in-vehicle Ethernet hardware and applications
- [Synopsys IP Resources] Prototyping as a Service (PaaS): Breaking through chip design process bottlenecks and simplifying the path to innovation