|
基于51單片機(jī)的XY軸激光打印機(jī)電路原理圖,內(nèi)含51單片機(jī)原理圖相關(guān)的庫文件,以及該打印機(jī)的測試代碼。
原理圖
單片機(jī)源程序如下:
- #include<reg52.h>
- #include<math.h>
- #include<data.h>
- #include<delay.h>
- #include<delayms.h>
- #define work_pl 2000 //計時器初值
- #define dl 71.5 //脈沖當(dāng)量
- #define wid 10.0 //數(shù)字字寬
- #define wid_1 130.0 //漢字字寬
- #define rad 15 //所打印圓半徑
- #define len 33 //所打印圓的圓心基點
- #define high 1.73205 //根號3對應(yīng)常數(shù)
- #define on 0 //激光開關(guān)
- #define off 1
- sbit x_move=P2^4;
- sbit x_direct=P2^5;
- sbit y_move=P2^2;
- sbit y_direct=P2^3;
- sbit light=P2^0; //激光開關(guān)
- sbit turnlight=P2^1; //打印開始或結(jié)束
- sbit x_stp=P1^1; //限位開關(guān)
- sbit y_stp=P1^0;
- sbit start=P1^3; //啟動開關(guān)
- sbit contin=P1^4; //暫停
- // 脈沖發(fā)生器
- void time0make(unsigned char a,unsigned char b)
- {
- TMOD=0x01;
- TH0=(65536-work_pl)/256;
- TL0=(65536-work_pl)%256;
- EA=1;
- TR0=1;
- while(1)
- {
- if(TF0)
- {
- TF0=0;
- if(a==0)
- {
- x_direct=b;
- x_move=!x_move;
- TH0=(65536-work_pl)/256;
- TL0=(65536-work_pl)%256;
- while(!TF0);
- x_move=!x_move;
- TF0=0;
- return;
- }
- else
- {
- y_direct=b;
- y_move=!y_move;
- TH0=(65536-work_pl)/256;
- TL0=(65536-work_pl)%256;
- while(!TF0);
- y_move=!y_move;
- TF0=0;
- return;
- }
- TH0=(65536-work_pl)/256;
- TL0=(65536-work_pl)%256;
- while(!TF0)
- TF0=0;
- return;
- }
- }
- }
- //直線插補(bǔ)
- void math_zhixian(float x_e,float y_e)
- {
- float f0,x0,y0,sum;
- unsigned char a,b;
- if(x_e>=0&&y_e>=0) //相對坐標(biāo)象限判斷
- {a=1;b=1;}
- else if(x_e<=0&&y_e>=0)
- {a=0;b=1;}
- else if(x_e<=0&&y_e<=0)
- {a=0,b=0;}
- else
- {a=1,b=0;};
- x0=fabs(dl*x_e);
- y0=fabs(dl*y_e);
- f0=0;
- sum=x0+y0;
- while(sum>=0)
- {
- if(f0>=0)
- {
- time0make(0,a);
- f0=f0-y0;
- sum=sum-1;
- }
- else
- {
- time0make(1,b);
- f0=f0+x0;
- sum=sum-1;
- }
- }
- }
- //第一象限逆圓弧插補(bǔ)
- void math_yuanhu(float x0,float y0,float x1,float y1)
- {
- float f0,sum,temp;
- f0=0;
- x0=dl*x0;
- y0=dl*y0;
- x1=dl*x1;
- y1=dl*y1;
- sum=x0+y1;
- temp=sum;
- while(sum>0) //第一象限
- {
- if(f0>=0)
- {
- time0make(0,0);
- f0=f0-2*x0+1;
- x0=x0-1;
- sum=sum-1;
- }
- else
- {
- time0make(1,1);
- f0=f0+2*y0+1;
- y0=y0+1;
- sum=sum-1;
- }
- }
- sum=temp;
- f0=0;
- while(sum>0) //第二象限
- {
- if(f0>=0)
- {
- time0make(1,0);
- f0=f0-2*y0+1;
- y0=y0-1;
- sum=sum-1;
- }
- else
- {
- time0make(0,0);
- f0=f0-2*x0+1;
- x0=x0-1;
- sum=sum-1;
- }
- }
- sum=temp;
- f0=0;
- while(sum>0) //第三象限
- {
- if(f0>=0)
- {
- time0make(0,1);
- f0=f0+2*x0+1;
- x0=x0+1;
- sum=sum-1;
- }
- else
- {
- time0make(1,0);
- f0=f0-2*y0+1;
- y0=y0-1;
- sum=sum-1;
- }
- }
- sum=temp;
- f0=0;
- while(sum>0) //第四象限
- {
- if(f0>=0)
- {
- time0make(1,1);
- f0=f0+2*y0+1;
- y0=y0+1;
- sum=sum-1;
- }
- else
- {
- time0make(0,1);
- f0=f0+2*x0+1;
- x0=x0+1;
- sum=sum-1;
- }
- }
- }
- //回到初始點
- void init0()
- {
- delay();
- while(1)
- {
- time0make(0,0);
- if(x_stp==0)
- {
- if(x_stp==0)
- break;
- }
- }
- while(1)
- {
- time0make(1,0);
- if(y_stp==0)
- {
- if(y_stp==0)
- break;
- }
- }
- }
- void main() //主函數(shù)
- {
- char p,m,order;
- int k;
- float i,j,length;
- EA=1;
- IT0=1; //脈沖觸發(fā)外部中斷控制
- // start=1;
- // while(start)
- // {
- // delay();
- // if(start==0)
- // break;
- // }
- light=off;
- delayms();
- turnlight=off;
- init0(); //歸零
- i=len+rad;
- math_zhixian(i,len+40); //預(yù)留打印數(shù)字和漢字的高度
- light=on; //打印圓
- delay();
- turnlight=on;
- math_yuanhu(rad,0,0,rad);
- light=off;
- delay();
- turnlight=off;
- length=rad*2*high;
- i=0-(rad+length/2);
- j=0-rad;
- math_zhixian(i,j);
- i=length/2; //打印等邊三角形
- j=length*high/2;
- light=on;
- delay();
- turnlight=on;
- math_zhixian(i,j);
- i=length/2;
- j=0-length*high/2;
- math_zhixian(i,j);
- i=0-length;
- j=0;
- math_zhixian(i,j);
- light=off;
- delay();
- turnlight=off;
- i=0-20;
- j=0-10;
- math_zhixian(i,j);
- for(m=0;m<12;m++)
- {
- order=xuehao[m];
- if(order==6)
- {
- k=0;
- for(;;) //打印數(shù)字 6
- {
-
- p=num6[k];
- if(p==0)
- break;
- k++;
- i=num6[k];
- i=(2/wid)*i;
- k++;
- j=num6[k];
- j=0-(2/wid)*j; //Y取反
- k++;
- if(p==1)
- {light=on;
- delay();
- turnlight=on;}
- else if(p==2)
- {light=off;
- delay();
- turnlight=off;}
- math_zhixian(i,j);
- }
- }
- else if(order==4)
- {
- k=0;
- for(;;) //打印數(shù)字 4
- {
-
- p=num4[k];
- if(p==0)
- break;
- k++;
- i=num4[k];
- i=(2/wid)*i;
- k++;
- j=num4[k];
- j=0-(2/wid)*j;
- k++;
- if(p==1)
- {light=on;
- delay();
- turnlight=on;}
- else if(p==2)
- {light=off;
- delay();
- turnlight=off;}
- math_zhixian(i,j);
- }
- }
- else if(order==3)
- {
- k=0;
- for(;;) //打印數(shù)字 3
- {
-
- p=num3[k];
- if(p==0)
- break;
- k++;
- i=num3[k];
- i=(2/wid)*i;
- k++;
- j=num3[k];
- j=0-(2/wid)*j;
- k++;
- if(p==1)
- {light=on;
- delay();
- turnlight=on;}
- else if(p==2)
- {light=off;
- delay();
- turnlight=off;}
- math_zhixian(i,j);
- }
- }
- else if(order==2)
- {
- k=0;
- for(;;) //打印數(shù)字2
- {
-
- p=num2[k];
- if(p==0)
- break;
- k++;
- i=num2[k];
- i=(2/wid)*i;
- k++;
- j=num2[k];
- j=0-(2/wid)*j;
- k++;
- if(p==1)
- {light=on;
- delay();
- turnlight=on;}
- else if(p==2)
- {light=off;
- delay();
- turnlight=off;}
- math_zhixian(i,j);
- }
- }
- else if(order==1)
- {
- k=0;
- for(;;) //打印數(shù)字 1
- {
-
- p=num1[k];
- if(p==0)
- break;
- k++;
- i=num1[k];
- i=(2/wid)*i;
- k++;
- j=num1[k];
- j=0-(2/wid)*j;
- k++;
- if(p==1)
- {light=on;
- delay();
- turnlight=on;}
- else if(p==2)
- {light=off;
- delay();
- turnlight=off;}
- math_zhixian(i,j);
- }
- }
- else if(order==0)
- {
- k=0;
- for(;;) //打印數(shù)字 0
- {
-
- p=num0[k];
- if(p==0)
- break;
- k++;
- i=num0[k];
- i=(2/wid)*i;
- k++;
- j=num0[k];
- j=0-(2/wid)*j;
- k++;
- if(p==1)
- {light=on;
- delay();
- turnlight=on;}
- else if(p==2)
- {light=off;
- delay();
- turnlight=off;}
- math_zhixian(i,j);
- }
- }
- else
- continue;
- }
- light=off;
- delay();
- turnlight=off;
- i=0-5*12; //移動到打印字的起點且與數(shù)字同一個邊開始
- j=0-20;
- math_zhixian(i,j);
- k=0;
- for(;;) //打印姓名首字
- {
-
- p=cai[k];
- if(p==0)
- break;
- k++;
- i=cai[k];
- i=(15/wid_1)*i;
- k++;
- j=cai[k];
- j=0-(15/wid_1)*j;
- k++;
- if(p==1)
- {light=on;
- delay();
- turnlight=on;}
- else if(p==2)
- {light=off;
- delay();
- turnlight=off;}
- math_zhixian(i,j);
- }
- k=0;
- for(;;) //打印姓名第二字
- {
-
- p=ying[k];
- if(p==0)
- break;
- k++;
- i=ying[k];
- i=(15/wid_1)*i;
- k++;
- j=ying[k];
- j=0-(15/wid_1)*j;
- k++;
- if(p==1)
- {light=on;
- delay();
- turnlight=on;}
- else if(p==2)
- {light=off;
- delay();
- turnlight=off;}
- math_zhixian(i,j);
- }
- k=0;
- for(;;) //打印姓名第三字
- {
-
- p=tao[k];
- if(p==0)
- break;
- k++;
- i=tao[k];
- i=(15/wid_1)*i;
- k++;
- j=tao[k];
- j=0-(15/wid_1)*j;
- k++;
- if(p==1)
- {light=on;
- delay();
- turnlight=on;}
- else if(p==2)
- {light=off;
- delay();
- turnlight=off;}
- math_zhixian(i,j);
- }
- while(1);
- }
- void stop() interrupt 0
- {
- char x;
- x=1;
- delay();
- while(x)
- {
- if(contin==0)
- {
- delay();
- if(contin==0)
- break;
- }
- }
- }
復(fù)制代碼
所有資料51hei提供下載:
test.7z
(57.72 KB, 下載次數(shù): 69)
2020-4-20 14:47 上傳
點擊文件名下載附件
內(nèi)含原理圖及 相關(guān)ad庫文件和測試代碼
|
評分
-
查看全部評分
|