您的位置:首页 > 文旅 > 旅游 > 深圳景观设计公司排行_如何自己创作一个游戏_seo好学吗入门怎么学_北京疫情最新情况

深圳景观设计公司排行_如何自己创作一个游戏_seo好学吗入门怎么学_北京疫情最新情况

2024/12/23 9:34:24 来源:https://blog.csdn.net/czhaii/article/details/143083663  浏览:    关键词:深圳景观设计公司排行_如何自己创作一个游戏_seo好学吗入门怎么学_北京疫情最新情况
深圳景观设计公司排行_如何自己创作一个游戏_seo好学吗入门怎么学_北京疫情最新情况

/***升降机 2,4寸触摸屏2021 5 15 PCB***/    
/***L407 CODE 2421 2021 5 28PAST   ***/    
              #include     <REG52.H>              //开机第一个参数设置翻页需改进
              #include     <intrins.h>            //保压时间
              #include     <string.h>
              #include     "stdio.h"
              #include     <stdlib.h>
              #define      uint unsigned int
              #define      uchar unsigned char
              sbit         INTPUT1=P3^2;         //启动信号
              sbit         INTPUT2=P3^3;         //电机下降
              sbit         INTPUT3=P3^4;         //电机上升
              sbit         INTPUT4=P3^5;         //电磁铁
              sbit         INTPUT5=P3^6;         //
              sbit         INTPUT6=P3^7;         //
              sbit         OUT0=P2^6;            //剪刀
              sbit         OUT1=P2^7;            //气缸前进
              sbit         OUT2=P1^0;            //气缸后退
              sbit         OUT3=P1^1;            //电磁铁
              sbit         OUT4=P1^2;            //电机上升
              sbit         OUT5=P1^3;            //电机下降
              sbit         OUT6=P1^4;            //
              sbit         OUT7=P1^5;            //
              sbit         OUT8=P1^6;            //
              sbit         LED=P5^5;             //EEPROM写指示
              uint         FLAG_S;
              uchar        i;                    //循环总变量i
              #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
              #define      IAP_ADDRESS 0x1200    //时间 EEPROM首地址
              bit          Dataa_Flag;
              bit          Datab_Flag;
              typedef      unsigned char BYTE;
              typedef      unsigned int WORD;
/*************周期一*********/              
              static uint  Down_Time;            //下降延时 剪刀后下降延时
              static uint  Forward_Time;         //气缸推进延时
              static uint  Back_Time;            //气缸返回延时
/**********************/
              bit           Receive_Flag;
              bit          Run_Flag;
              uchar        kcounter,kstatus;     //按键计数标志 按键状态标志
              uint         a[10];             //定义数组a 存储串口数据串
/*------------------------------------------*/
              void delay(uint t)
              {
              uint i,j;
              for(i=0;i<t;i++)
              for(j=0;j<100;j++);
              }
/*-----------(1)延时子程序12MHz 加千百十个显示--------*/
               void Delay100ms(uint x)              //
               {
               uint i,j;
               for(i=0;i<x;i++)
               for(j=0;j<11000;j++);
               }
/*-----------(1)延时子程序12MHz 加千百十个显示--------*/
               void Delay_100ms(uint x)          //page 5 保压,上升计时  Delay100ms
               {
               uint i,j;
                for(i=0;i<x;i++)
                {
                for(j=0;j<9200;j++);
                printf("n3.val=%d\xff\xff\xff",i);//
                }
               }    
/*----关闭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)
              {
              uint m,n;         
              m=IapReadByte(IAP_ADDRESS+0);  //时间前八位
              n=IapReadByte(IAP_ADDRESS+1);  //时间后八位
              Down_Time=m*256+n;             //下降延时
              m=IapReadByte(IAP_ADDRESS+2);  //时间前八位
              n=IapReadByte(IAP_ADDRESS+3);  //时间后八位
              Forward_Time=m*256+n;             //推进延时
              m=IapReadByte(IAP_ADDRESS+4);  //时间前八位
              n=IapReadByte(IAP_ADDRESS+5);  //时间后八位
              Back_Time=m*256+n;             //返回延时
              LED=1;
              }
/*************写时间参数到EEPROM*******************************/
               void Write_EepromTime()
              {
               IapEraseSector(IAP_ADDRESS); //扇区擦除
               IapProgramByte(IAP_ADDRESS+0,Down_Time/256);    //下降延时    
               IapProgramByte(IAP_ADDRESS+1,Down_Time%256);  

               IapProgramByte(IAP_ADDRESS+2,Forward_Time/256); //推进延时
               IapProgramByte(IAP_ADDRESS+3,Forward_Time%256);  

               IapProgramByte(IAP_ADDRESS+4,Back_Time/256);    //返回延时
               IapProgramByte(IAP_ADDRESS+5,Back_Time%256);  

               LED=1;
               }
/*************关所有输出*******************************/             
               void reset_io()
               {
               P2M0=0X00;
               P2M1=0X00;
               P3M0=0X00;
               P3M1=0X00;
               P5M0=0X00;
               P5M1=0X00;
               OUT0=1;
               OUT1=1;
               OUT2=1;
               OUT3=1;
               OUT4=1;
               OUT5=1;
               OUT6=1;
               OUT7=1;
               OUT8=1;
               INTPUT1=1;                         //
               INTPUT2=1;                         //
               INTPUT3=1;                         //
               INTPUT4=1;                         //
               INTPUT5=1;                         //
               INTPUT6=1;                         //
               }
/****************按键计数器状态寄存器归零*************/
               void RstKey()
               {
               kcounter=0;                       //按键计数器归零
               kstatus=0;                        //状态寄存器归零
               }
/*****************按键低电平检测函数*****************/
               void   LowVoltKey(void)           //按键计数器状态标志加一
               {
               kcounter++;                       
               kstatus++;     
               delay(5);                         //延时                  
               }
/*****************按键高电平检测函数*****************/
               void    HighVoltKey(void)         //按键计数器加一 状态标志归零
               {
               kcounter++;                       //按键计数器加一
               kstatus=0;                        //按键状态标志归零
               Delay100ms(5);                         //延时
               }
/*------------页面显示---------------------*/
               void disdata()//                            
               {
                red_eeprom();
                printf("n0.val=%d\xff\xff\xff",Down_Time);        //剪刀下降延时
                printf("n0.val=%d\xff\xff\xff",Down_Time);        //剪刀下降延时
                printf("n1.val=%d\xff\xff\xff",Forward_Time);   //气缸推进延时
                printf("n2.val=%d\xff\xff\xff",Back_Time);        //气缸返回延时
               }
/*------------自动运行开始---------------------*/
              void start()
              {    
               printf("t3.txt=\"剪 刀\"");
               printf("\xff\xff\xff");//
               OUT0=0;                             //剪刀工作
               Delay100ms(12);                     //上升两秒
               OUT0=1;                             //剪刀关闭
               Delay_100ms(Down_Time);             //等待机械手释放
               OUT4=0;                           //电机上升开
               printf("t3.txt=\"上 升\"");
               printf("\xff\xff\xff");//
               Delay100ms(20);                     //上升两秒
               OUT4=1;                           //电机上升关
               printf("t3.txt=\"电磁铁\"");
               printf("\xff\xff\xff");//
               OUT3=0;                           //电磁铁启动
               Delay100ms(30);                     //等待3秒
               OUT5=0;                           //电机下降开
               printf("t3.txt=\"下 降\"");
               printf("\xff\xff\xff");//
               kcounter=0;  
               for(;kcounter<=5;)                /*寄存器复位*/
                {
                if(!INTPUT2)                     /*检测电机下降为低电平?*/
                {                     
                 kcounter++;
                 delay(10);
                }
                else if(~!INTPUT2)               /*检测手动测试电磁铁为高电平?*/
                kcounter=0;                      /*寄存器复位*/                 
                }   
               OUT3=1;                           //电磁铁关闭
               OUT5=1;                           //电机下降关
               OUT1=0;                           //气缸前进开
               printf("t3.txt=\"气缸进\"");
               printf("\xff\xff\xff");//
               Delay_100ms(Forward_Time);
               OUT1=1;                           //气缸前进关
               OUT2=0;                             //气缸后退开
               printf("t3.txt=\"气缸退\"");
               printf("\xff\xff\xff");//
               Delay_100ms(Back_Time);
               OUT2=1;                             //气缸后退关
               Delay100ms(20);                     //暂停两秒
               OUT4=0;                           //电机上升
               printf("t3.txt=\"上 升\"");
               printf("\xff\xff\xff");//
               RstKey();
               kcounter=0;  
               for(;kcounter<=5;)                /*寄存器复位*/
                {
                if(!INTPUT3)                     /*检测手动测试电磁铁为低电平?*/
                {                     
                 kcounter++;
                 delay(10);
                }
                else if(~!INTPUT3)               /*检测手动测试电磁铁为高电平?*/
                kcounter=0;                      /*寄存器复位*/                 
                }   
               OUT4=1;                           //电机上升关
               printf("t3.txt=\"停 止\"");
               printf("\xff\xff\xff");//
              }
/*------------初始化串口---------------------*/
              void InitUart()
              {
              SCON=0X50;                         //8位数据,可变波特率
              AUXR|=0x01;                        //串口1选择定时器2为波特率发生器
              AUXR|=0X04;                        //定时器2时钟为Fosc,即1T
              T2L=0XE0;                          //设置定时器处置  110592》9600
              T2H=0XFE;                          //设置定时器处置  110592》9600
              AUXR|=0X10;                        //启动定时器2
              TI=1;                                 //
              ES=1;                                 //
              EA=1;                                 //
              }
/*×--------UART 中断服务程序-------------------**/
/**×**把接收到的数据存进数组a[i]**i开机初始化****/
/***×*接收到触摸屏结束码Receive_Flag标志位置1****/
/****×主程序检测到标志码=1判断指令功能***********/
              void Uart() interrupt 4 using 1
              {
               if(RI)
               {
                if(SBUF==0XFA||SBUF==0XFF)         //触摸屏结束码
                {
                Receive_Flag=1;                     //接收数据标志置一
                RI=0;                             //
                i=0;                             //数组计数器归零
                }
                else
                {
                a[i]=SBUF;                        //数组下标位置的数据等于SBUF
                RI=0;                              //
                i++;
                }
               }
              }
/*************************************************/
              void   main( )                      /*主程序开始*/
              {
               reset_io();
               LED=0;
               Delay100ms(300);                    //延时(30)等触摸屏先启动
               AUXR=0X80;                         //STC系列的1T 设置
               TMOD=0X01;
               P_SW1=0x00;                        //RXD/P3.0, TXD/P3.1
               Receive_Flag=0;    
               InitUart();                        //初始化串口
               printf("0XFF,0XFF,0XFF");
               disdata();                       //
               Run_Flag=0;
               FLAG_S=6;                          //1下降 2上升 3停止 4结束5保压6待机7周期一8周期二9周期三
               printf("va0.val=%d\xff\xff\xff",FLAG_S);    //
               i=0;                               //数据接收计数器等于0
               while(1)            //INTPUT1
               {
                if(Dataa_Flag==1)
                {
                Dataa_Flag=0;    //复位
                disdata();
                }

               if(Receive_Flag==1)
               {
                Receive_Flag=0;                     //重新接收
/**********************/
                 if(a[0]==0XE0)            
                 {
                  if(a[1]==0X00)                  
                  {
                  Dataa_Flag=1;
                  Down_Time=a[3]*256+a[2];       //下降延时 剪刀后下降延时
                  printf("n3.val=%d\xff\xff\xff",Down_Time);//数据校对
                  }
                  else if(a[1]==0X01)
                  {
                  Dataa_Flag=1;
                  Forward_Time=a[3]*256+a[2];      //气缸前进    
                  printf("n3.val=%d\xff\xff\xff",Forward_Time);    //
                  }
                  else if(a[1]==0X02)       
                  {
                  Dataa_Flag=1;
                  Back_Time=a[3]*256+a[2];         //气缸返回
                  printf("n3.val=%d\xff\xff\xff",Back_Time);    //
                  }
                 LED=0;
                 Write_EepromTime();
                }
                else if(a[0]==0XE2&&a[1]==0XA1)        //E2 A1刷新显示
                {
                 Dataa_Flag=1;
                }
               }  
///    检测行程开关启动剪刀
               RstKey();
               for(;kcounter<5;)                //按键循环5次
               {
                if(!INTPUT1)                    //按键低电平
                {
                LowVoltKey();                   //按键低电平 计数器加一状态标志加一
                }
                else if(~!INTPUT1)              //按键高电平
                {
                HighVoltKey();                  //按键计数器加一    状态标志归零
                }
               }
               if(kstatus>=3)                   /*按键状态标志大于等于3为有效值*/
               {  
               start();
               }
///     测试电磁铁
               RstKey();
               for(;kcounter<5;)                //按键循环5次
               {
                if(!INTPUT4)                    //按键低电平
                {
                LowVoltKey();                   //按键低电平 计数器加一状态标志加一
                }
                else if(~!INTPUT4)              //按键高电平
                {
                HighVoltKey();                  //按键计数器加一    状态标志归零
                }
               }
               if(kstatus>=3)                   /*按键状态标志大于等于3为有效值*/
               {  
               OUT3=0;                              //手动测试电磁铁开
               }
               kcounter=0;  
               for(;kcounter<=5;)                /*寄存器复位*/
                {
                if(~!INTPUT4)                    /*检测手动测试电磁铁为高电平?*/
                {                     
                 kcounter++;
                 delay(10);
                }
                else if(!INTPUT4)                /*检测手动测试电磁铁为低电平?*/
                kcounter=0;                      /*寄存器复位*/                 
                }   
               OUT3=1;                              //手动测试电磁铁关
              }     
            }                                     //L407 CODE 2421 2021 5 28

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com