半自动双工位打孔机单片机程序

/**********L771 CODE 33895   2024 5 19    *******/
/***打孔机程序***/
/***2022 5 14包胶机PCB板     PAST  8:35      ***/
              #include     "reg52.h"             //取字库代码显示界面
              #include     "intrins.h"             //连续EEPROM地址写FM24C64文字
              #define      uchar  unsigned char
              #define      uint   unsigned int
              #define      IAP_ADDRESS 0x0000    //EEPROM首地址
              sbit         OLED_SCL=P3^3;       //
              sbit         OLED_SDA=P3^2;       //
              sbit         INTPUT1=P1^1;         //左进刀限位开关输入
              sbit         INTPUT2=P1^0;         //左退刀限位开关输入
              sbit         INTPUT3=P1^2;         //右进刀限位开关输入
              sbit         INTPUT4=P1^3;         //右退刀限位开关输入
              sbit         INTPUT5=P3^1;         //开始
              sbit         OUTPUT1=P1^6;         //左进刀输出
              sbit         OUTPUT2=P1^7;         //左退刀输出
              sbit         OUTPUT3=P3^7;         //右进刀输出
              sbit         OUTPUT4=P3^6;         //右退刀输出
              sbit         BP=P3^5;                 //
              bit          LeftForward_Flag;     //左进刀标志
              bit          LeftBack_Flag;         //左退刀标志
              bit          RightForward_Flag;    //右进刀标志
              bit          RightBack_Flag;         //右退刀标志
              sbit         KEY_ADD=P2^6;
              sbit         KEY_DEC=P2^7;
              sbit         KEY_SET=P1^0;
              sbit         KEY_ENTER=P1^1;
              uint         A1,A2,A3;       //输入文字总数 个位 十位 百位
              typedef      uchar BYTE;           //
              typedef      uint  WORD;                 //  
              uint         kcounter,kstatus;     //按键计数标志 按键状态标志
              uint         Counter;
              #define      high 1
              #define      low 0
              uchar        DAT1=0,DAT2=0;
/***********************0--A字符表*************************/
uchar code show1[]=
{
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,/*"0",0*/
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,/*"1",1*/
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,/*"2",2*/
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,/*"3",3*/
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,/*"4",4*/
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,/*"5",5*/
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,/*"6",6*/
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,/*"7",7*/
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,/*"8",8*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,/*"9",9*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x1F,0x01,0x01,0x01,0x01,0x1F,0x00,/*"A",10*/
0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,/*"D",11*/
0x08,0xF8,0x00,0xF8,0x00,0xF8,0x08,0x00,0x00,0x03,0x3E,0x01,0x3E,0x03,0x00,0x00,/*"W",12*/
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,/*"O",13*/
0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,/*"N",14*/
};    
uchar code show2[]=
{
0x08,0x08,0x08,0x08,0x88,0x78,0x0F,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,
0x20,0x10,0x48,0x46,0x41,0x41,0x41,0x41,0x7F,0x41,0x41,0x41,0x41,0x40,0x40,0x00,/*"左",0*/
0x08,0x08,0x08,0x08,0xC8,0x38,0x0F,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,
0x08,0x04,0x02,0x01,0xFF,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0xFF,0x00,0x00,0x00,/*"右",1*/
0x80,0x60,0xF8,0x07,0x00,0x04,0x74,0x54,0x55,0x56,0x54,0x54,0x74,0x04,0x00,0x00,
0x00,0x00,0xFF,0x00,0x03,0x01,0x05,0x45,0x85,0x7D,0x05,0x05,0x05,0x01,0x03,0x00,/*"停",2*/
0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0xFF,0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x00,
0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,/*"止",3*/
0x00,0x00,0x00,0xFC,0x44,0x44,0x44,0x45,0x46,0x44,0x44,0x44,0x44,0x7C,0x00,0x00,
0x40,0x20,0x18,0x07,0x00,0xFC,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0xFC,0x00,0x00,/*"启",4*/
0x40,0x44,0xC4,0x44,0x44,0x44,0x40,0x10,0x10,0xFF,0x10,0x10,0x10,0xF0,0x00,0x00,
0x10,0x3C,0x13,0x10,0x14,0xB8,0x40,0x30,0x0E,0x01,0x40,0x80,0x40,0x3F,0x00,0x00,/*"动",5*/
0x00,0x04,0x84,0x84,0x94,0xE4,0x85,0x86,0x84,0xC4,0xB4,0x84,0x84,0x84,0x80,0x00,
0x80,0x60,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"产",6*/
0x20,0x20,0x20,0xBE,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xBE,0x20,0x20,0x20,0x00,
0x00,0x80,0x80,0xAF,0xAA,0xAA,0xAA,0xFF,0xAA,0xAA,0xAA,0xAF,0x80,0x80,0x00,0x00,/*"量",7*/
0x40,0x40,0x42,0xCC,0x00,0x80,0x88,0x88,0xFF,0x88,0x88,0xFF,0x88,0x88,0x80,0x00,
0x00,0x40,0x20,0x1F,0x20,0x40,0x50,0x4C,0x43,0x40,0x40,0x5F,0x40,0x40,0x40,0x00,/*"进",8*/
0x40,0x40,0x42,0xCC,0x00,0x00,0xFF,0x49,0x49,0xC9,0x49,0x49,0x7F,0x80,0x00,0x00,
0x00,0x40,0x20,0x1F,0x20,0x40,0x5F,0x48,0x44,0x40,0x41,0x42,0x45,0x58,0x40,0x00,/*"退",9*/
0x00,0x00,0x04,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0x04,0x04,0xFC,0x00,0x00,0x00,
0x00,0x80,0x40,0x20,0x18,0x06,0x01,0x00,0x00,0x40,0x80,0x40,0x3F,0x00,0x00,0x00,/*"刀",10*/
0x00,0x10,0x88,0xC4,0x33,0x40,0x48,0x48,0x48,0x7F,0x48,0xC8,0x48,0x48,0x40,0x00,
0x02,0x01,0x00,0xFF,0x00,0x02,0x0A,0x32,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x00,/*"待",11*/
0x10,0x10,0xD0,0xFF,0x90,0x10,0x00,0xFE,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,
0x04,0x03,0x00,0xFF,0x00,0x83,0x60,0x1F,0x00,0x00,0x00,0x3F,0x40,0x40,0x78,0x00,/*"机",12*/
};
/*************Pin Define***************/
              void      Initial_LY096BG30();
              void      Delay_50ms(uint Del_50ms);
              void      fill_picture(uchar fill_Data);
              void      IIC_Start();
              void      IIC_Stop();
              void      Write_IIC_Command(uchar IIC_Command);
              void      Write_IIC_Data(uchar IIC_Data);
              bit       Write_IIC_Byte(uchar IIC_Byte);
              void      dis_Value(uchar s);
/*---------------延时子程序----------------*/
              void delay1 (uint ms)
              {
              uint i,j;
              for(i=0;i<ms;i++)
              for(j=0;j<200;j++)
              ;
              }
/**************Delay*******************************/
              void     Delay_50ms(uint Del_50ms)        //
              {
               uint m;
               for(;Del_50ms>0;Del_50ms--)
               for(m=62450;m>0;m--);
              }
/****************按键计数器状态寄存器归零*************/
              void RstKey()
              {
              kcounter=0;                        //按键计数器归零
              kstatus=0;                         //状态寄存器归零
              }
/*****************按键低电平检测函数*****************/
              void   LowVoltKey(void)            //按键计数器状态标志加一
              {
              kcounter++;                       
              kstatus++;     
              _nop_();                           //延时                  
              }
/*****************按键高电平检测函数*****************/
              void    HighVoltKey(void)          //按键计数器加一 状态标志归零
              {
              kcounter++;                        //按键计数器加一
              kstatus=0;                         //按键状态标志归零
              _nop_();                           //延时
              }
/*******************IIC Start******************/
              void IIC_Start()
              {
               OLED_SCL=high;
               OLED_SDA=high;
               _nop_();
               OLED_SDA=low;
               _nop_();_nop_();
               OLED_SCL=low;
              }
/*************IIC Stop*************************/
              void IIC_Stop()
              {
              OLED_SDA=low;
              _nop_();
              OLED_SCL=high;
              _nop_();_nop_();
              OLED_SDA=high;
              }
/*****************IIC Write byte***************/
              bit Write_IIC_Byte(unsigned char IIC_Byte)
              {
              unsigned char i;
               bit Ack_Bit;                      //应答信号
               for(i=0;i<8;i++)        
               {
               if(IIC_Byte & 0x80)               //1?0?
               OLED_SDA=high;
               else
               OLED_SDA=low;
               OLED_SCL=high;
               _nop_();_nop_();
               OLED_SCL=low;
               IIC_Byte<<=1;                     //loop
               }
              OLED_SDA=high;                     //释放IIC SDA总线为主器件接收从器件产生应答信号    
              _nop_();_nop_();
              OLED_SCL=high;                     //第9个时钟周期
              _nop_();_nop_();
              Ack_Bit=OLED_SDA;                  //读取应答信号
              OLED_SCL=low;
              return Ack_Bit;    
              }  
/*************IIC Write Command*****************/
              void Write_IIC_Command(unsigned char IIC_Command)
              {
              IIC_Start();
              Write_IIC_Byte(0x78);              //Slave address,SA0=0
              Write_IIC_Byte(0x00);              //write command
              Write_IIC_Byte(IIC_Command);
              IIC_Stop();
              }
/****************IIC Write Data*****************/
              void Write_IIC_Data(uchar IIC_Data)
              {
              IIC_Start();
              Write_IIC_Byte(0x78);            
              Write_IIC_Byte(0x40);              //write data
              Write_IIC_Byte(IIC_Data);
              IIC_Stop();
              }
/********************picture**********************/
              void cleardisp()
              {
              uchar x,y;
              for(y=0;y<8;y++)
               {
               Write_IIC_Command(0xb0+y);
               Write_IIC_Command(0x00);
               Write_IIC_Command(0x10);
                for(x=0;x<128;x++)               //横向像素
                {
                Write_IIC_Data(0X00);
                }
               }
              }
/***********************Initial code*********************/
              void  Initial_LY096BG30()
              {
              Write_IIC_Command(0xAE);   //display off
              Write_IIC_Command(0x20);     //Set Memory Addressing Mode    
              Write_IIC_Command(0x10);     //00,Horizontal Addressing Mode;01,Vertical Addressing Mode;10,Page Addressing Mode (RESET);11,Invalid
              Write_IIC_Command(0xb0);     //Set Page Start Address for Page Addressing Mode,0-7
              Write_IIC_Command(0xc8);      //Set COM Output Scan Direction
              Write_IIC_Command(0x00);   //---set low column address
              Write_IIC_Command(0x10);   //---set high column address
              Write_IIC_Command(0x40);   //--set start line address
              Write_IIC_Command(0x81);   //--set contrast control register
              Write_IIC_Command(0x7f);
              Write_IIC_Command(0xa1);   //--set segment re-map 0 to 127
              Write_IIC_Command(0xa6);   //--set normal display
              Write_IIC_Command(0xa8);   //--set multiplex ratio(1 to 64)
              Write_IIC_Command(0x3F);   //
              Write_IIC_Command(0xa4);   //0xa4,Output follows RAM content;0xa5,Output ignores RAM content
              Write_IIC_Command(0xd3);   //-set display offset
              Write_IIC_Command(0x00);   //-not offset
              Write_IIC_Command(0xd5);   //--set display clock divide ratio/oscillator frequency
              Write_IIC_Command(0xf0);   //--set divide ratio
              Write_IIC_Command(0xd9);   //--set pre-charge period
              Write_IIC_Command(0x22);   //
              Write_IIC_Command(0xda);   //--set com pins hardware configuration
              Write_IIC_Command(0x12);
              Write_IIC_Command(0xdb);   //--set vcomh
              Write_IIC_Command(0x20);   //0x20,0.77xVcc
              Write_IIC_Command(0x8d);   //--set DC-DC enable
              Write_IIC_Command(0x14);   //
              Write_IIC_Command(0xaf);   //--turn on oled panel
             }
/********************显示待机**********************/
              void Diswait()
              {
              uchar x,y;
              uint  Cnt=32;
              for(y=0;y<2;y++)
               {
               Write_IIC_Command(0xb6+y); //竖向第一行    待
               Write_IIC_Command(0x00);
               Write_IIC_Command(0x10);      //横向第一个字
                for(x=0;x<16;x++)          //横向像素
                {
                Write_IIC_Data(show2[x+y*16+Cnt*11]); //字符表第7个字
                }
               }
//
               for(y=0;y<2;y++)
               {
               Write_IIC_Command(0xb6+y); //竖向第一行    机
               Write_IIC_Command(0x00);
               Write_IIC_Command(0x11);      //横向第二个字
                for(x=0;x<16;x++)          //横向像素
                {
                Write_IIC_Data(show2[x+y*16+Cnt*12]);  //字符表第8个字
                }
               }
              }
/********************显示开始**********************/
              void  DisStart()                       //显示延时
              {
              uchar x,y;
              uint  Cnt=32;
              for(y=0;y<2;y++)
               {
               Write_IIC_Command(0xb6+y); //竖向第一行    开
               Write_IIC_Command(0x00);
               Write_IIC_Command(0x10);      //横向第一个字
                for(x=0;x<16;x++)          //横向像素
                {
                Write_IIC_Data(show2[x+y*16+Cnt*4]); //字符表第1个字
                }
               }
//
               for(y=0;y<2;y++)
               {
               Write_IIC_Command(0xb6+y); //竖向第一行    始
               Write_IIC_Command(0x00);
               Write_IIC_Command(0x11);      //横向第二个字
                for(x=0;x<16;x++)          //横向像素
                {
                Write_IIC_Data(show2[x+y*16+Cnt*5]);  //字符表第2个字
                }
               }
              }
/********************左进刀**********************/
              void  LeftForward()                       //显示延时
              {
              uchar x,y;
              uint  i=0;
              uint  Cnt=32;
              for(y=0;y<2;y++)
               {
               Write_IIC_Command(0xb2+y); //竖向第一行    左
               Write_IIC_Command(0x00);
               Write_IIC_Command(0x10);      //横向第一个字
                for(x=0;x<16;x++)          //横向像素
                {
                Write_IIC_Data(show2[x+y*16+Cnt*0]); //字符表第1个字
                }
               }
//
               for(y=0;y<2;y++)
               {
               Write_IIC_Command(0xb2+y); //竖向第一行    进
               Write_IIC_Command(0x00);
               Write_IIC_Command(0x11);      //横向第二个字
                for(x=0;x<16;x++)          //横向像素
                {
                Write_IIC_Data(show2[x+y*16+Cnt*8]);  //字符表第9个字
                }
               }
//
               for(y=0;y<2;y++)
               {
               Write_IIC_Command(0xb2+y); //竖向第一行    刀
               Write_IIC_Command(0x00);
               Write_IIC_Command(0x12);      //横向第二个字
                for(x=0;x<16;x++)          //横向像素
                {
                Write_IIC_Data(show2[x+y*16+Cnt*10]);  //字符表第11个字
                }
               }
              }
/********************左退刀**********************/
              void  LeftBack()                       //显示延时
              {
              uchar x,y;
              uint  i=0;
              uint  Cnt=32;
              for(y=0;y<2;y++)
               {
               Write_IIC_Command(0xb2+y); //竖向第一行    左
               Write_IIC_Command(0x00);
               Write_IIC_Command(0x10);      //横向第一个字
                for(x=0;x<16;x++)          //横向像素
                {
                Write_IIC_Data(show2[x+y*16+Cnt*0]); //字符表第1个字
                }
               }
//
               for(y=0;y<2;y++)
               {
               Write_IIC_Command(0xb2+y); //竖向第一行    退
               Write_IIC_Command(0x00);
               Write_IIC_Command(0x11);      //横向第二个字
                for(x=0;x<16;x++)          //横向像素
                {
                Write_IIC_Data(show2[x+y*16+Cnt*9]);  //字符表第10个字
                }
               }
//
               for(y=0;y<2;y++)
               {
               Write_IIC_Command(0xb2+y); //竖向第一行    刀
               Write_IIC_Command(0x00);
               Write_IIC_Command(0x12);      //横向第二个字
                for(x=0;x<16;x++)          //横向像素
                {
                Write_IIC_Data(show2[x+y*16+Cnt*10]);  //字符表第11个字
                }
               }
              }
/*******************左退刀停**********************/
              void  LeftBackStop()               //显示延时
              {
              uchar x,y;
              uint  i=0;
              uint  Cnt=32;
              for(y=0;y<2;y++)
               {
               Write_IIC_Command(0xb2+y); //竖向第一行    退
               Write_IIC_Command(0x00);
               Write_IIC_Command(0x10);      //横向第一个字
                for(x=0;x<16;x++)          //横向像素
                {
                Write_IIC_Data(show2[x+y*16+Cnt*9]); //字符表第1个字
                }
               }
//
               for(y=0;y<2;y++)
               {
               Write_IIC_Command(0xb2+y); //竖向第一行    刀
               Write_IIC_Command(0x00);
               Write_IIC_Command(0x11);      //横向第二个字
                for(x=0;x<16;x++)          //横向像素
                {
                Write_IIC_Data(show2[x+y*16+Cnt*10]);  //字符表第10个字
                }
               }
//
               for(y=0;y<2;y++)
               {
               Write_IIC_Command(0xb2+y); //竖向第一行    停
               Write_IIC_Command(0x00);
               Write_IIC_Command(0x12);      //横向第二个字
                for(x=0;x<16;x++)          //横向像素
                {
                Write_IIC_Data(show2[x+y*16+Cnt*2]);  //字符表第11个字
                }
               }
              }                                           //RightBackStop()

/********************右进刀**********************/
              void  RightForward()                       //显示延时
              {
              uchar x,y;
              uint  i=0;
              uint  Cnt=32;
              for(y=0;y<2;y++)
               {
               Write_IIC_Command(0xb4+y); //竖向第一行    右
               Write_IIC_Command(0x00);
               Write_IIC_Command(0x10);      //横向第一个字
                for(x=0;x<16;x++)          //横向像素
                {
                Write_IIC_Data(show2[x+y*16+Cnt*1]); //字符表第1个字
                }
               }
//
               for(y=0;y<2;y++)
               {
               Write_IIC_Command(0xb4+y); //竖向第一行    进
               Write_IIC_Command(0x00);
               Write_IIC_Command(0x11);      //横向第二个字
                for(x=0;x<16;x++)          //横向像素
                {
                Write_IIC_Data(show2[x+y*16+Cnt*8]);  //字符表第9个字
                }
               }
//
               for(y=0;y<2;y++)
               {
               Write_IIC_Command(0xb4+y); //竖向第一行    刀
               Write_IIC_Command(0x00);
               Write_IIC_Command(0x12);      //横向第二个字
                for(x=0;x<16;x++)          //横向像素
                {
                Write_IIC_Data(show2[x+y*16+Cnt*10]);  //字符表第11个字
                }
               }
              }
/********************右退刀**********************/
              void  RightBack()                       //显示延时
              {
              uchar x,y;
              uint  i=0;
              uint  Cnt=32;
              for(y=0;y<2;y++)
               {
               Write_IIC_Command(0xb4+y); //竖向第一行    右
               Write_IIC_Command(0x00);
               Write_IIC_Command(0x10);      //横向第一个字
                for(x=0;x<16;x++)          //横向像素
                {
                Write_IIC_Data(show2[x+y*16+Cnt*1]); //字符表第1个字
                }
               }
//
               for(y=0;y<2;y++)
               {
               Write_IIC_Command(0xb4+y); //竖向第一行    退
               Write_IIC_Command(0x00);
               Write_IIC_Command(0x11);      //横向第二个字
                for(x=0;x<16;x++)          //横向像素
                {
                Write_IIC_Data(show2[x+y*16+Cnt*9]);  //字符表第10个字
                }
               }
//
               for(y=0;y<2;y++)
               {
               Write_IIC_Command(0xb4+y); //竖向第一行    刀
               Write_IIC_Command(0x00);
               Write_IIC_Command(0x12);      //横向第二个字
                for(x=0;x<16;x++)          //横向像素
                {
                Write_IIC_Data(show2[x+y*16+Cnt*10]);  //字符表第11个字
                }
               }
              }
 /*******************右退刀停**********************/
              void  RightBackStop()               //显示延时
              {
              uchar x,y;
              uint  i=0;
              uint  Cnt=32;
              for(y=0;y<2;y++)
               {
               Write_IIC_Command(0xb4+y); //竖向第一行    退
               Write_IIC_Command(0x00);
               Write_IIC_Command(0x10);      //横向第一个字
                for(x=0;x<16;x++)          //横向像素
                {
                Write_IIC_Data(show2[x+y*16+Cnt*9]); //字符表第1个字
                }
               }
//
               for(y=0;y<2;y++)
               {
               Write_IIC_Command(0xb4+y); //竖向第一行    刀
               Write_IIC_Command(0x00);
               Write_IIC_Command(0x11);      //横向第二个字
                for(x=0;x<16;x++)          //横向像素
                {
                Write_IIC_Data(show2[x+y*16+Cnt*10]);  //字符表第10个字
                }
               }
//
               for(y=0;y<2;y++)
               {
               Write_IIC_Command(0xb4+y); //竖向第一行    停
               Write_IIC_Command(0x00);
               Write_IIC_Command(0x12);      //横向第二个字
                for(x=0;x<16;x++)          //横向像素
                {
                Write_IIC_Data(show2[x+y*16+Cnt*2]);  //字符表第11个字
                }
               }
              }                                    
/**************显示产量********************/
              void  disThrough()
              {
              uchar x,y;
              uint  Cnt=32;
              for(y=0;y<2;y++)
               {
               Write_IIC_Command(0xb0+y); //竖向第一行    产
               Write_IIC_Command(0x00);
               Write_IIC_Command(0x10);      //横向第一个字
                for(x=0;x<16;x++)          //横向像素
                {
                Write_IIC_Data(show2[x+y*16+Cnt*6]); //字符表第7个字
                }
               }
//
               for(y=0;y<2;y++)
               {
               Write_IIC_Command(0xb0+y); //竖向第一行    量
               Write_IIC_Command(0x00);
               Write_IIC_Command(0x11);      //横向第二个字
                for(x=0;x<16;x++)          //横向像素
                {
                Write_IIC_Data(show2[x+y*16+Cnt*7]);  //字符表第8个字
                }
               }
              }
/**************产量刷新********************/
              void  disThroughput(uint a)
              {
               uchar x,y;
               uchar A1,A2,A3,A4;
               A1=a/1000;
               A2=(a-A1*1000)/100;
               A3=(a-A1*1000-A2*100)/10;
               A4=a-A1*1000-A2*100-A3*10;
               for(y=0;y<2;y++)                  //百位显示
               {
               Write_IIC_Command(0XB0+y);        //纵向页
               Write_IIC_Command(00);            //横向离左部边缘开始的距离
               Write_IIC_Command(0X12);          //横向第四个字
                for(x=0;x<8;x++)                 //横向像素
                {
                Write_IIC_Data(show1[x+y*8+A1*16]);     //0--A字符表 千位
                }
                for(x=0;x<8;x++)                 //横向像素
                {
                Write_IIC_Data(show1[x+y*8+A2*16]);      //百位
                }
               }
               for(y=0;y<2;y++)                  //百位显示
               {
               Write_IIC_Command(0XB0+y);        //纵向页
               Write_IIC_Command(00);            //横向离左部边缘开始的距离
               Write_IIC_Command(0X13);          //横向第四个字
                for(x=0;x<8;x++)                 //横向像素
                {
                Write_IIC_Data(show1[x+y*8+A3*16]);     //0--A字符表 十位
                }
                for(x=0;x<8;x++)                 //横向像素
                {
                Write_IIC_Data(show1[x+y*8+A4*16]);       //个位
                }
               }
              }
/*************关所有输出*******************************/             
              void reset_io()
              {
              P1M0=0X00;
              P1M1=0X00;
              P2M0=0X00;
              P2M1=0X00;
              P3M0=0X00;
              P3M1=0X00;
              P5M0=0X00;
              P5M1=0X00;
              INTPUT1=1;                         //左进刀限位开关输入
              INTPUT2=1;                         //左退刀限位开关输入
              INTPUT3=1;                         //右进刀限位开关输入
              INTPUT4=1;                         //右退刀限位开关输入
              INTPUT5=1;                         //开始打孔信号
              LeftForward_Flag=0;                 //左进刀启动标志
              LeftBack_Flag=0;                     //左退刀启动标志
              RightForward_Flag=0;                 //右进刀启动标志
              RightBack_Flag=0;                     //右退刀启动标志
              }
/******************************************************/
              void serve_T0() interrupt 1 using 1
              {
               TH0=0x2f;
               TL0=0x40;
              // DAT2++;
              // if(DAT2>=100)
              // {
              // DAT2=0;
              // BP=~BP;
              // }
              }                                                                       
/*********************************************************/
              void main(void)                    //
              {
              EA=1;
              ET0=1;
              TR0=1;
              Initial_LY096BG30();               //初始化显示屏
              Counter=0;                         //产量归零
              cleardisp();                         //清除显示
              reset_io();                         //IO复位
              Diswait();                         //显示待机
              Delay_50ms(2);
              RstKey();
              disThrough();                         //
              disThroughput(Counter);             //
              while(1)
               {
                DAT1++;
               if(DAT1>=100)
               {
               DAT1=0;
               BP=~BP;
               }
                RstKey();
                for(;kcounter<10;)                //按键循环10
                 {
                  if(!INTPUT5)                     //按键低电平
                  {
                  LowVoltKey();                    //按键低电平 计数器加一状态标志加一
                  }
                  else if(~!INTPUT5)               //按键高电平
                  {
                  HighVoltKey();                   //按键计数器加一    状态标志归零
                  }
                  delay1(2);                        //2023
                 }
                 if(kstatus>=8)                    /*按键状态标志大于等于8为有效值*/
                 {
                  DisStart();                     //
                  LeftForward();                 //左进刀
                  RightForward();                 //右进刀
                  LeftForward_Flag=1;             //左进刀启动标志
                  RightForward_Flag=1;             //右进刀启动标志
                  OUTPUT1=0;                     //开左进刀输出
                  OUTPUT3=0;                     //右进刀输出
                 }
//打孔开始
                 if(LeftForward_Flag==1)
                 {
                  RstKey();
                  for(;kcounter<5;)              //按键循环10
                  {
                   if(!INTPUT1)                  //按键低电平
                   {
                   LowVoltKey();                 //按键低电平 计数器加一状态标志加一
                   }
                   else if(~!INTPUT1)            //按键高电平
                   {
                   HighVoltKey();                //按键计数器加一    状态标志归零
                   }
                   delay1(2);                    //2023
                  }
                  if(kstatus>=3)                 /*按键状态标志大于等于8为有效值*/
                  {
                  LeftBack();                     //显示左退刀
                  LeftForward_Flag=0;             //关左进刀启动标志
                  OUTPUT1=1;                     //关左进刀输出
                  LeftBack_Flag=1;                 //开左退刀启动标志
                  OUTPUT2=0;                     //开左退刀输出
                  }
                 }
//左进刀限位
                 if(RightForward_Flag==1)
                 {
                  RstKey();
                  for(;kcounter<5;)              //按键循环10
                  {
                   if(!INTPUT3)                  //按键低电平
                   {
                   LowVoltKey();                 //按键低电平 计数器加一状态标志加一
                   }
                   else if(~!INTPUT3)            //按键高电平
                   {
                   HighVoltKey();                //按键计数器加一    状态标志归零
                   }
                   delay1(2);                    //2023
                  }
                  if(kstatus>=3)                 /*按键状态标志大于等于8为有效值*/
                  {
                  RightBack();                     //显示右退刀
                  RightForward_Flag=0;             //关右进刀启动标志
                  OUTPUT3=1;                     //关右进刀输出
                  RightBack_Flag=1;                 //开右退刀启动标志
                  OUTPUT4=0;                     //开右退刀输出
                  }
                 }
//右进刀限位
                 if(LeftBack_Flag==1)
                 {
                  RstKey();
                  for(;kcounter<5;)              //按键循环10
                  {
                   if(!INTPUT2)                  //按键低电平
                   {
                   LowVoltKey();                 //按键低电平 计数器加一状态标志加一
                   }
                   else if(~!INTPUT2)            //按键高电平
                   {
                   HighVoltKey();                //按键计数器加一    状态标志归零
                   }
                   delay1(2);                    //2023
                  }
                  if(kstatus>=3)                 /*按键状态标志大于等于8为有效值*/
                  {
                  LeftBack_Flag=0;                 //关左进刀启动标志
                  OUTPUT2=1;                     //关左退刀输出
                  LeftBackStop();
                  }
                 }
//左退刀限位
                 if(RightBack_Flag==1)
                 {
                  RstKey();
                  for(;kcounter<5;)              //按键循环10
                  {
                   if(!INTPUT4)                  //按键低电平
                   {
                   LowVoltKey();                 //按键低电平 计数器加一状态标志加一
                   }
                   else if(~!INTPUT4)            //按键高电平
                   {
                   HighVoltKey();                //按键计数器加一    状态标志归零
                   }
                   delay1(2);                    //2023
                  }
                  if(kstatus>=3)                 /*按键状态标志大于等于8为有效值*/
                  {
                  RightBack_Flag=0;                 //关右进刀启动标志
                  OUTPUT4=1;                     //关右退刀输出
                  RightBackStop();
                  Counter++;
                  disThroughput(Counter);
                  }
                 }
//右退刀限位
                }
              }                                     //L771  CODE3895 2024 5 19

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值