⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dph.c

📁 动平衡机 51单片机
💻 C
📖 第 1 页 / 共 5 页
字号:
          {
          busy();
          LCDS=0x80+cp*8;
          }
          break;
          case 2:
          cp++;
          if(cp>3)  cp=0;
          if(cp>=2)
          {
          busy();
          LCDS=0xc0+(cp-2)*8;
          }
          else
          {
          busy();
          LCDS=0x80+cp*8;
          }
          break;
          case 3:
          if((cp==0)||(cp==1)) 
          {
          if(keybit==1)
          {
           do{
             key=getkey();
           /*  if(key==0xff)
             d2ms();
             key=getkey(); */
             }while(key!=0xff);
           keybit=0;
          }
           lrfb();
           cp=0;
           re_scr=1;
           menu_state=9;
          }
          else if(cp==2)
          {
          menu_state=10;
          cp=0;
          re_scr=1;
          }
          else if(cp==3)
          {
          menu_state=11;
          cp=0;
          re_scr=1;
          }
          break;
         }
       }






       void state10(void)    
       {
        uchar xdata i,c;
        switch(key)
         {
          case 2:
          cp++;
          if(cp>=3)
          {
          cp=0;
          busy();
          LCDS=0x84;
          }
          else
          {
           if(cp==2)
           {
           busy();
           LCDS=0x14;
           busy();
           LCDS=0x14;
           }
           else
           {
           busy();
           LCDS=0x14;
           }
          }
          break;
          case 1:
          busy();
          c=LCDR;
          busy();
          LCDS=0x10;
          if(c>=0x39) c=0x30;
          else c++;
          busy();
          LCDD=c;
          busy();
          LCDS=0x10;
          break;
          case 3:
          busy();
          LCDS=0x84;
          for(i=0;i<4;i++)
          {
          busy();
          c=LCDR;
          lcd_buf[20][i+4]=c;
          set_buf[i]=c;
          }
          set_buf[4]=0x00;
          gml=atof(set_buf);
          if(keybit==1)
          {
           do{
             key=getkey();
             if(key==0xff)
             d2ms();
             key=getkey();
             }while(key!=0xff);
           keybit=0;
          }
          lrfb();
          menu_state=9;
          cp=0;
          re_scr=1;
          break;
         }
       }
       void state11(void)     /*03状态下各键功能*/
       {
        uchar xdata i,c;
        switch(key)
         {
          case 2:
          cp++;
          if(cp>=3)
          {
          cp=0;
          busy();
          LCDS=0x84;
          }
          else
          {
           if(cp==2)
           {
           busy();
           LCDS=0x14;
           busy();
           LCDS=0x14;
           }
           else
           {
           busy();
           LCDS=0x14;
           }
          }
          break;
          case 1:
          busy();
          c=LCDR;
          busy();
          LCDS=0x10;
          if(c>=0x39) c=0x30;
          else c++;
          busy();
          LCDD=c;
          busy();
          LCDS=0x10;
          break;
          case 3:
          busy();
          LCDS=0x84;
          for(i=0;i<4;i++)
          {
          busy();
          c=LCDR;
          lcd_buf[22][i+4]=c;
          set_buf[i]=c;
          }
          set_buf[4]=0x00;
          gmr=atof(set_buf);
          if(keybit==1)
          {
           do{
             key=getkey();
             if(key==0xff)
             d2ms();
             key=getkey();
             }while(key!=0xff);
           keybit=0;
          }
          lrfb();
          menu_state=9;
          cp=0;
          re_scr=1;
          break;
         }
       }

       void state12(void)    
       {
         uchar xdata i,c; 
         switch(key)
         {
          case 2:
          if(cp==2)  cp=0 ;
          else       cp++ ;
          if(cp==0)
          {
           busy();
           LCDS=0x89;
          }
          else if(cp==1)
          {
           busy();
           LCDS=0x8a;
          }
          else if(cp==2)
          {
           busy();
           LCDS=0xc9;
          }
          break;
          case 1:
          busy();
          c=LCDR;
          busy();
          LCDS=0x10;
          if(cp==1)
          {
           if(c>=0x39) c=0x31;
           else        c++;
           }
           else if(cp==0)
          {
           if(c>=0x39) c=0x30;
           else        c++;
          }
           else if(cp==2)
            {
               if(c=='+')   c='-';
               else         c='+';
            }
          busy();
          LCDD=c;
          busy();
          LCDS=0x10;
          break;
          case 3:
          menu_state=0;
          cp=0;
          re_scr=1;
          busy();
          LCDS=0x89;
          for(i=0;i<2;i++)
          {
          busy();
          c=LCDR;
          set_buf[i]=c;
          lcd_buf[24][9+i]=c;
          }
          busy();
          LCDS=0x10;
          busy();
          LCDS=0x10;
          set_buf[2]=0x00;
          compen.t=atoi(set_buf); 
          busy();
          LCDS=0xc9;
          add=LCDR;
          if(add=='+')
          {
            lcd_buf[25][9]='+';
            BITIO=0x00;
            BITIO=0x03;
           }
          else
          {

           lcd_buf[25][9]='-';
           BITIO=0x02;
           BITIO=0x01;
           }
          break;
         }
       }

       void state13(void)
       {
          bit sim_save;
          uchar i;
          float xdata ul_sim;
          float xdata ur_sim;
          switch(key)
         {
          case 3:
          if(cp==2)
          {
           menu_state=0;
           re_scr=1;
           cp=0;
           sim_save=sim;
           sim=0;
           EX1=1;
           ul_sim=0;
           ur_sim=0;
           busy();
           LCDS=0x01;
           busy();
           LCDS=0xc0;
           lcddsp(sim_inf); 
           key=0xff;
           ulx_ave=0;
           uly_ave=0;
           urx_ave=0;
           ury_ave=0;
           ad_count=1;
           while((key!=MENU)&&(lock!=0))
           {
            key=getkey();
            if(data_redy==1)
            {
             caluxy();
             ulx_sim=test.ul_x;
             uly_sim=test.ul_y;
             urx_sim=test.ur_x;
             ury_sim=test.ur_y;
             ul_sim-=test.ul;
             ul_sim=fabs(ul_sim);
             if(ul_sim>999.9)  ul_sim=999.9;
             ur_sim-=test.ur;
             ur_sim=fabs(ur_sim);
             if(ur_sim>999.9)  ur_sim=999.9;
             sprintf(ul_sim_buf,"L:%3.1f&",ul_sim);
             sprintf(ur_sim_buf,"R:%3.1f&",ur_sim);
             ul_sim=test.ul;
             ur_sim=test.ur;
             data_redy=0;
             busy();
             LCDS=0x82;
             for(i=0;i<5;i++)
             {
              busy();
              LCDD='0';
             }
             busy();
             LCDS=0x80;
             lcddsp(ul_sim_buf);
             busy();
             LCDS=0x8b;
             for(i=0;i<5;i++)
             {
              busy();
              LCDD='0';
             }
             busy();
             LCDS=0x89;
             lcddsp(ur_sim_buf);
             }
            }
            if(key==MENU)
            {
             sim=1;
             BITIO=0x80;
            }
           else
            sim=sim_save;
          }
          else  if(cp==0)
          {
           menu_state=0;
           cp=0;
           re_scr=1;
           sim=1;
           BITIO=0x80;
          }
          else  if(cp==1)
          {
           menu_state=0;
           cp=0;
           re_scr=1;
           sim=0;
           BITIO=0x81;
          }
          break;
          case 2:
          cp++  ;
          if(cp>2)
          {
           cp=0;
           busy();
           LCDS=0x82;
          }
          else if(cp==1)
          {
           busy();
           LCDS=0x87;
          }
          else if(cp==2)
          {
           busy();
           LCDS=0xc2;
          }
          break;
          case 1:
          if(cp==0) cp=2;
          else      cp--;
          if(cp==0)
          {
           busy();
           LCDS=0x82;
          }
          else if(cp==1)
          {
           busy();
           LCDS=0x87;
          }
          else if(cp==2)
          {
           busy();
           LCDS=0xc2;
          }
          break;
         } 
       }  

       unsigned char getkey(void)
       {
        unsigned  char  xdata r,c,t;
        scan: KEYR=0x00;
        t=0;
        if((KEYC&0x03)!=0x03)
        d2ms();
        else
        return(0xff);
        if((KEYC&0x03)!=0x03)
        {
         r=0x01;
         do{
          KEYR=255-r;
          if((KEYC&0x03)!=0x03)
          {
           r=t;
           c=(KEYC&0x03);
           if(c==0x01)  t=1;
           else         t=0;
            t=t*8+r;
            if(t>15) return(0xff);
            else     return(t);
           }
          r<<=1;
          t++;
         }while(t<8);
        }
        return(0xff);
     }



        void lcdset(void)
        {
          uchar xdata r;
          busy();
          LCDS=0x38;
          busy();
          LCDS=0x06;
          busy();
          LCDS=0x0e;
          busy();
          LCDS=0x01;
       }

       void  lcddsp(char *buf)
       {
        uchar xdata r;
        r=0;
        while((buf[r]!='&')&&(r<17))
        {
         busy();
         LCDD=buf[r];
         r++;
        }
       }

       void  busy(void)
       {
       do{
          ACC=LCDB;
         }while(bsy==1);
       }

       void  d2ms(void)
       {
        uchar   r0,r1;
        for(r0=8;r0>0;r0--)
         for(r1=200;r1>0;r1--);
       }
       void  delay(void)
       {
        uchar   r0,r1;
        for(r0=100;r0>0;r0--)
         for(r1=200;r1>0;r1--);
       }
       void  beep(void)
       {
          P1_3=0;
          d2ms();
          d2ms();
          d2ms();
          d2ms();
          P1_3=1;
        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -