武汉绘芯科技有限公司欢迎您!
10余年经验沉淀展览展示运动控制的专家
全国咨询热线:027-87052087
联系我们
武汉绘芯科技有限公司
电话:027-87052087
手机:13329706647
邮箱:956693667@qq.com
地址:武汉市江夏区藏龙岛谭湖一路8号
联系人:黄先生
您的位置: 滑轨屏|绘芯科技 > 知识库 >
知识库

ARM触摸式计算器设计

日期:2016-07-29 07:45:37 来源:未知 点击

  触摸式计算器设计


 

一、设计任务

本电子系统的功能是借助ARM 7教学实验箱,使用S3C44B0三星处理器能及触摸屏及LCD显示屏等硬件编写程序来实现计算器的设计。

实验要求:

1、要用触摸屏来实现

2、能够具有触摸按键选择功能,并且具有显示数字功能

3、可以实现四则运算功能

二、软件实现流程图

三、主程序:

#include "44b.h"

#include"uhal.h"

#include "option.h"

#include"def.h"

#include "tchScr.h"

#include"myuart.h"

#include "tchScr.h"

#include "maro.h"

#pragma import(__use_no_semihosting_swi)  // ensure no functions that use semihosting

extern U32 LCDBuffer[240][320];

U32 jcolor;

int number =0;//记录数字

int number1=0;

char signal;

int main(void)

{

int i,j,k;

int m,n;

 

 

 

 

   ARMTargetInit();   //开发版初始化

   LCD_Init();        //LCD初始化

  

 

 

 

 /* for (i=0;i<9;i++)

     {  switch (i)

        {  case 0: jcolor=0x00000000;  //RGB均为0   黑色

                   break;

           case 1: jcolor=0x000000e0;  //R   红色

                   break;

           case 2: jcolor=0x0000d0e0;  //R  and G 橙色

                   break;

           case 3: jcolor=0x0000e0e0;   //R  and G

                   break;

           case 4: jcolor=0x0000e000;  //G  绿色

                   break;

           case 5: jcolor=0x00e0e000;  //G  B   青色

                   break;

           case 6: jcolor=0x00e00000;  //B    蓝色

                   break;

           case 7: jcolor=0x00e000e0;  //R  and B   紫色

                   break;

           case 8: jcolor=0x00e0e0e0;  //RGB   白色

                   break;  

         }

       */

    

         

         

    jsqInit();

    getNum(235,7,0);

     LCD_Refresh() ;  

    while(1){

    TchScr_Test();

     Delay(1000);

    }

   return 0;

}

 getNum(int x,int y,int num){

   int i,j;

   for(i=x;i<=x+8;i++)

      for(j=y;j<=y+14;j++)

      {

         LCDBuffer[j][i]=0x00000000;

         switch(num){

            case 0:if(i==x||i==x+8) LCDBuffer[j][i]=0x0000e000;

                   if(j==y||j==y+14) LCDBuffer[j][i]=0x0000e000;

                   break;

            case 1:if(i==x+8) LCDBuffer[j][i]=0x0000e000;

                   break;

            case 2:if(j==y||j==y+7||j==y+14) LCDBuffer[j][i]=0x0000e000;

                   if((i==x&&j>=y+7)||(i==x+8&&j<=y+7))  LCDBuffer[j][i]=0x0000e000;

                   break;

            case 3:if(j==y||j==y+7||j==y+14) LCDBuffer[j][i]=0x0000e000;

                   if(i==x+8) LCDBuffer[j][i]=0x0000e000;

                   break;

            case 4:  if(j==y+7) LCDBuffer[j][i]=0x0000e000;

                   if(i==x&&j<=y+7) LCDBuffer[j][i]=0x0000e000;

                   if(i==x+8) LCDBuffer[j][i]=0x0000e000;

                   break;

            case 5:if(j==y||j==y+7||j==y+14) LCDBuffer[j][i]=0x0000e000;

                   if((i==x&&j<=y+7)||(i==x+8&&j>=y+7)) LCDBuffer[j][i]=0x0000e000;

                   break;

            case 6:if(j==y||j==y+7||j==y+14) LCDBuffer[j][i]=0x0000e000;

                   if(i==x||(i==x+8&&j>=y+7))  LCDBuffer[j][i]=0x0000e000;

                   break;

            case 7:if(i==x+8)  LCDBuffer[j][i]=0x0000e000;

                   if(j==y)  LCDBuffer[j][i]=0x0000e000;

                   break;

            case 8:if(j==y||j==y+7||j==y+14) LCDBuffer[j][i]=0x0000e000;

                   if(i==x||i==x+8) LCDBuffer[j][i]=0x0000e000;

                   break;

            case 9:if(j==y||j==y+7||j==y+14) LCDBuffer[j][i]=0x0000e000;

                   if((i==x&&j<=y+7)||i==x+8) LCDBuffer[j][i]=0x0000e000;

                   break;

            }

         }

}

getOp(){

   int i,j;

   for(i=235;i<=243;i++)

      for(j=7;j<21;j++)

      {

         switch(signal){

            case '+':if(j==14||i==239) LCDBuffer[j][i]=0x00e00000;break;

            case '-':if(j==14) LCDBuffer[j][i]=0x00e00000;break;

            case '*':if(j+i==245||j-i==221)LCDBuffer[j][i]=0x00e00000;break;

            case '/':if(j-i==221)LCDBuffer[j][i]=0x00e00000;break;

         }

      }

}

 jsqInit(){

int k,i,j;

 for (k=0;k<260;k++)

        for (j=i*32;j<i*32+32;j++)

          {

         

          LCDBuffer[2][k+10]= 0x00e00000;

       

           LCDBuffer[42][k+10]= 0x00e00000;

          

           LCDBuffer[215][105]= 0x00e00000;//'.'

          

           LCDBuffer[107][235]= 0x00e00000;//'/'

           LCDBuffer[117][235]= 0x00e00000;//'/'

          

           }

          

          

 

        

            for (k=0;k<10;k++)

        for (j=i*32;j<i*32+32;j++)

          {

         

          LCDBuffer[57][k+100]= 0x00e00000;//2’的位置

           LCDBuffer[67][k+100]= 0x00e00000;

           LCDBuffer[77][k+100]= 0x00e00000;

          

          

            LCDBuffer[57][k+165]= 0x00e00000;//3’的位置

            LCDBuffer[67][k+165]= 0x00e00000;

            LCDBuffer[77][k+165]= 0x00e00000;

          

           LCDBuffer[112][k+35]= 0x00e00000;//4’的位置

          

           

           LCDBuffer[102][k+100]= 0x00e00000;//5’的位置

           LCDBuffer[112][k+100]= 0x00e00000;

           LCDBuffer[122][k+100]= 0x00e00000;

              

           LCDBuffer[102][k+165]= 0x00e00000;//6’的位置

           LCDBuffer[112][k+165]= 0x00e00000;

           LCDBuffer[122][k+165]= 0x00e00000;

          

           LCDBuffer[147][k+35]= 0x00e00000;//7’的位置

          

           LCDBuffer[147][k+100]= 0x00e00000;//8’的位置

           LCDBuffer[157][k+100]= 0x00e00000;

           LCDBuffer[167][k+100]= 0x00e00000;

          

           LCDBuffer[147][k+165]= 0x00e00000;//9’的位置

           LCDBuffer[157][k+165]= 0x00e00000;

           LCDBuffer[167][k+165]= 0x00e00000;

          

           LCDBuffer[192][k+35]= 0x00e00000;//0’的位置

           LCDBuffer[212][k+35]= 0x00e00000;

          

           LCDBuffer[157][k+230]= 0x00e00000;//-’的位置

          

           LCDBuffer[202][k+165]= 0x00e00000;//+’的位置

          

           LCDBuffer[200][k+230]= 0x00e00000;//=’的位置

           LCDBuffer[204][k+230]= 0x00e00000;

          

          

           LCDBuffer[112][k+230]= 0x00e00000;//'/'

          

           

          

          

           }

          

          

          

           

           for (k=0;k<60;k++)

        for (j=i*32;j<i*32+32;j++)

          {

         

         

          

           LCDBuffer[47][k+10]= 0x00e00000;

           LCDBuffer[87][k+10]= 0x00e00000;

          

          

          

           LCDBuffer[47][k+75]= 0x00e00000;

           LCDBuffer[87][k+75]= 0x00e00000;

          

           LCDBuffer[47][k+140]= 0x00e00000;

           LCDBuffer[87][k+140]= 0x00e00000;

 

           LCDBuffer[47][k+205]= 0x00e00000;

           LCDBuffer[87][k+205]= 0x00e00000;

          

          

          

          

          

          

           LCDBuffer[92][k+10]= 0x00e00000;

           LCDBuffer[132][k+10]= 0x00e00000;

          

           LCDBuffer[92][k+75]= 0x00e00000;

           LCDBuffer[132][k+75]= 0x00e00000;

          

           LCDBuffer[92][k+140]= 0x00e00000;

           LCDBuffer[132][k+140]= 0x00e00000;

 

           LCDBuffer[92][k+205]= 0x00e00000;

           LCDBuffer[132][k+205]= 0x00e00000;

          

         

          

          

          

           

           LCDBuffer[137][k+10]= 0x00e00000;

           LCDBuffer[177][k+10]= 0x00e00000;

          

           LCDBuffer[137][k+75]= 0x00e00000;

           LCDBuffer[177][k+75]= 0x00e00000;

          

           LCDBuffer[137][k+140]= 0x00e00000;

           LCDBuffer[177][k+140]= 0x00e00000;

 

           LCDBuffer[137][k+205]= 0x00e00000;

           LCDBuffer[177][k+205]= 0x00e00000;

           

          

          

           LCDBuffer[182][k+10]= 0x00e00000;

           LCDBuffer[222][k+10]= 0x00e00000;

          

           LCDBuffer[182][k+75]= 0x00e00000;

           LCDBuffer[222][k+75]= 0x00e00000;

          

           LCDBuffer[182][k+140]= 0x00e00000;

           LCDBuffer[222][k+140]= 0x00e00000;

 

           LCDBuffer[182][k+205]= 0x00e00000;

           LCDBuffer[222][k+205]= 0x00e00000;

          

         

          

           }

         

  jcolor=0x00e00000;

  for (i=0;i<40;i++)

      {

      if (i==80||i==160)

         jcolor<<=8;

       for (j=288;j<320;j++) 

       {

      

       LCDBuffer[i+2][10]=0x00e00000;

       LCDBuffer[i+2][270]=0x00e00000;

      

      

      

      

      

      

       LCDBuffer[i+47][10]=0x00e00000;

      

     

      

       LCDBuffer[i+47][70]=0x00e00000;

       LCDBuffer[i+47][75]=0x00e00000;

       LCDBuffer[i+47][135]=0x00e00000;

       LCDBuffer[i+47][140]=0x00e00000;

       LCDBuffer[i+47][200]=0x00e00000;

       LCDBuffer[i+47][205]=0x00e00000;

       LCDBuffer[i+47][265]=0x00e00000;

      

      

      

      

       LCDBuffer[i+92][10]=0x00e00000;

       LCDBuffer[i+92][70]=0x00e00000;

       LCDBuffer[i+92][75]=0x00e00000;

       LCDBuffer[i+92][135]=0x00e00000;

       LCDBuffer[i+92][140]=0x00e00000;

       LCDBuffer[i+92][200]=0x00e00000;

       LCDBuffer[i+92][205]=0x00e00000;

       LCDBuffer[i+92][265]=0x00e00000;

      

      

       LCDBuffer[i+137][10]=0x00e00000;

       LCDBuffer[i+137][70]=0x00e00000;

       LCDBuffer[i+137][75]=0x00e00000;

       LCDBuffer[i+137][135]=0x00e00000;

       LCDBuffer[i+137][140]=0x00e00000;

       LCDBuffer[i+137][200]=0x00e00000;

       LCDBuffer[i+137][205]=0x00e00000;

       LCDBuffer[i+137][265]=0x00e00000;

      

      

       

       LCDBuffer[i+182][10]=0x00e00000;

       LCDBuffer[i+182][70]=0x00e00000;

       LCDBuffer[i+182][75]=0x00e00000;

       LCDBuffer[i+182][135]=0x00e00000;

       LCDBuffer[i+182][140]=0x00e00000;

       LCDBuffer[i+182][200]=0x00e00000;

       LCDBuffer[i+182][205]=0x00e00000;

       LCDBuffer[i+182][265]=0x00e00000;

     

     

     

       }

      

       }

       jcolor=0x00e00000;

  for (i=0;i<10;i++)

      {

      if (i==80||i==160)

         jcolor<<=8;

       for (j=288;j<320;j++) 

       {

      

     

     

     

        LCDBuffer[i+67][100]=0x00e00000;// ‘2’

         LCDBuffer[i+57][110]=0x00e00000;

        

         LCDBuffer[i+102][35]=0x00e00000;// ‘4’

        

         LCDBuffer[i+102][100]=0x00e00000;// ‘5’

         LCDBuffer[i+112][110]=0x00e00000;

        

         LCDBuffer[i+112][175]=0x00e00000;// ‘6’

        

          LCDBuffer[i+147][165]=0x00e00000; // ‘9’

      

       LCDBuffer[i+197][170]=0x00e00000; // ‘+’

        }

      

      

        }

        

       jcolor=0x00e00000;

  for (i=0;i<20;i++)

      {

      if (i==80||i==160)

         jcolor<<=8;

       for (j=288;j<320;j++) 

       {

      

         LCDBuffer[i+62][40]=0x00e00000;//‘1’

        

         LCDBuffer[i+57][175]=0x00e00000;//‘3’

        

         LCDBuffer[i+102][40]=0x00e00000;//‘4’

        

         LCDBuffer[i+102][165]=0x00e00000;//‘6’ 

        

          LCDBuffer[i+147][45]=0x00e00000;//‘7’

         

          LCDBuffer[i+147][100]=0x00e00000;//‘8’

          LCDBuffer[i+147][110]=0x00e00000;

          

          LCDBuffer[i+147][175]=0x00e00000;//‘9’

         

          LCDBuffer[i+192][35]=0x00e00000;//‘0’

          LCDBuffer[i+192][45]=0x00e00000;  

        }

      

      

        }

        //return;

  // }      

         

}

tchNum(int x,int y){

   int i;

   int x1,y1;

   x1=(x-5)/65;

   y1=(y-42)/45;

   if(number<99999999||(x1==1&&y1==3)||(x1==2&&y1==3)||x1==3){

   switch(x1){

      case 0:switch(y1){

                case 0:number=number*10+1;return;

                case 1:number=number*10+4;return;

                case 2:number=number*10+7;return;

                case 3:number=number*10;return;

            }

      case 1:switch(y1){

                case 0:number=number*10+2;return;

                case 1:number=number*10+5;return;

                case 2:number=number*10+8;return;

                case 3:signal='*';clear();getOp(); number1=number;number=0;return;

            }

           

      case 2:switch(y1){

                case 0:number=number*10+3;return;

                case 1:number=number*10+6;return;

                case 2:number=number*10+9;return;

                case 3:signal='+';

                      clear();

                      getOp();

                      number1=number;

                      number=0;

                return;

            }

           

      case 3:switch(y1){

                case 0:number=0;

                      number1=0;

                      clear();

                      getNum(235,7,0);

                      return;

                case 1:signal='/';clear();getOp(); number1=number;number=0;return;

                case 2:signal='-';clear();getOp(); number1=number; number=0;return;

                case 3:operation();return;

            }       

   }

   }

}

showNum()

{

   //tchNum();

   int ws=1;

   int n;

   n=number;

   Uart_Printf("$$$$$$$$number=%d",n);

   Uart_Printf("$$$$$$$$number=%d",number);

   if(number<0) {isFu();n=-n;}

   while(n!=0||n/10!=0){

      switch(ws){

         case 1:getNum(235,7,n%10);break;

         case 2:getNum(220,7,n%10);break;

         case 3:getNum(205,7,n%10);break;

         case 4:getNum(190,7,n%10);break;

         case 5:getNum(175,7,n%10);break;

         case 6:getNum(160,7,n%10);break;

         case 7:getNum(145,7,n%10);break;

         case 8:getNum(130,7,n%10);break;

         case 9:getNum(115,7,n%10);break;

      }

      ws++;

      n=n/10;

   }

 

}

 clear(){

   int i,j;

   for(i=115;i<=235;i=i+15)

   getNum(i,7,10);

   for(i=100;i<=108;i++)

      for(j=7;j<21;j++)

      {

         if(j==14) LCDBuffer[j][i]=0x00e0e0e0;break;

      }

}

 operation(){

   switch(signal){

   case '+': number = number+number1;

            clear();

            break;

   case '-':number = number1-number;

            clear();

            break;

   case '*':number = number*number1;

            clear();

            break;

   case '/':number = number1/number;

            clear();

            break;

      }

}

isFu(){

   int i,j;

   for(i=100;i<=108;i++)

      for(j=7;j<21;j++)

      {

         if(j==14) LCDBuffer[j][i]=0x00e0e0e0;break;

      }

}

四、实验结果显示

 

五、实验心得

1在做计算器时,第一步关键是要将触摸屏校准,使用触摸屏实验程序,通过超级终端将坐标打印出来,从而去调整TchScr_Xmax, TchScr_Xmin, TchScr_Ymax,  TchScr_Ymin四个坐标值,使得触摸屏与LCD显示屏能够正确的对应

2在坐标对应的过程中,首先要确定实际触摸屏的XY坐标方向,以及程序中的XY坐标方向是不是已经和实际坐标对应起来,否则容易出现后面按键时出现按键错位。

3运算时候要注意数据类型。

 

 


在线客服
联系方式

热线电话

13329706647

上班时间

周一到周五

公司电话

027-87052087

二维码
线