📄 keyboard.c
字号:
#include <p30f4011.h>
#include "adr_port_define.h"
#include "extern_define.h"
unchar z_encodermange()
{
if(motor_jingei==0)motor_jingeiliang=1; //1um
else if(motor_jingei==1)motor_jingeiliang=2; //2um
else if(motor_jingei==2)motor_jingeiliang=5; //5um
else if(motor_jingei==3)motor_jingeiliang=10;
else if(motor_jingei==4)motor_jingeiliang=20;
else if(motor_jingei==5)motor_jingeiliang=30;
else if(motor_jingei==6)motor_jingeiliang=50;
}
keyboard()
{
operator_mode=0;
switch(operator_mode)
{
case 0: //manual
switch(SW)
{
case 1: //Z DOWN
motor_jingei=7;
if(motor_jingei==7) //high speed
{
TRISE=0X00;
if(KEYUPDOWN==0)
{
pluse_counter=0;
last_pluse_counter=pluse_counter;
PWMCON1=0X0401; //enable pwm out pwm_A RE0
PWM_ON=1; //enable pwm
T2_ON=1;
KEYUPDOWN=SW;
}
else //z_encoder_pluse 为发出的pluse
{
if(xx_photo==3)
{
if(z_postion_staus==0)z_postion_staus=1;
}
z_encoder_pluse=z_encoder_pluse-pluse_counter+last_pluse_counter;
z_postion=z_encoder_pluse/5;
if(z_postion<1)z_postion=0;
last_pluse_counter=pluse_counter;
KEYUPDOWN=SW;
}
break;
}
else
{
if(KEYUPDOWN==0) //RE5 方向受管理器影响变低,note!!!
{
if(z_postion_staus==0)z_postion_staus=1;
pluse_counter=0;
TRISE=0X00;
// RE5=1; //motor jingei=5um
z_encodermange();
motor_jingeiliang=1;
motor_jingei_encoder=motor_jingeiliang*5; //unit :encoder
total_pluse=motor_jingei_encoder;
PWMCON1=0X0401; //enable pwm out pwm_A RE0
PWM_ON=1; //enable pwm
T2_ON=1; //enable timer2
z_postion=z_postion-motor_jingeiliang; //unit:mm
KEYUPDOWN=SW; //motor_jingeiliang=1um,2um,5um...
}
break;
}
break;
case 2: //Y 向后
if(KEYUPDOWN==0)
{
LR_num.bits.LR3=1;
LR_num.bits.LR4=0;
if(xx_photo==3)//y_postion=var
{
// y_postion=100;
if(y_postion_staus==0)
y_postion_staus=1;
}
KEYUPDOWN=SW;
}
break;
case 3: //X 向左
if(KEYUPDOWN==0)
{
LR_num.bits.LR6=1;
LR_num.bits.LR5=0;
KEYUPDOWN=SW;
}
break;
case 4: //Y 后定点
if(KEYUPDOWN==0)
{
y_endpos=158;//var;
y_postion=y_endpos;
y_totallength=y_endpos;
Y_DIRECTION=1; //y on first postion
if(xx_photo==1)
{
y_totallength_staus=1;
}
if(xx_photo==3)
{
if(y_postion_staus==0)
y_postion_staus=1;
}
KEYUPDOWN=SW;
}
break;
case 5: //Y 间距小
if(KEYUPDOWN==0)
{
y_distance=y_distance-1;
if(xx_photo==1)
y_distance_staus=1;
KEYUPDOWN=SW;
}
break;
case 6: // 冷却启动
if(KEYUPDOWN==0)
{
LED_num.bits.LED7=1;
LED_num.bits.LED4=0;
LR_num.bits.LR2=0;
KEYUPDOWN=SW;
}
break;
case 7: //冷却停止
if(KEYUPDOWN==0)
{
LED_num.bits.LED4=1;
LED_num.bits.LED7=0;
LR_num.bits.LR2=1;
KEYUPDOWN=SW;
}
break;
case 8: //Z向上
motor_jingei=7;
if(motor_jingei==7) //high speed
{
TRISE=0X00;
if(KEYUPDOWN==0)
{
pluse_counter=0;
PWMCON1=0X0410; //enable pwm out pwm_B RE1
PWM_ON=1; //enable pwm
T2_ON=1;
last_pluse_counter=pluse_counter;
KEYUPDOWN=SW;
}
else
{
if(xx_photo==3)
{
if(z_postion_staus==0)z_postion_staus=1;
}
z_encoder_pluse=z_encoder_pluse+pluse_counter-last_pluse_counter;
z_postion=z_encoder_pluse/5;
last_pluse_counter=pluse_counter;
KEYUPDOWN=SW;
}
break;
}
else
{
if(KEYUPDOWN==0)
{
TRISE=0X00;
if(z_postion_staus==0)z_postion_staus=1;
pluse_counter=0;
// RE5=0;
z_encodermange();
motor_jingeiliang=1;
motor_jingei_encoder=motor_jingeiliang*5; //unit :encoder
total_pluse=motor_jingei_encoder;
PWMCON1=0X0410; //enable pwm out pwm_B RE1
PWM_ON=1; //enable pwm
T2_ON=1; //enable timer2
z_postion=z_postion+motor_jingeiliang; //unit:mm
KEYUPDOWN=SW;
}
break;
}
break;
case 9: //Y 向前
if(KEYUPDOWN==0)
{
LR_num.bits.LR4=1; //off y backwards
LR_num.bits.LR3=0;
if(xx_photo==3)//y_postion=var
{
// y_postion=200;
if(y_postion_staus==0)
y_postion_staus=1;
}
KEYUPDOWN=SW;
}
break;
case 10: //X 向右 OK
if(KEYUPDOWN==0)
{
LR_num.bits.LR5=1; //off x leftwards
LR_num.bits.LR6=0;
KEYUPDOWN=SW;
}
break;
case 11: //Y 前定点
if(KEYUPDOWN==0)
{
var=0;
y_firstpos=0;
Y_DIRECTION=0; //y on first postion
y_postion=y_firstpos;
y_totallength=y_firstpos;
if(xx_photo==1)
{
y_totallength_staus=1;
}
if(xx_photo==3)
{
if(y_postion_staus==0)
y_postion_staus=1;
}
KEYUPDOWN=SW;
}
break;
case 12: //Y间距大
if(KEYUPDOWN==0)
{
y_distance=y_distance+1;
if(xx_photo==1)
y_distance_staus=1;
KEYUPDOWN=SW;
}
break;
case 13: //主轴启动
if(KEYUPDOWN==0)
{
LED_num.bits.LED6=1;
LED_num.bits.LED3=0;
LR_num.bits.LR1=0;
KEYUPDOWN=SW;
}
break;
case 14: //主轴停止
if(KEYUPDOWN==0)
{
LED_num.bits.LED3=1;
LED_num.bits.LED6=0;
LR_num.bits.LR1=1;
KEYUPDOWN=SW;
}
break;
case 15: //home
if(KEYUPDOWN==0)
{
z_encoder_pluse=jingei_times*motor_jingeiliang;
z_postion=z_encoder_pluse/5; //read current encoder mm
if(xx_photo==3)
{
if(z_postion_staus==0)
z_postion_staus=1;
KEYUPDOWN=SW;
}
}
break;
case 16: //回待机点
if(KEYUPDOWN==0)
{
if(xx_photo==3)
{
if(y_postion_staus==0)
y_postion_staus=1;
}
KEYUPDOWN=SW;
}
break;
case 17: //X往复
if(KEYUPDOWN==0)
{
LED_num.bits.LED8=1; //ctrl led output ON
count=count+1;
if(count==1) SW_flag=1;
if(count==2)
{
count=0;
SW_flag=0;
LED_num.bits.LED8=0; //X stop
LR_num.bits.LR6=1; //clsoe
LR_num.bits.LR5=1; //close
X_END=1;
}
KEYUPDOWN=SW;
}
break;
case 18: //平面
if(KEYUPDOWN==0)
{
plane=1;
LED_num.bits.LED1=1; //开槽
LED_num.bits.LED0=0; //平面
KEYUPDOWN=SW;
}
break;
case 19: //开槽
if(KEYUPDOWN==0)
{
plane=2;
LED_num.bits.LED0=1; //平面
LED_num.bits.LED1=0; //开槽
KEYUPDOWN=SW;
}
break;
case 20: //oil 启动
if(KEYUPDOWN==0)
{
LED_num.bits.LED5=1;
LED_num.bits.LED2=0;
LR_num.bits.LR0=0;
KEYUPDOWN=SW;
}
break;
case 21: //oil 停止
if(KEYUPDOWN==0)
{
LED_num.bits.LED2=1;
LED_num.bits.LED5=0;
LR_num.bits.LR0=1;
KEYUPDOWN=SW;
}
break;
case 22: //TAB
if(KEYUPDOWN==0)
{
KEYUPDOWN=SW;
TAB=1;
}
break;
case 23: //+
if(KEYUPDOWN==0) //ADD
{
if(xx_photo==1)
{
if(ADDR==1)
{
LCD_jingei_staus=1;
jingei_times=jingei_times+1;
if(jingei_times>254)jingei_times=254;
else if(jingei_times<1)jingei_times=1;
}
}
else if(xx_photo==2)
{
if(ADDR==2)
{
z_waitpostion_staus=1;
z_waitpostion=z_waitpostion+1;
if(z_waitpostion>999998)z_waitpostion=999998;
else if(z_waitpostion<1)z_waitpostion=0;
}
else if(ADDR==1)
{
guangmo_times_staus=1;
guangmo_times=guangmo_times+1;
if(guangmo_times>254)guangmo_times=254;
else if(guangmo_times<1)guangmo_times=1;
}
}
else if(xx_photo==4)
{
if(ADDR==1)
{
z_up_speed_staus=1;
z_up_speed=z_up_speed+1;
if(z_up_speed>9998)z_up_speed=9998;
else if(z_up_speed<1)z_up_speed=0;
}
else if(ADDR==2)
{
z_down_speed_staus=1;
z_down_speed=z_down_speed+1;
if(z_down_speed>9998)z_down_speed=9998;
else if(z_down_speed<1)z_down_speed=1;
}
}
KEYUPDOWN=SW;
}
break;
case 24: //-
if(KEYUPDOWN==0) //reduce
{
if(xx_photo==1)
{
if(ADDR==1)
{
LCD_jingei_staus=1;
jingei_times=jingei_times-1;
if(jingei_times>254)jingei_times=254;
else if(jingei_times<1)jingei_times=0;
}
}
else if(xx_photo==2)
{
if(ADDR==2)
{
z_waitpostion_staus=1;
z_waitpostion=z_waitpostion-1;
if(z_waitpostion>999998)z_waitpostion=999998;
else if(z_waitpostion<1)z_waitpostion=0;
}
else if(ADDR==1)
{
guangmo_times_staus=1;
guangmo_times=guangmo_times-1;
if(guangmo_times>254)guangmo_times=254;
else if(guangmo_times<1)guangmo_times=1;
}
}
else if(xx_photo==4)
{
if(ADDR==1)
{
z_up_speed_staus=1;
z_up_speed=z_up_speed-1;
if(z_up_speed>9998)z_up_speed=9998;
else if(z_up_speed<1)z_up_speed=1;
}
else if(ADDR==2)
{
z_down_speed_staus=1;
z_down_speed=z_down_speed-1;
if(z_down_speed>9998)z_down_speed=9998;
else if(z_down_speed<1)z_down_speed=1;
}
}
KEYUPDOWN=SW;
}
break;
case 25: //CLR
if(KEYUPDOWN==0)
{
if(xx_photo==1)
{
if(ADDR==1)
{
LCD_jingei_staus=1;
jingei_times=0;
}
}
else if(xx_photo==2)
{
if(ADDR==2)
{
z_waitpostion_staus=1;
z_waitpostion=0;
}
else if(ADDR==1)
{
guangmo_times_staus=1;
guangmo_times=0;
}
}
else if(xx_photo==4)
{
if(ADDR==1)
{
z_up_speed_staus=1;
z_up_speed=0;
}
else if(ADDR==2)
{
z_down_speed_staus=1;
z_down_speed=0;
}
}
KEYUPDOWN=SW;
}
break;
case 26: //换画面
if(KEYUPDOWN==0)
{
xx_photo=xx_photo+1;
if(xx_photo<1)xx_photo=1;
if(xx_photo>4)xx_photo=1;
EXCHANGE=1;
KEYUPDOWN=SW;
}
break;
default:
break;
}
case 1: //half auto
break;
case 2: //auto
break;
default:
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -