基于單片機的CK6163數(shù)控車床控制系統(tǒng)設計.zip,基于,單片機,CK6163,數(shù)控車床,控制系統(tǒng),設計
#include
#include
#define uint unsigned int
#define uchar unsigned char
#define com8255 XBYTE[0x007f]//8255端口地址
#define PA8255 XBYTE[0x007c]
#define PB8255 XBYTE[0x007d]
#define PC8255 XBYTE[0x007e]
uchar code F_rotation1[]={0x80,0xc0,0x40,0x60,0x20,0xa0};//步進電機正反轉控制狀態(tài)表
uchar code B_rotation1[]={0xa0,0x20,0x60,0x40,0xc0,0x80};
uchar code F_rotation2[]={0x08,0x0c,0x04,0x06,0x02,0x0a};
uchar code B_rotation2[]={0x0a,0x02,0x06,0x04,0x0c,0x08};
uchar code F_rotation3[]={0x88,0xcc,0x44,0x66,0x22,0xaa};
uchar code B_rotation3[]={0xaa,0x22,0x66,0x44,0xcc,0x88};
uchar code F_rotation4[]={0x8a,0xc2,0x46,0x64,0x2c,0xa8};
uchar code B_rotation4[]={0xa8,0x2c,0x64,0x46,0xc2,0xa8};
uchar code table[16] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//數(shù)碼管數(shù)字顯示表
uchar code table_d[16] = {0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
void xianshi();//數(shù)碼管顯示函數(shù)
void jianpan();//鍵盤功能實現(xiàn)函數(shù)
uchar keyscan();//鍵盤掃描函數(shù)
int A,W,H;
int X3=0, Z3=0, X4=-50,Z4=-50;//加工參數(shù)設置
int X5, Z5, F1,j0;
uchar i0=0,k0=0;
int X0=0,Z0=-50,X1=0,Z1=0,X2=-50,Z2=-50;
int F=0,X,Z;
uchar n,m=0,k=0;
uchar key,g,count;
void delay(t)//延時函數(shù)
{
uint i,j;
for(i=0;i0)
{
if(F1<0)
{
PA8255=B_rotation2[i0];
F1=F1+Z5;
i0++;A++;H++;
if(i0==6)
i0=0;
}
else
{
PA8255=B_rotation1[k0];
F1=F1-X5;
k0++;W++;H++;
if(k0==6)
k0=0;
}
j0--;
}
}
void RS_move()//第三象限圓弧順時針加工函數(shù)
{
if(n=0)
{
PA8255=B_rotation2[m];
F=F-2*X+1;
X=X-1;
m++;A++;H++;
if(m==6)
m=0;
}
else
{
PA8255=B_rotation1[k];
F=F-2*Z+1;
Z=Z-1;
k++;W++;H++;
if(k==6)
k=0;
}
n++;
}
}
void iti() interrupt 1//中斷函數(shù)
{
TH0=(65536-8000)/256;
TL0=(65536-8000)%256;
count++;
if(count==15)
{
count=0;
jianpan();
}
}
void main()
{
TMOD=0x01;
TH0=(65536-8000)/256;
TL0=(65536-8000)%256;
TR0=1;
ET0=1;
EA=0;
A=0;W=0;
com8255=0x80;
PA8255=0x00;
X1=X1-X0;Z1=Z1-Z0;
X2=X2-X0;Z2=Z2-Z0;
Z=Z1;X=X1;H=0;
X5=X3-X4;Z5=Z3-Z4;
j0=X5+Z5;
while(1)
{
xianshi();
key=keyscan();
if(key==1)
{
A=0;W=0;
}
else if(key==2)
EA=0;
else if(key==5)
EA=1;
}
}
uchar keyscan()
{
uchar Y[]={0xfe,0xfd,0xfb,0xf7}, X[]={0xd0,0xb0,0x70},ii=0,jj=0,temp;
P1=Y[ii];
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(2);
if(temp!=0xf0)
for(;jj<3;jj++)
if(temp==X[jj])
return 3*ii+jj;
}
ii++;
P1=Y[ii];
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(2);
if(temp!=0xf0)
for(;jj<3;jj++)
if(temp==X[jj])
return 3*ii+jj;
}
ii++;
P1=Y[ii];
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(2);
if(temp!=0xf0)
for(;jj<3;jj++)
if(temp==X[jj])
return 3*ii+jj;
}
ii++;
P1=Y[ii];
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(2);
if(temp!=0xf0)
for(;jj<3;jj++)
if(temp==X[jj])
return 3*ii+jj;
}
}
void jianpan()
{
if(key==8)
{
com8255=0x80;
PA8255=B_rotation2[g++];
A++;
if(g==6)g=0;
}
else if(key==11)
{
com8255=0x80;
PA8255=F_rotation2[g++];
A--;
if(g==6)g=0;
}
else if(key==7)
{
com8255=0x80;
PA8255=B_rotation1[g++];
W++;
if(g==6)g=0;
}
else if(key==10)
{
com8255=0x80;
PA8255=F_rotation1[g++];
W--;
if(g==6)g=0;
}
else if(key==6)
{
com8255=0x80;
PA8255=B_rotation3[g++];
W++;
A++;
if(g==6)g=0;
}
else if(key==9)
{
com8255=0x80;
PA8255=F_rotation3[g++];
W--;
A--;
if(g==6)g=0;
}
else if(key==3)
{
com8255=0x80;
PA8255=F_rotation4[g++];
W--;
A++;
if(g==6)g=0;
}
else if(key==4)
{
com8255=0x80;
PA8255=F_rotation4[g++];
W++;
A--;
if(g==6)g=0;
}
else
{
if(H<100)
RS_move();
else
// S_move()
;
}
}
void xianshi()
{
PB8255=0x00;
PB8255=0x5b;
PC8255=7;
delay(1);
if(W>0){
PB8255=0x00;
PB8255=0x40;
PC8255=6;
delay(1);
PB8255=0x00;
PB8255=table[W%1000000/100000];
PC8255=5;
delay(1);
PB8255=0x00;
PB8255=table[W%1000000%100000/10000];
PC8255=4;
delay(1);
PB8255=0x00;
PB8255=table[W%1000000%100000%10000/1000];
PC8255=3;
delay(1);
PB8255=0x00;
PB8255=table_d[W%1000000%100000%10000%1000/100];
PC8255=2;
delay(1);
PB8255=0x00;
PB8255=table[W%1000000%100000%10000%1000%100/10];
PC8255=1;
delay(1);
PB8255=0x00;
PB8255=table[W%1000000%100000%10000%1000%100%10];
PC8255=0;
delay(1);
PB8255=0x00;}
else{
PB8255=0x00;
PB8255=0x3f;
PC8255=6;
delay(1);
PB8255=0x00;
PB8255=table[-W/100000];
PC8255=5;
delay(1);
PB8255=0x00;
PB8255=table[-W%100000/10000];
PC8255=4;
delay(1);
PB8255=0x00;
PB8255=table[-W%100000%10000/1000];
PC8255=3;
delay(1);
PB8255=0x00;
PB8255=table_d[-W%100000%10000%1000/100];
PC8255=2;
delay(1);
PB8255=0x00;
PB8255=table[-W%100000%10000%1000%100/10];
PC8255=1;
delay(1);
PB8255=0x00;
PB8255=table[-W%100000%10000%1000%100%10];
PC8255=0;
delay(1);
PB8255=0x00;}
PB8255=0x76;
PC8255=0x0f;
delay(1);
PB8255=0x00;
PB8255=0x40;
PC8255=0x0e;
delay(1);
PB8255=0x00;
PB8255=table[A/100000];
PC8255=0x0d;
delay(1);
PB8255=0x00;
PB8255=table[A%100000/10000];
PC8255=0x0c;
delay(1);
PB8255=0x00;
PB8255=table[A%100000%10000/1000];
PC8255=0x0b;
delay(1);
PB8255=0x00;
PB8255=table_d[A%100000%10000%1000/100];
PC8255=0x0a;
delay(1);
PB8255=0x00;
PB8255=table[A%100000%10000%1000%100/10];
PC8255=0x09;
delay(1);
PB8255=0x00;
PB8255=table[A%100000%10000%1000%100%10];
PC8255=0x08;
delay(1);
}