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

📄 touchscreen.c

📁 该程序是触摸屏控制电机转动试验,在armlinux下
💻 C
字号:
#include"../ucos-ii/includes.h"              
#include "../ucos-ii/add/osaddition.h"
#include "../inc/drivers.h"
#include "../inc/MotorCtrl.h"
#include "../inc/sys/lib.h"
#include "../src/gui/gui.h"
#include <string.h>
#include <stdio.h>

#define rTCON  (*(volatile unsigned *)0x51000008)
#define MCLK (50700000)
#define MOTOR_SEVER_FRE		1000		//20kHz
#define MOTOR_CONT				(MCLK/2/2/MOTOR_SEVER_FRE)
#define MOTOR_MID				(MOTOR_CONT/2)
#define Speedup1  0.1
#define Speedup2  0.2
#define Speedup3  0.3
#define Speedup4  0.4
#define Speeddown1  0.1
#define Speeddown2  0.2
#define Speeddown3  0.3
#define Speeddown4  0.4
int TchScr_Xmin=145,TchScr_Xmax=902, TchScr_Ymin=142,TchScr_Ymax=902;
 void touch_screen(U32 nkey, double *t,int *f,int *chag)
{   
    int LARGE=1;
     int x,y;
     
     x=nkey&0xffff;
     y=(nkey&0xffff0000)>>16;
  
     
   
     
     if((x>=330&&x<=630)&&(y>=330&&y<=380))//start
         
          { *t=0.1;
           *f=1;
     
        
            }
     else if((x>=330&&x<=620)&&(y>=390&&y<=440))//stop
  
          {  *t=0;
           *f=0;
        
          
           }
     else if((x>=20&&x<=80)&&(y>=180&&y<=240)&&*f)//speedupstep
      
      
       {  if((*t+0.1)<LARGE)
             *t=(*t)+0.1;
             else *t=LARGE;
        
       }
     
     else if((x>=20&&x<=80)&&(y>=340&&y<=400)&&*f)//speeddownstep  
        {
         if((*t-0.1)>0)
         *t=(*t)-0.1;
         else *t=0;
         }
     else if(y>=250&&y<=310&&*f) 
     {
       if(x>=20&&x<=90)
       {
         if((*t+Speedup1)<LARGE)
            *t=(*t)+Speedup1;
         else *t=LARGE;
         }
         
       else if(x>90&&x<=160)
       {
         if((*t+Speedup2)<LARGE)
          *t=(*t)+Speedup2;
         else *t=LARGE;
        }
         
        else if(x>160&&x<=230)
        {
         if((*t+Speedup3)<LARGE)
         *t=(*t)+Speedup3;
         else *t=LARGE;
        }
	   else if(x>230&&x<=300)
	   {
         if((*t+Speedup4)<LARGE)
          *t=(*t)+Speedup4;
         else *t=LARGE;
        }
      
    }
   else if(y>=410&&y<=470&&*f) 
    {
       if(x>=20&&x<=90)
       {
         if((*t-Speeddown1)>0)
         *t=(*t)-Speedup1;
         else *t=0;
         }
         
       else if(x>90&&x<=160)
       {
         if((*t-Speeddown2)>0)
         *t=(*t)-Speedup2;
         else *t=0;
        }
         
       else if(x>160&&x<=230)
        {
        if((*t-Speeddown3)>0)
          *t=(*t)-Speedup3;
         else *t=0;
        }
	   else if(x>230&&x<=300)
	   {
        if((*t-Speeddown4)>0)
         *t=(*t)-Speedup4;
         else *t=0;
        }
   
   } 
   else if(y>=90&&y<=150&&*f) 
    {
       if(x>=20&&x<=90)
       {
        *t=0.2;
         }
         
       else if(x>90&&x<=160)
       {
        *t=0.4;
        }
         
       else if(x>160&&x<=230)
        {
          *t=0.6;
        }
	   else if(x>230&&x<=300)
	   {
         *t=0.8;
        }

  
    } 
  else if((x>=20&&x<=80)&&(y>=20&&y<=80)&&*f)
   {
    *chag=((*chag)+1)%2;
    rTCON=rTCON^(1<<2);	
   }
  else 
   {  
       printf("**&&&&&&&&&&&&&&&&&&&&&\n");
  
   }
	SetPWM((*t)*MOTOR_CONT);
  printf("%f,%d\n",*t,*chag);
	
	
	
}


⌨️ 快捷键说明

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