切断机 参数设置草稿

mac2024-12-28  16

 

                 Vp=0;                          //比例因子比较计数器                   for(;kcounter<=3;)             /*寄存器复位*/                    {                     if(~!KeyIn1)                 /*检测右移为高电平?*/                     {                            /**/                     kcounter++;                     }                     else if(!KeyIn1)             /*检测右移为低电平?*/                     {                     kcounter=0;                  /*寄存器复位*/                     delays(val3);                 //电机速度                     Vp++;                     CP1=!CP1;                    //输出脉冲                     if(Vp>=val4)                 //比例因子比较计数器加1                     {                     Vp=0;                     vala-=1;                     //加1                     }                     }                             }                             //松开右移按键

/*-切断机     2019 11 5  L1601 CODE5749****/               #include       <REG52.H>                  #include       <intrins.H>               #define        uint unsigned int                 #define        uchar unsigned char               uchar          code disdt[11]={0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xa3};               uchar          kcounter,kstatus;        //按键计数标志 按键状态标志               uint           val1,val3,vala;          /*1切断长度,3电机速度延时,vala台板位置*/               uchar             val2,val4;                  /*2切刀次数4比例因子*/               uint           val10;                     /*电机运行缓冲寄存器*/               sbit           BP=P5^4;               sbit           CS=P4^7;                 // 12864PIN4     vala显示缓冲valb加减时间处理缓冲               sbit           SID=P1^2;                // 12864PIN5               sbit           SCLK=P1^3;               // 12864PIN6               sbit           CLRTOTAL=P1^1;               sbit           OUT1=P2^7;               /****输出上升信号****/               sbit           OUT2=P2^6;               /****输出下降信号****/               sbit           Motor=P2^5;              /****电机信号****/               sbit           OUT4=P2^4;               /****输出信号****/               sbit           CP1=P4^2;               sbit           Dir1=P4^3;               sbit           En1=P4^4;               sbit           CP2=P2^0;               sbit           Dir2=P2^1;               sbit           En2=P2^2;               sbit           INT0PUT=P3^2;               /****外中断0****/               sbit           KeyOut1=P0^6;            /****按键输出总线1****/               sbit           KeyOut2=P1^7;            /****按键输出总线2****/               sbit           KeyIn1=P1^6;             /****按键输入总线****/               sbit           KeyIn2=P1^5;             /****按键输入总线****/               sbit           funkey=P1^5;               sbit           KeyIn3=P1^4;             /****按键输入总线****/               sbit           DATAUP=P1^4;               sbit           KeyIn4=P1^1;             /****按键输入总线****/               sbit             DATADOWN=P1^1;              //               sbit           KeyIn5=P1^0;             /****按键输入总线****/               sbit           KeyIn6=P0^7;             /****按键输入总线****/               sbit           ADD1=P1^5;               /****参数加****/               sbit           DEC1=P1^4;               /****参数减****/               sbit           Intput1=P3^4;              //  START               sbit           Intput2=P3^3;             //  原点       中断               sbit           Intput3=P3^5;                  sbit           Intput4=P3^6;                  sbit           Intput5=P3^7;                  sbit           Intput6=P4^1;               #define        IAP_ADDRESS          0x0000   //EEPROM首地址 切断长度               #define        IAP_ADDRESS_CutTime  0x0200   //EEPROM首地址 切刀次数               #define        IAP_ADDRESS_MotSpeed 0x0400   //EEPROM首地址 电机速度               #define        IAP_ADDRESS_Proportion_Factor  0x0600   //EEPROM首地址    比例因子               typedef        uchar   BYTE;               typedef        uint    WORD;               #define        CMD_IDLE    0            //空闲模式               #define        CMD_READ    1            //IAP字节读命令               #define        CMD_PROGRAM 2            //IAP字节编程命令               #define        CMD_ERASE   3            //IAP扇区擦除命令               #define        ENABLE_IAP  0x82         //if SYSCLK<20MHz               uint           x,l,m,n,k,z;             /****个十百代码缓冲**/               uint           t1,t2,t3,t4;               /****个十百千****/               void           delay_iic(int v);        /****eeprom读写延时**/               void           display11(uint h);               void           display22(uchar h);               uchar          rd_24c01(char a);        /****读EEPROM函数****/               void           wr_24c01(char a,char b); /****写EEPROM函数****/               void           delay(uint k);           /****延时****/               uchar          A1=0,B1=0;               uchar             func;                      /*功能标志*/               bit            adddecbit;                                 bit              OriginEnBit;              //原点检测使能标志,初始化置一确认原点后置零               bit              MtAdDc_FLAG;              //电机加减速标志 初始化加速置1,加速结束置0               uint           aa;               uint           MtAdDc_mtspeed;          /*电机加减速寄存器*/               uint           Zero_mtspeed;            /*原点电机运行速度寄存器*/ /*------------------延时子程序------------------------*/                void delay_1ms(uint x)                {                int i, j;                for(i=0;i<x;i++)                for(j=0;j<1500;j++);                } /*----关闭IAP----------------------------*/               void IapIdle()               {               IAP_CONTR=0;                  //关闭IAP功能               IAP_CMD=0;                    //清除命令寄存器               IAP_TRIG=0;                   //清除触发寄存器               IAP_ADDRH=0x80;               //将地址设置到非IAP区域               IAP_ADDRL=0;               } /*-从ISP/IAP/EEPROM区域读取一字节-*/               BYTE IapReadByte(WORD addr)               {               BYTE dat;                     //数据缓冲区               IAP_CONTR=ENABLE_IAP;         //使能IAP               IAP_CMD=CMD_READ;             //设置IAP命令               IAP_ADDRL=addr;               //设置IAP低地址               IAP_ADDRH=addr>>8;            //设置IAP高地址               IAP_TRIG=0x5a;                //写触发命令(0x5a)               IAP_TRIG=0xa5;                //写触发命令(0xa5)               _nop_();                      //等待ISP/IAP/EEPROM操作完成               dat=IAP_DATA;                 //读ISP/IAP/EEPROM数据               IapIdle();                    //关闭IAP功能               return dat;                   //返回               } /*-写一字节数据到ISP/IAP/EEPROM区域-*/               void IapProgramByte(WORD addr, BYTE dat)               {               IAP_CONTR=ENABLE_IAP;         //使能IAP               IAP_CMD=CMD_PROGRAM;          //设置IAP命令               IAP_ADDRL=addr;               //设置IAP低地址               IAP_ADDRH=addr>>8;            //设置IAP高地址               IAP_DATA=dat;                 //写ISP/IAP/EEPROM数据               IAP_TRIG=0x5a;                //写触发命令(0x5a)               IAP_TRIG=0xa5;                //写触发命令(0xa5)               _nop_();                      //等待ISP/IAP/EEPROM操作完成               IapIdle();               } /*---扇区擦除---------------*/               void IapEraseSector(WORD addr)               {               IAP_CONTR=ENABLE_IAP;         //使能IAP val=IapReadByte(IAP_ADDRESS+1);               IAP_CMD=CMD_ERASE;            //设置IAP命令               IAP_ADDRL=addr;               //设置IAP低地址               IAP_ADDRH=addr>>8;            //设置IAP高地址               IAP_TRIG=0x5a;                //写触发命令(0x5a)               IAP_TRIG=0xa5;                //写触发命令(0xa5)               _nop_();                      //等待ISP/IAP/EEPROM操作完成               IapIdle();               } /*-----------------------------------------*/               void red_eeprom(void)               {               t1=IapReadByte(IAP_ADDRESS);                           //切断长度               t2=IapReadByte(IAP_ADDRESS+1);               t3=IapReadByte(IAP_ADDRESS+2);               t4=IapReadByte(IAP_ADDRESS+3);               val1=t1*1000+t2*100+t3*10+t4;               t1=IapReadByte(IAP_ADDRESS_CutTime);                   //切断次数               t2=IapReadByte(IAP_ADDRESS_CutTime+1);               t3=IapReadByte(IAP_ADDRESS_CutTime+2);               val2=t1*100+t2*10+t3;               t1=IapReadByte(IAP_ADDRESS_MotSpeed);               //电机速度               t2=IapReadByte(IAP_ADDRESS_MotSpeed+1);               t3=IapReadByte(IAP_ADDRESS_MotSpeed+2);               val3=t1*100+t2*10+t3;               t1=IapReadByte(IAP_ADDRESS_Proportion_Factor);       //比例因子               t2=IapReadByte(IAP_ADDRESS_Proportion_Factor+1);               t3=IapReadByte(IAP_ADDRESS_Proportion_Factor+2);               val4=t1*100+t2*10+t3;               } /*------------------延时子程序------------------------*/                void delay1ms(int x)        //@12.000MHz    50us                {                unsigned char j,s;                s=x ;                for(s=0;s<x;s++)                for(j=0;j<15;j++);                } /*------------------延时子程序------------------------*/               void delay(uint t)               {               uint i,j;               for(i=0;i<t;i++)               for(j=0;j<121;j++);               } /****************按键计数器状态寄存器归零*************/               void RstKey()               {               kcounter=0;                       //按键计数器归零               kstatus=0;                        //状态寄存器归零               } /*****************按键低电平检测函数*****************/               void   LowVoltKey(void)           //按键计数器状态标志加一               {               kcounter++;                                      kstatus++;                    delay(5);                         //延时                                 } /*****************按键高电平检测函数*****************/               void    HighVoltKey(void)         //按键计数器加一 状态标志归零               {               kcounter++;                       //按键计数器加一               kstatus=0;                        //按键状态标志归零               delay(5);                         //延时               } /*------------------写命令到LCD-----------------------*/               void write_com(uchar cmdcode)               {                uchar i;                uchar i_data,temp_data1,temp_data2;                EA=0;                i_data=0xf8;                delay_1ms(10);                CS=1;                SCLK=0;                 for(i=0;i<8;i++)                 {                 SID=(bit)(i_data&0x80);                 SCLK=0;                 SCLK=1;                 i_data=i_data<<1;                 }                i_data=cmdcode;                i_data&=0xf0;                 for(i=0;i<8;i++)                 {                 SID=(bit)(i_data&0x80);                 SCLK=0;                 SCLK=1;                 i_data=i_data<<1;                 }                i_data=cmdcode;                temp_data1=i_data&0xf0;                temp_data2=i_data&0x0f;                temp_data1>>=4;                temp_data2<<=4;                i_data=temp_data1|temp_data2;                i_data&=0xf0;                 for(i=0;i<8;i++)                 {                 SID=(bit)(i_data&0x80);                 SCLK=0;                 SCLK=1;                 i_data=i_data<<1;                 }                CS=0;                EA=1;               } /*-------------------写数据到LCD----------------------*/               void write_data(uchar Dispdata)               {                uchar i;                uchar i_data,temp_data1,temp_data2;                EA=0;                i_data=0xfa;                delay_1ms(10);                CS=1;                 for(i=0;i<8;i++)                 {                 SID=(bit)(i_data&0x80);                 SCLK=0;                 SCLK=1;                 i_data=i_data<<1;                 }                i_data=Dispdata;                i_data&=0xf0;                 for(i=0;i<8;i++)                 {                 SID=(bit)(i_data&0x80);                 SCLK=0;                 SCLK=1;                 i_data=i_data<<1;                 }                i_data=Dispdata;                temp_data1=i_data&0xf0;                temp_data2=i_data&0x0f;                temp_data1>>=4;                temp_data2<<=4;                i_data=temp_data1|temp_data2;                i_data&=0xf0;                 for(i=0;i<8;i++)                 {                 SID=(bit)(i_data&0x80);                 SCLK=0;                 SCLK=1;                 i_data=i_data<<1;                 }                CS=0;                EA=1;               } /*------------------初始化LCD屏-----------------------*/               void lcd_init()               {                uchar comdata;                delay_1ms(100);                comdata=0x30;                write_com(comdata); /*功能设置:一次送8位数据,基本指令集*/                comdata=0x04;                write_com(comdata); /*点设定:显示字符/光标从左到右移位,DDRAM地址加1*/                comdata=0x0f;                write_com(comdata); /*显示设定:开显示,显示光标,当前显示位反白闪动*/                comdata=0x01;                write_com(comdata); /*清DDRAM*/                comdata=0x02;                write_com(comdata); /*DDRAM地址归位*/                comdata=0x80;                write_com(comdata); /*把显示地址设为0X80,即为第一行的首位*/               } /*--------参数设置------------------*/                void xscssz()                {                 write_com(0X82);                 /*---参---*/                 write_data(0xB2);                 write_data(0xCE);                                                write_com(0X83);                 /*---数---*/                 write_data(0xCA);                 write_data(0xFD);                    write_com(0X84);                 /*---设---*/                 write_data(0xC9);                 write_data(0xE8);                                                write_com(0X85);                 /*---置---*/                 write_data(0xD6);                 write_data(0xC3);                    } /**************台板位置****************/               void  TablePosition()               {                write_com(0X90);                 //                write_data(0XCC);                write_data(0XA8);                /*---台----*/                write_com(0X91);                write_data(0XB0);                write_data(0XE5);                /*---板----*/                write_com(0X92);                write_data(0XCE);                write_data(0XBB);                /*---位----*/                write_com(0X93);                write_data(0XD6);                write_data(0XC3);                /*---置----*/               } /**************台板参数显示************/               void  DisTableData()               {                t1=vala/1000;                t2=(vala-t1*1000)/100;                t3=(vala-t1*1000-t2*100)/10;                t4=vala-t1*1000-t2*100-t3*10;                write_com(0x94);                  /*地址*/                write_data(0xA3);                 /*半个字符*/                write_data(disdt[t1]);            /*千位*/                                                                write_com(0x95);                  /*地址*/                write_data(0xA3);                 /*半个字符*/                write_data(disdt[t2]);            /*百位*/                write_com(0x96);                  /*地址*/                write_data(0xA3);                 /*半个字符*/                write_data(disdt[t3]);            /*十位*/                                                                write_com(0x97);                  /*地址*/                write_data(0xA3);                 /*半个字符*/                write_data(disdt[t4]);            /*个位*/               } /**************切断长度****************/               void  CutteLength()               {                write_com(0X90);                 //                write_data(0XC7);                write_data(0XD0);                /*---切----*/                write_com(0X91);                write_data(0XB6);                write_data(0XCF);                /*---断----*/                write_com(0X92);                write_data(0XB3);                write_data(0XA4);                /*---长----*/                write_com(0X93);                write_data(0XB6);                write_data(0XC8);                /*---度----*/               } /**************电机速度****************/               void  MotorSpeed()               {                write_com(0x90);                 //                write_data(0xB5);                write_data(0xE7);                /*---电----*/                write_com(0x91);                write_data(0xBB);                write_data(0xFA);                /*---机----*/                write_com(0x92);                write_data(0xCB);                write_data(0xD9);                /*---速----*/                write_com(0x93);                write_data(0xB6);                write_data(0xC8);                /*---度----*/               } /**************切刀次数****************/               void  CutteTime()               {                write_com(0X90);                 //                write_data(0XC7);                write_data(0XD0);                /*---切----*/                write_com(0X91);                write_data(0XB5);                write_data(0XB6);                /*---刀----*/                write_com(0X92);                write_data(0XB4);                write_data(0XCE);                /*---次----*/                write_com(0X93);                write_data(0XCA);                write_data(0XFD);                /*---数----*/               } /**************比例因子****************/               void  Proportion_Factor()               {                write_com(0X90);                 //                write_data(0XB1);                write_data(0XC8);                /*---比----*/                write_com(0X91);                write_data(0XC0);                write_data(0XFD);                /*---例----*/                write_com(0X92);                write_data(0XD2);                write_data(0XF2);                /*---因----*/                write_com(0X93);                write_data(0XD7);                write_data(0XD3);                /*---子----*/               } /*-----显示-状态-----------------------------------*/               void display()               {                       write_com(0x80);                                                  write_data(0xB2);                write_data(0xFA);                /*---产---*/                                               write_com(0x81);                                                  write_data(0xC1);                write_data(0xBF);                /*---量---*/                  TablePosition();                 //台板位置                write_com(0X88);                 //                write_data(0XC7);                write_data(0XD0);                /*---切----*/                write_com(0X89);                write_data(0XB6);                write_data(0XCF);                /*---断----*/                write_com(0X8A);                write_data(0XB3);                write_data(0XA4);                /*---长----*/                write_com(0X8B);                write_data(0XB6);                write_data(0XC8);                /*---度----*/                display11(val1);                write_com(0X98);                 //                write_data(0XC7);                write_data(0XD0);                /*---切----*/                write_com(0X99);                write_data(0XB5);                write_data(0XB6);                /*---刀----*/                write_com(0X9A);                write_data(0XB4);                write_data(0XCE);                /*---次----*/                write_com(0X9B);                write_data(0XCA);                write_data(0XFD);                /*---数----*/                display22(val2);               } /*--------------显示切断长度---------------------*/               void display1(uint h)                                                   {                t1=h/1000;                t2=(h-t1*1000)/100;                t3=(h-t1*1000-t2*100)/10;                t4=h-t1*1000-t2*100-t3*10;                write_com(0x94);                  /*地址*/                write_data(0xA3);                 /*半个字符*/                write_data(disdt[t1]);            /*千位*/                                                                write_com(0x95);                  /*地址*/                write_data(0xA3);                 /*半个字符*/                write_data(disdt[t2]);            /*百位*/                write_com(0x96);                  /*地址*/                write_data(0xA3);                 /*半个字符*/                write_data(disdt[t3]);            /*十位*/                                                                write_com(0x97);                  /*地址*/                write_data(0xA3);                 /*半个字符*/                write_data(disdt[t4]);            /*个位*/               }     /*--------------显示切断长度---------------------*/               void display11(uint h)                                                   {                t1=h/1000;                t2=(h-t1*1000)/100;                t3=(h-t1*1000-t2*100)/10;                t4=h-t1*1000-t2*100-t3*10;                write_com(0X8C);                  /*地址*/                write_data(0xA3);                 /*半个字符*/                write_data(disdt[t1]);            /*千位*/                                                                write_com(0X8D);                  /*地址*/                write_data(0xA3);                 /*半个字符*/                write_data(disdt[t2]);            /*百位*/                write_com(0X8E);                  /*地址*/                write_data(0xA3);                 /*半个字符*/                write_data(disdt[t3]);            /*十位*/                                                                write_com(0X8F);                  /*地址*/                write_data(0xA3);                 /*半个字符*/                write_data(disdt[t4]);            /*个位*/               }     /*------显示切断次数,电机速度,比例因子----------*/               void display2(uchar h)                                                   {                uchar S1,S2,S3;                S1=h/100;                S2=(h-S1*100)/10;                S3=h-S1*100-S2*10;                write_com(0X94);                  /*地址*/                write_data(0xA3);                 /*半个字符*/                write_data(disdt[S1]);            /*千位*/                                                                write_com(0X95);                  /*地址*/                write_data(0xA3);                 /*半个字符*/                write_data(disdt[S2]);            /*百位*/                write_com(0X96);                  /*地址*/                write_data(0xA3);                 /*半个字符*/                write_data(disdt[S3]);            /*十位*/                                                                }     /*------显示切断次数,电机速度,比例因子----------*/               void display22(uchar h)                                                   {                uchar S1,S2,S3;                S1=h/100;                S2=(h-S1*100)/10;                S3=h-S1*100-S2*10;                write_com(0X9C);                  /*地址*/                write_data(0xA3);                 /*半个字符*/                write_data(disdt[S1]);            /*百位*/                                                                write_com(0X9D);                  /*地址*/                write_data(0xA3);                 /*半个字符*/                write_data(disdt[S2]);            /*十位*/                write_com(0X9E);                  /*地址*/                write_data(0xA3);                 /*半个字符*/                write_data(disdt[S3]);            /*个位*/                write_com(0X9F);                  /*---CLEAR---*/                write_data(0xB6);                write_data(0xA0);                                                                 }     /*---------------显示自动---------------------*/               void disauto()               {                                  /*开始*/                write_com(0x84);                  /*地址*/                write_data(0xD7);                 /*半个字符*/                write_data(0xD4);                 /*半个字符*/                write_com(0x85);                  /*地址*/                write_data(0xB6);                 /*半个字符*/                write_data(0xAF);                 /*半个字符*/               }        /*---------------显示停止---------------------*/               void disstop()               {                                  /*开始*/                write_com(0x84);                  /*停地址*/                write_data(0xCD);                 /*半个字符*/                write_data(0xA3);                 /*半个字符*/                write_com(0x85);                  /*止地址*/                write_data(0xD6);                 /*半个字符*/                write_data(0xB9);                 /*半个字符*/               }              /************************rundelay()**********************/                      void  addtotal()               {                if(val4>9999){val4=0;}            /*大于9999归零*/                t1=val4/1000;                t2=(val4-t1*1000)/100;                t3=(val4-t1*1000-t2*100)/10;                t4=val4-t1*1000-t2*100-t3*10;     /*分离千 百 十 个三位*/               }   /*------------------开机广告-----------------------*/               void displayAdvertising()               {                write_com(0x06);                 /*游标的移动方向及指定显示的移位*/                write_com(0X82);                 /*--切---*/                write_data(0XC7);                write_data(0XD0);                write_com(0x83);                 /*--断---*/                write_data(0XB6);                write_data(0XCF);                write_com(0x84);                 /*--机---*/                write_data(0XBB);                write_data(0XFA);                  write_com(0x91);                 /*--自---*/                write_data(0XD7);                write_data(0XD4);                     write_com(0x92);                 /*--动---*/                write_data(0XB6);                write_data(0XAF);                   write_com(0x93);                 /*--控---*/                write_data(0XBF);                write_data(0XD8);                    write_com(0x94);                 /*--制---*/                write_data(0XD6);                write_data(0XC6);                  write_com(0x95);                 /*--器---*/                write_data(0XC6);                write_data(0XF7);                   write_com(0x88);                 /*--手----*/                write_data(0xCA);                write_data(0xD6);                                                 write_com(0x89);                 /*--机----*/                write_data(0xBB);                write_data(0xFA);                                                 write_com(0x8A);                     write_data(0x3A);                /*--:----*/                write_data(0x31);                /*--1----*/                                            write_com(0x8B);                     write_data(0x33);                /*--3----*/                write_data(0x37);                /*--7----*/                write_com(0x8C);                     write_data(0x37);                /*--7----*/                write_data(0x35);                /*--5----*/                write_com(0x8D);                     write_data(0x30);                /*--0----*/                write_data(0x36);                /*--6----*/                write_com(0x8E);                     write_data(0x31);                /*--1----*/                write_data(0x37);                /*--7----*/                write_com(0x8F);                     write_data(0x39);                /*--9----*/                write_data(0x32);                /*--2----*/               } /**************显示刀架上升****/                void Model_Up()                {                write_com(0X84);                   //刀                write_data(0XB5);                write_data(0XB6);                  write_com(0X85);                   //架                write_data(0XBC);                write_data(0XDC);                   write_com(0X86);                   //上                write_data(0XC9);                write_data(0XCF);                  write_com(0X87);                   //升                write_data(0XC9);                write_data(0XFD);                       } /**************显示刀架下降****/                void Model_Dwon()                {                write_com(0X84);                   //刀                write_data(0XB5);                write_data(0XB6);                  write_com(0X85);                   //架                write_data(0XBC);                write_data(0XDC);                   write_com(0X86);                   //下                write_data(0XCF);                write_data(0XC2);                  write_com(0X87);                   //降                write_data(0XBD);                write_data(0XB5);                       }

最新回复(0)