- void main(void)
- {
- uchar PWKZ_cnt=0;//电源控制标志位,按钮次数
- uchar LIGKZ_cnt=0;//照明控制标志位,按钮次数
- PWKZ=0;//24V电源控制
- LIGKZ=0;//照明控制初始化
- P2=0;//所有电机不工作
- LCD_Init();//LCD初始化
- while(1)
- {
- if(S1==0)
- {
- Delay_ms(10);
- if(S1==0)
- {
- step=13; //S1临时测试按钮,测试完成后由矩阵键盘输入step值
- while(SI==0);
- }
- }
- else
- {
- step=0;
- }
- switch(step)
- {
- case 0:
- {
- M1ZZ=0; //所有电机停止转动
- M1FZ=0;
- M2ZZ=0;
- M2FZ=0;
- M3ZZ=0;
- M3FZ=0;
- M4ZZ=0;
- M4FZ=0;
- LCD_ShowNum(1,13,step,2);
- break;
- }
- case 1:
- M1ZZ=1;
- LCD_ShowNum(1,13,step,2);
- break; //电机M1正转
- case 2:
- M2ZZ=1;
- LCD_ShowNum(1,13,step,2);
- break; //电机M2正转
- case 3:
- M3ZZ=1;
- M4ZZ=1;
- LCD_ShowNum(1,13,step,2);
- break; //电机M3,M4正转
- case 4:
- M3ZZ=1;
- M4FZ=1;
- LCD_ShowNum(1,13,step,2);
- break; //电机M3正转,M4反转
- case 5:
- M1FZ=1;
- LCD_ShowNum(1,13,step,2);
- break; //电机M1反转
- case 6:
- M2FZ=1;
- LCD_ShowNum(1,13,step,2);
- break; //电机M2发转
- case 7:
- M3FZ=1;
- M4FZ=1;
- LCD_ShowNum(1,13,step,2);
- break; //电机M3,M4反转
- case 8:
- M3FZ=1;
- M4ZZ=1;
- LCD_ShowNum(1,13,step,2);
- break; //电机M3反转,M4正转
- case 9:
- M1ZZ=1;
- M2ZZ=1;
- LCD_ShowNum(1,13,step,2);
- break; //电机M1与M2正转
- case 10:
- M1FZ=1;
- M2FZ=1;
- LCD_ShowNum(1,13,step,2);
- break; //电机M1与M2反转
- case 11:
- M1FZ=1;
- M2FZ=1;
- M3FZ=1;
- M4FZ=1;
- LCD_ShowNum(1,13,step,2);
- break; //所有电机电机M1,M2,M3,M4反转
- case 12:
- M1ZZ=1;
- M2ZZ=1;
- M3ZZ=1;
- M4ZZ=1;
- LCD_ShowNum(1,13,step,2);
- break; //所有电机电机M1,M2,M3,M4正转
- case 13: /*照明控制程序*/
- // LCD_ShowString(1,1," ");
- LCD_ShowString(1,1,"lighting control");//在第1行照明控制
- LIGKZ_cnt++;
- if(LIGKZ_cnt==1)
- {
- LIGKZ=1; //灯亮
- LCD_ShowString(2,1,"Status: LightOn");//在第2行灯亮
- }
- if(LIGKZ_cnt==2)
- {
- LIGKZ=0;//灯灭
- LCD_ShowString(2,1,"Status: LightOff");//在第2行灯亮
- LIGKZ_cnt=0;
- }
- step = 0;
- break;
- case 14:
- if(step==14)
- {
- Delay_ms(10);
- if(step==14)
- {
- // LCD_ShowString(1,1," ");
- LCD_ShowString(1,1,"At stopped state");//在第1行照明控制-LCD显示
- PWKZ_cnt++;
- if(PWKZ_cnt==1)
- {
- PWKZ=1;
- LCD_ShowString(2,1,"Status:Operation");//在第2行灯亮-LCD显示
- }
- if(PWKZ_cnt==2)
- {
- PWKZ=0;
- LCD_ShowString(2,1," Please unlock ");//在第2行灯亮-LCD显示
- PWKZ_cnt=0;
- }
- while(step==14)
- {
- Delay_ms(10);
- }
- }
- }
- break;
- case 15:
- break; //备用
- case 16:
- break; //备用
- }
- }
- }
复制代码 |