Please do not blame me for the poor hand-drawn schematic diagram of the DIY laser engraving machine by others.
The circuit schematic diagram in the experimental exercise is as follows:
The microcontroller source program is as follows:
/*z address definition
50 1=x+,2=x-,3=y+,4=y-
51 High forward and backward steps
52 Low forward and backward steps
53
54/55 character width
56
57 Low light switch
58/59 Laser Intensity
60 x-axis speed
61 y-axis speed
62 Start printing 0,57
63 Pause
64 Stop Sign
65
66 left and right marks
100 Grayscale image data at the beginning
*/
#include #define uint unsigned int #define uchar unsigned char #define N z[60] //X speed #define M z[61] //Y speed sbit a=P1^3; // Stepper motor wiring definition Moving laser head sbit a_=P1^2; sbit b=P1^1; sbit b_=P1^0; sbit xa=P1^4; sbit xa_=P1^5; sbit xb=P1^6; sbit xb_=P1^7; /*sbit a=P1^4; //Stepper motor wiring definition mobile base sbit a_=P1^5; sbit b=P1^6; sbit b_=P1^7; sbit xa=P1^3; sbit xa_=P1^2; sbit xb=P1^1; sbit xb_=P1^0; */ sbit jg=P2^0; sbit led=P2^1; // indicator light uchar xdata z[500]={0};//cache uchar buff[3]; //Serial port buffer uchar x1,x0,y1,y0,cont2=0; uchar xfb=4,yfb=4; //walking flag unsigned char HighRH = 0; //high byte of high level reload value unsigned char HighRL = 0; //low byte of high level reload value unsigned char LowRH = 0; //high byte of low level reload value unsigned char LowRL = 0; //low byte of low level reload value void delayms(uint xms) { uint i,j; for(i=xms;i>0;i--) //i=xms means delay of about xms milliseconds for(j=110;j>0;j--); } /* Configure and start PWM, fr-frequency, dc-duty cycle*/ void ConfigPWM(unsigned int fr, unsigned char dc) { unsigned int high, low; unsigned long tmp; tmp = (11059200/12) / fr; //Calculate the count value required for one cycle high = (tmp*dc) / 100; //Calculate the count value required for the high level low = tmp - high; //Calculate the count value required for the low level high = 65536 - high + 12; //Calculate the high level reload value and compensate for interrupt delay low = 65536 - low + 12; //Calculate the low level reload value and compensate for interrupt delay HighRH = (unsigned char)(high>>8); //Split the high-level reload value into high and low bytes HighRL = (unsigned char)high; LowRH = (unsigned char)(low>>8); // split the low level reload value into high and low bytes LowRL = (unsigned char)low; TMOD &= 0xF0; // Clear the control bit of T0 TMOD |= 0x01; //Configure T0 to mode 1 TH0 = HighRH; //Load T0 reload value TL0 = HighRL; ET0 = 1; // Enable T0 interrupt TR0 = 1; //Start T0 jg = 1; // Output low level, turn off the laser } /* Turn off PWM */ void ClosePWM() { TR0 = 0; //Stop timer 0 ET0 = 0; //Disable timer 0 interrupt jg = 1; // Output low level, turn off the laser } /* T0 interrupt service function, generate PWM output */ void InterruptTimer0() interrupt 1 { if (jg == 1) //When the current output is low level, load the high level value and output high level { TH0 = LowRH; TL0 = LowRL; jg = 0; } else //When the current output is high level, load the low level value and output low level { TH0 = HighRH; TL0 = HighRL; jg = 1; } } void xfor(uint i) //x-axis forward function, how many steps to advance { while(1) { if(xfb==4) { xa=xb=1; xb_=xa_=0; xfb=1; i--; delayms(N); if(i==0){xa=xb=0; break;} } if(xfb==1) { xb=xa_=1; xa=xb_=0; xfb=2; i--; delayms(N); if(i==0){xa_=xb=0; break;} } if(xfb==2) { xa_=xb_=1; xb=xa=0; xfb=3; //Walking flag i--; delayms(N); if(i==0){xa_=xb_=0; break;} } if(xfb==3) { xa_=xb=0; xb_=xa=1; xfb=4; i--; delayms(N); if(i==0){xa=xb_=0; break;} } } } void xbac(uint i) //xxx back function { while(1) { if(xfb==1) { xa_=xb=0; xb_=xa=1; xfb=4; i--; //Walking flag delayms(N); if(i==0){xa=xb_=0; break;} } if(xfb==4) { xa_=xb_=1; xb=xa=0; xfb=3; i--; delayms(N); if(i==0){xa_=xb_=0; break;} } if(xfb==3) { xb=xa_=1; xa=xb_=0; xfb=2; //Walking flag i--; delayms(N); if(i==0){xa_=xb=0; break;} } if(xfb==2) { xa=xb=1; xb_=xa_=0; xfb=1; i--; delayms(N); if(i==0){xa=xb=0; break;} } } } void yfor(uint i) //y-axis forward function { while(1) { switch(yfb) { case 4:{a=b=1; b_=a_=0; yfb=1; i--; delayms(M); if(i==0){a=b=0;break;}} case 1:{b=a_=1; a=b_=0; yfb=2; i--; delayms(M); if(i==0){a_=b=0;break;}} case 2:{a_=b_=1; b=a=0; yfb=3; i--; delayms(M); if(i==0){a_=b_=0;break;}} case 3:{b_=a=1; a_=b=0; yfb=4; i--; delayms(M); if(i==0){a=b_=0;break;}} } if(i==0) break; } } void ybac(uint i) //yy back function { while(1) { switch(yfb) { case 1:{a=b_=1; b=a_=0; yfb=4; i--; delayms(M); if(i==0){a=b_=0;break;}} case 4:{b_=a_=1; a=b=0; yfb=3; i--; delayms(M); if(i==0){a_=b_=0;break;}} case 3:{a_=b=1; b_=a=0; yfb=2; i--; delayms(M); if(i==0){a_=b=0;break;}} case 2:{b=a=1; a_=b_=0; yfb=1; i--; delayms(M); if(i==0){a=b=0;break;}} } if(i==0) break; } } void dazi(uint zik) //print function ******The print function has been changed****** { uint x; jg=0; for(x=0;x while(z[63]); //pause and wait if(z[64]==1) break;//Stop sign to jump out of the loop SBUF=255; // Every time a dot is printed, send 255 to the host computer, which is used to display the progress of the host computer jg=0; //Turn on the laser delayms((z[99+x]*(z[58]*256+z[59]))/100); jg=1; //Turn off the laser if(z[66]==1) { xbac(1); } else { xfor(1); } } if(z[64==1]) z[64]=0; else{yfor(1);} //Y axis advances one line z[62]=0; //One line of printing completed SBUF=1; //Send information, indicating that printing of one line is completed } /* Serial port configuration function, baud-communication baud rate*/ void ConfigUART(unsigned int baud) { SCON = 0x50; //Configure the serial port to mode 1 TMOD &= 0x0F; // Clear the control bit of T1 TMOD |= 0x20; //Configure T1 to mode 2 TH1 = 256 - (11059200/12/32)/baud; //Calculate T1 reload value TL1 = TH1; //initial value equals reload value ET1 = 0; //Disable T1 interrupt ES = 1; // Enable serial port interrupt TR1 = 1; //Start T1 } void chuanlo() interrupt 4 { if(RI) { buff[cont2]=SBUF; //3 bytes each time, address high, address low, data,, cont2++; if(cont2==3) //Every time 3 bytes are received, write the data to the address { z[(buff[0]*256)+buff[1]]=buff[2]; cont2=0; SBUF=0; //*****************Add this line of code here to test it******************************** } RI=0; } if(TI) { TI=0; } } main() { EA=1; P0=0xff; ConfigUART(9600); z[60]=15; //Default parameters z[61]=15; z[56]=1; z[62]=0; jg=0; cont2=0; while(1) { // *****THIS HAS BEEN CHANGED****** if(z[57]==100){ConfigPWM(100, 98);delayms(10);} //Host computer command processing, turn on low-light positioning, frequency 100Hz, duty cycle 98% else if(z[57]==1) jg=0; //Turn on the bright light else { ClosePWM(); delayms(10);} if(cont2!=0) led=0; else led=1;//Indicates whether communication is available if(z[50]==1){xfor(z[51]*256+z[52]);z[50]=0;}//x+ if(z[50]==2){xbac(z[51]*256+z[52]);z[50]=0;}//x- if(z[50]==3){yfor(z[51]*256+z[52]);z[50]=0;}//y+ if(z[50]==4){ybac(z[51]*256+z[52]);z[50]=0;}//y- if(z[62]) //Start printing flag { dazi(z[54]*256+z[55]); } } }
Previous article:Simulation and source code of a simple automatic tracking car based on single chip microcomputer control
Next article:51 MCU simulation SPI bus communication program and proteus simulation
- 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?
- CATL releases October battle report
- Battery industry in October 2024: growth momentum remains unabated!
- Mercedes-Benz will launch the eCitaro equipped with NMC4 batteries to provide high energy density and long life
- Many companies have announced progress on solid-state batteries. When will solid-state batteries go into mass production?
- Xsens Sirius Series Inertial Sensors Enable 3D Inertial Navigation in Harsh Environments
- Infineon's Automotive Landscape: From Hardware to Systems
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- Optimization of DSP Hardware Implementation (Part 2) - Resource Optimization When Conjugation Appears in Complex Multiplication
- Providing antenna flexibility and high performance for mid-range and high-end smartphones
- Schematic diagram - Use PMOS to build an anti-reverse connection circuit. Are all the schemes in the figure feasible? What is the principle? Welcome to discuss.
- What are VOH and VOL?
- Broadband power divider simulation verification + physical parameter comparison analysis
- MOTOROLA 8-bit MCU Selection Guide (Part 1)
- [Free trial of Pingtouge Bluetooth Mesh Gateway Development Kit] + Development environment preparation and use
- lib file link mechanism
- What are the advantages of HK7833 compared to ASM1117-3.3V? Why does the former cost 1 yuan, while the latter only costs 0.1 yuan?
- Based on AM335X development board ARM Cortex-A8——NAND FLASH version core board usage instructions