分享一个硬件SPI读取TFT触摸屏程序

#include \"touch.h\"

#include \"lcd.h\"

#include \"delay.h\"

#include \"stdlib.h\"

#include \"math.h\"

#include \"24cxx.h\"   

#include \"spi.h\"

#include \"mmc_sd.h\"

#include \"led.h\"

#define SPI_TOUCH

 

Pen_Holder Pen_Point;//定义笔实体

//默认为touchtype=0的数据.

u8 CMD_RDX=0XD0;

u8 CMD_RDY=0X90;

// void ADS_Write_Byte(u8 num)   

// { 

//  u8 count=0;  

//  for(count=0;count<8;count++) 

//  {    

//      if(num&0x80)TDIN=1; 

//      else TDIN=0;  

//      num<<=1;   

//      TCLK=0;//上升沿有效      

//      TCLK=1;     

//  }              

// }        

//从7846/7843/XPT2046/UH7843/UH7846读取adc值      

u16 ADS_Read_AD(u8 CMD)  

{        

    u16 Num=0;

#ifndef SPI_TOUCH  

    u8 count=0;

#endif

    TCLK=0;                    //先拉低时钟  

    TCS=0;                     //选中ADS7843

#ifdef SPI_TOUCH

  SPI2_SetSpeed(SPI_SPEED_16); 

    SPI2_ReadWriteByte(CMD);   //发送命令字

#else

    ADS_Write_Byte(CMD);

#endif

    delay_us(6);               //ADS7846的转换时间最长为6us

    TCLK=1;                    //给1个时钟,清除BUSY          

    TCLK=0;

#ifdef SPI_TOUCH

  Num=SPI2_ReadWriteByte(0);

    Num<<=8;

  Num=Num|SPI2_ReadWriteByte(0);   

#else

    for(count=0;count<16;count++) 

    {                

        Num<<=1;  

        TCLK=0;//下降沿有效                

        TCLK=1;

        if(DOUT)Num++;      

    }

#endif

    Num>>=4;                   //只有高12位有效.

    TCS=1;                     //释放ADS7843  

    return(Num);  

}

//读取一个坐标值

//连续读取READ_TIMES次数据,对这些数据升序排列,

//然后去掉最低和最高LOST_VAL个数,取平均值

#define READ_TIMES 15     //读取次数

#define LOST_VAL 5        //丢弃值

u16 ADS_Read_XY(u8 xy)

{

    u16 i, j;

    u16 buf[READ_TIMES];

    u16 sum=0;

    u16 temp;

    for(i=0;i

    {               

        buf[i]=ADS_Read_AD(xy);    

    }                  

    for(i=0;i//排序

    {

        for(j=i+1;j

        {

            if(buf[i]>buf[j])       //升序排列

            {

                temp=buf[i];

                buf[i]=buf[j];

                buf[j]=temp;

            }

        }

    }    

    sum=0;

    for(i=LOST_VAL;i

    temp=sum/(READ_TIMES-2*LOST_VAL);

    return temp;  

}

//带滤波的坐标读取

//最小值不能少于100.

u8 Read_ADS(u16 *x,u16 *y)

{

    u16 xtemp,ytemp;                         

    xtemp=ADS_Read_XY(CMD_RDX);

    ytemp=ADS_Read_XY(CMD_RDY);                                                   

    if(xtemp<100||ytemp<100)return 0;//读数失败

    *x=xtemp;

    *y=ytemp;

    return 1;                        //读数成功

}  

//2次读取ADS7846,连续读取2次有效的AD值,且这两次的偏差不能超过

//50,满足条件,则认为读数正确,否则读数错误.     

//该函数能大大提高准确度

#define ERR_RANGE 50 //误差范围

u8 Read_ADS2(u16 *x,u16 *y)

{

    u16 x1,y1;

    u16 x2,y2;

    u8 flag;   

    flag=Read_ADS(&x1,&y1);  

    if(flag==0)return(0);

    flag=Read_ADS(&x2,&y2);   

    if(flag==0)return(0);  

    if(((x2<=x1&&x1//前后两次采样在+-50内

    &&((y2<=y1&&y1

    {

        *x=(x1+x2)/2;

        *y=(y1+y2)/2;

        return 1;

    }else return 0;  

}

//读取一次坐标值  

//仅仅读取一次,知道PEN松开才返回!                      

u8 Read_TP_Once(void)

{

    u8 t=0;    

    Pen_Int_Set(0);           //关闭中断

    Pen_Point.Key_Sta=Key_Up;

    Read_ADS2(&Pen_Point.X,&Pen_Point.Y);

    while(PEN==0&&t<=250)

    {

        t++;

        delay_ms(10);

    };

    Pen_Int_Set(1);//开启中断       

    if(t>=250)return 0;//按下2.5s 认为无效

    else return 1; 

}

 

//////////////////////////////////////////////////

//与LCD部分有关的函数 

//画一个触摸点

//用来校准用的

void Drow_Touch_Point(u8 x,u16 y)

{

    LCD_DrawLine(x-12,y,x+13,y);//横线

    LCD_DrawLine(x,y-12,x,y+13);//竖线

    LCD_DrawPoint(x+1,y+1);

    LCD_DrawPoint(x-1,y+1);

    LCD_DrawPoint(x+1,y-1);

    LCD_DrawPoint(x-1,y-1);

    Draw_Circle(x,y,6);//画中心圈

}    

//画一个大点

//2*2的点           

void Draw_Big_Point(u8 x,u16 y)

{      

    LCD_DrawPoint(x,y);//中心点

    LCD_DrawPoint(x+1,y);

    LCD_DrawPoint(x,y+1);

    LCD_DrawPoint(x+1,y+1);        

}

//////////////////////////////////////////////////

 

//转换结果

//根据触摸屏的校准参数来决定转换后的结果,保存在X0,Y0中

void Convert_Pos(void)

{            

    if(Read_ADS2(&Pen_Point.X,&Pen_Point.Y))

    {

        Pen_Point.X0=Pen_Point.xfac*Pen_Point.X+Pen_Point.xoff;

        Pen_Point.Y0=Pen_Point.yfac*Pen_Point.Y+Pen_Point.yoff; 

    }

}     

//中断,检测到PEN脚的一个下降沿.

//置位Pen_Point.Key_Sta为按下状态

//中断线11线上的中断检测

void EXTI9_5_IRQHandler(void)

{                   

    Pen_Point.Key_Sta=Key_Down;//按键按下

  LED0=~LED0;  

    EXTI->PR=1<<5;  //清除LINE5上的中断标志位

}

//PEN中断设置   

void Pen_Int_Set(u8 en)

{

    if(en)EXTI->IMR|=1<<5;   //开启line5上的中断    

    else EXTI->IMR&=~(1<<5); //关闭line5上的中断   

}        

//////////////////////////////////////////////////////////////////////////

//此部分涉及到使用外部EEPROM,如果没有外部EEPROM,屏蔽此部分即可

#ifdef ADJ_SAVE_ENABLE

//保存在EEPROM里面的地址区间基址,占用13个字节(RANGE:SAVE_ADDR_BASE~SAVE_ADDR_BASE+12)

#define SAVE_ADDR_BASE 40

//保存校准参数                                           

void Save_Adjdata(void)

{

      s32 temp;         

    //保存校正结果!                                    

      temp=Pen_Point.xfac*100000000;//保存x校正因素     

    AT24CXX_WriteLenByte(SAVE_ADDR_BASE,temp,4);  

      temp=Pen_Point.yfac*100000000;//保存y校正因素   

    AT24CXX_WriteLenByte(SAVE_ADDR_BASE+4,temp,4);

    //保存x偏移量

    AT24CXX_WriteLenByte(SAVE_ADDR_BASE+8,Pen_Point.xoff,2);           

    //保存y偏移量

      AT24CXX_WriteLenByte(SAVE_ADDR_BASE+10,Pen_Point.yoff,2);

    //保存触屏类型

      AT24CXX_WriteOneByte(SAVE_ADDR_BASE+12,Pen_Point.touchtype); 

      temp=0X0A;//标记校准过了

      AT24CXX_WriteOneByte(SAVE_ADDR_BASE+13,temp);         

}

//得到保存在EEPROM里面的校准值

//返回值:1,成功获取数据

//        0,获取失败,要重新校准

u8 Get_Adjdata(void)

{                    

    s32 tempfac;

//  tempfac=AT24CXX_ReadOneByte(SAVE_ADDR_BASE+13);//读取标记字,看是否校准过!      

    if(AT24CXX_ReadOneByte(SAVE_ADDR_BASE+13)==0X0A)//触摸屏已经校准过了           

    {                                                   

        tempfac=AT24CXX_ReadLenByte(SAVE_ADDR_BASE,4);        

        Pen_Point.xfac=(float)tempfac/100000000;//得到x校准参数

        tempfac=AT24CXX_ReadLenByte(SAVE_ADDR_BASE+4,4);                     

        Pen_Point.yfac=(float)tempfac/100000000;//得到y校准参数

        //得到x偏移量

        Pen_Point.xoff=AT24CXX_ReadLenByte(SAVE_ADDR_BASE+8,2);              

        //得到y偏移量

        Pen_Point.yoff=AT24CXX_ReadLenByte(SAVE_ADDR_BASE+10,2);                     

        Pen_Point.touchtype=AT24CXX_ReadOneByte(SAVE_ADDR_BASE+12);//读取触屏类型标记

        if(Pen_Point.touchtype)//X,Y方向与屏幕相反

        {

            CMD_RDX=0X90;

            CMD_RDY=0XD0;   

        }else                  //X,Y方向与屏幕相同

        {

            CMD_RDX=0XD0;

            CMD_RDY=0X90;   

        }       

        return 1;   

    }

    return 0;

}

#endif 

//

void ADJ_INFO_SHOW(u8*str)

{

    LCD_ShowString(40,40,\"x1:       y1:       \");

    LCD_ShowString(40,60,\"x2:       y2:       \");

    LCD_ShowString(40,80,\"x3:       y3:       \");

    LCD_ShowString(40,100,\"x4:       y4:       \");

    LCD_ShowString(40,100,\"x4:       y4:       \");

    LCD_ShowString(40,120,str);                   

}

      

//触摸屏校准代码

//得到四个校准参数

void Touch_Adjust(void)

{                               

    signed short pos_temp[4][2];//坐标缓存值

    u8  cnt=0; 

    u16 d1,d2;

    u32 tem1,tem2;

    float fac;    

    cnt=0;             

    POINT_COLOR=BLUE;

    BACK_COLOR =WHITE;

    LCD_Clear(WHITE);//清屏  

    POINT_COLOR=RED;//红色

    LCD_Clear(WHITE);//清屏

    Drow_Touch_Point(20,20);//画点1

    Pen_Point.Key_Sta=Key_Up;//消除触发信号

    Pen_Point.xfac=0;//xfac用来标记是否校准过,所以校准之前必须清掉!以免错误    

    while(1)

    {

        if(Pen_Point.Key_Sta==Key_Down)//按键按下了

        {

            if(Read_TP_Once())//得到单次按键值

            {                                 

                pos_temp[cnt][0]=Pen_Point.X;

                pos_temp[cnt][1]=Pen_Point.Y;

                cnt++;

            }           

            switch(cnt)

            {             

                case 1:

                    LCD_Clear(WHITE);//清屏

                    Drow_Touch_Point(220,20);//画点2

                    break;

                case 2:

                    LCD_Clear(WHITE);//清屏

                    Drow_Touch_Point(20,300);//画点3

                    break;

                case 3:

                    LCD_Clear(WHITE);//清屏

                    Drow_Touch_Point(220,300);//画点4

                    break;

                case 4:  //全部四个点已经得到

                    //对边相等

                    tem1=abs(pos_temp[0][0]-pos_temp[1][0]);//x1-x2

                    tem2=abs(pos_temp[0][1]-pos_temp[1][1]);//y1-y2

                    tem1*=tem1;

                    tem2*=tem2;

                    d1=sqrt(tem1+tem2);//得到1,2的距离

                     

                    tem1=abs(pos_temp[2][0]-pos_temp[3][0]);//x3-x4

                    tem2=abs(pos_temp[2][1]-pos_temp[3][1]);//y3-y4

                    tem1*=tem1;

                    tem2*=tem2;

                    d2=sqrt(tem1+tem2);//得到3,4的距离

                    fac=(float)d1/d2;

                    if(fac<0.95||fac>1.20||d1==0||d2==0)//不合格

                    {

                        cnt=0;

                        LCD_Clear(WHITE);//清屏

                        Drow_Touch_Point(20,20);

                        ADJ_INFO_SHOW(\"ver fac is:\");  

                        LCD_ShowNum(40+24,40,pos_temp[0][0],4,16);      //显示数值

                        LCD_ShowNum(40+24+80,40,pos_temp[0][1],4,16);   //显示数值

                        LCD_ShowNum(40+24,60,pos_temp[1][0],4,16);      //显示数值

                        LCD_ShowNum(40+24+80,60,pos_temp[1][1],4,16);   //显示数值

                        LCD_ShowNum(40+24,80,pos_temp[2][0],4,16);      //显示数值

                        LCD_ShowNum(40+24+80,80,pos_temp[2][1],4,16);   //显示数值

                        LCD_ShowNum(40+24,100,pos_temp[3][0],4,16);     //显示数值

                        LCD_ShowNum(40+24+80,100,pos_temp[3][1],4,16);  //显示数值

                        //扩大100倍显示

                        LCD_ShowNum(40,140,fac*100,3,16);//显示数值,该数值必须在95~105范围之内.

                        continue;

                    }

                    tem1=abs(pos_temp[0][0]-pos_temp[2][0]);//x1-x3

                    tem2=abs(pos_temp[0][1]-pos_temp[2][1]);//y1-y3

                    tem1*=tem1;

                    tem2*=tem2;

                    d1=sqrt(tem1+tem2);//得到1,3的距离

                     

                    tem1=abs(pos_temp[1][0]-pos_temp[3][0]);//x2-x4

                    tem2=abs(pos_temp[1][1]-pos_temp[3][1]);//y2-y4

                    tem1*=tem1;

                    tem2*=tem2;

                    d2=sqrt(tem1+tem2);//得到2,4的距离

                    fac=(float)d1/d2;

                    if(fac<0.95||fac>1.20)//不合格

                    {

                        cnt=0;

                        LCD_Clear(WHITE);//清屏

                        Drow_Touch_Point(20,20);

                        ADJ_INFO_SHOW(\"hor fac is:\");  

                        LCD_ShowNum(40+24,40,pos_temp[0][0],4,16);      //显示数值

                        LCD_ShowNum(40+24+80,40,pos_temp[0][1],4,16);   //显示数值

                        LCD_ShowNum(40+24,60,pos_temp[1][0],4,16);      //显示数值

                        LCD_ShowNum(40+24+80,60,pos_temp[1][1],4,16);   //显示数值

                        LCD_ShowNum(40+24,80,pos_temp[2][0],4,16);      //显示数值

                        LCD_ShowNum(40+24+80,80,pos_temp[2][1],4,16);   //显示数值

                        LCD_ShowNum(40+24,100,pos_temp[3][0],4,16);     //显示数值

                        LCD_ShowNum(40+24+80,100,pos_temp[3][1],4,16);  //显示数值

                        //扩大100倍显示

                        LCD_ShowNum(40,140,fac*100,3,16);//显示数值,该数值必须在95~105范围之内.

                        continue;

                    }//正确了

                                    

                    //对角线相等

                    tem1=abs(pos_temp[1][0]-pos_temp[2][0]);//x1-x3

                    tem2=abs(pos_temp[1][1]-pos_temp[2][1]);//y1-y3

                    tem1*=tem1;

                    tem2*=tem2;

                    d1=sqrt(tem1+tem2);//得到1,4的距离

     

                    tem1=abs(pos_temp[0][0]-pos_temp[3][0]);//x2-x4

                    tem2=abs(pos_temp[0][1]-pos_temp[3][1]);//y2-y4

                    tem1*=tem1;

                    tem2*=tem2;

                    d2=sqrt(tem1+tem2);//得到2,3的距离

                    fac=(float)d1/d2;

                    if(fac<0.95||fac>1.20)//不合格

                    {

                        cnt=0;

                        LCD_Clear(WHITE);//清屏

                        Drow_Touch_Point(20,20);

                        ADJ_INFO_SHOW(\"dia fac is:\");  

                        LCD_ShowNum(40+24,40,pos_temp[0][0],4,16);      //显示数值

                        LCD_ShowNum(40+24+80,40,pos_temp[0][1],4,16);   //显示数值

                        LCD_ShowNum(40+24,60,pos_temp[1][0],4,16);      //显示数值

                        LCD_ShowNum(40+24+80,60,pos_temp[1][1],4,16);   //显示数值

                        LCD_ShowNum(40+24,80,pos_temp[2][0],4,16);      //显示数值

                        LCD_ShowNum(40+24+80,80,pos_temp[2][1],4,16);   //显示数值

                        LCD_ShowNum(40+24,100,pos_temp[3][0],4,16);     //显示数值

                        LCD_ShowNum(40+24+80,100,pos_temp[3][1],4,16);  //显示数值

                        //扩大100倍显示

                        LCD_ShowNum(40,140,fac*100,3,16);//显示数值,该数值必须在95~105范围之内.

                        continue;

                    }//正确了

                    //计算结果

                    Pen_Point.xfac=(float)200/(pos_temp[1][0]-pos_temp[0][0]);//得到xfac      

                    Pen_Point.xoff=(240-Pen_Point.xfac*(pos_temp[1][0]+pos_temp[0][0]))/2;//得到xoff

                           

                    Pen_Point.yfac=(float)280/(pos_temp[2][1]-pos_temp[0][1]);//得到yfac

                    Pen_Point.yoff=(320-Pen_Point.yfac*(pos_temp[2][1]+pos_temp[0][1]))/2;//得到yoff 

 

                    if(abs(Pen_Point.xfac)>2||abs(Pen_Point.yfac)>2)//触屏和预设的相反了.

                    {

                        cnt=0;

                        LCD_Clear(WHITE);//清屏

                        Drow_Touch_Point(20,20);

                        LCD_ShowString(35,110,\"TP Need readjust!\");

                        Pen_Point.touchtype=!Pen_Point.touchtype;//修改触屏类型.

                        if(Pen_Point.touchtype)//X,Y方向与屏幕相反

                        {

                            CMD_RDX=0X90;

                            CMD_RDY=0XD0;   

                        }else                  //X,Y方向与屏幕相同

                        {

                            CMD_RDX=0XD0;

                            CMD_RDY=0X90;   

                        }

                        delay_ms(500);

                        continue;

                    }

                    POINT_COLOR=BLUE;

                    LCD_Clear(WHITE);//清屏

                    LCD_ShowString(35,110,\"Touch Screen Adjust OK!\");//校正完成

                    delay_ms(500);

                    LCD_Clear(WHITE);//清屏  

                    return;//校正完成               

            }

        }

    }

}          

//外部中断初始化函数

void Touch_Init(void)

{                         

    RCC->APB2ENR|=1<<3;    //PB时钟使能      

  RCC->APB2ENR|=1<<0;    //开启辅助时钟

    GPIOB->CRL&=0XFF0FFFFF;//PB5

    GPIOB->CRL|=0X00800000;

    GPIOB->CRH&=0XFFF0FFFF;//PB11-12

    GPIOB->CRH|=0X00030000;//PB11-12

    GPIOB->ODR|=1<<5|1<<12;    //PB11-12 全部上拉    

  SPI2_Init(); 

    SPI2_SetSpeed(SPI_SPEED_16);

    Read_ADS(&Pen_Point.X,&Pen_Point.Y);//第一次读取初始化          

    MY_NVIC_Init(1,0,EXTI9_5_IRQChannel,2); 

  RCC->APB2ENR|=0x01;    //使能io复用时钟     

  AFIO->EXTICR[1]|=1<<4;  //EXTI5映射到PB5

    EXTI->IMR|=1<<5;        //开启line5上的中断

    EXTI->EMR|=1<<5;        //不屏蔽line5上的事件

    EXTI->FTSR|=1<<5;       //line5上事件下降沿触发       

#ifdef ADJ_SAVE_ENABLE   

    AT24CXX_Init();//初始化24CXX

    if(Get_Adjdata())return;//已经校准

    else               //未校准?

    {                                          

        LCD_Clear(WHITE);//清屏

      Touch_Adjust();  //屏幕校准

        Save_Adjdata(); 

    }          

    Get_Adjdata();

#else

    LCD_Clear(WHITE);//清屏

  Touch_Adjust();  //屏幕校准,带自动保存           

#endif                                              

//  printf(\"Pen_Point.xfac:%f\n\",Pen_Point.xfac);

//  printf(\"Pen_Point.yfac:%f\n\",Pen_Point.yfac);

//  printf(\"Pen_Point.xoff:%d\n\",Pen_Point.xoff);

//  printf(\"Pen_Point.yoff:%d\n\",Pen_Point.yoff);

}

 

void touch_chack_init(void)

{

        LCD_ShowString(CUB_X1,CUB_Y1+14,\"   1     2     3     A\");

        LCD_ShowString(CUB_X1,CUB_Y2+14,\"   4     5     6     B\");

        LCD_ShowString(CUB_X1,CUB_Y3+14,\"   7     8     9     C\");

        LCD_ShowString(CUB_X1,CUB_Y4+14,\"   *     0     #     D\");

        LCD_DrawRectangle(CUB_X1,CUB_Y1,CUB_X1+JIANGE,CUB_Y1+JIANGE);

        LCD_DrawRectangle(CUB_X2,CUB_Y1,CUB_X2+JIANGE,CUB_Y1+JIANGE);

        LCD_DrawRectangle(CUB_X3,CUB_Y1,CUB_X3+JIANGE,CUB_Y1+JIANGE);

        LCD_DrawRectangle(CUB_X4,CUB_Y1,CUB_X4+JIANGE,CUB_Y1+JIANGE);

         

        LCD_DrawRectangle(CUB_X1,CUB_Y2,CUB_X1+JIANGE,CUB_Y2+JIANGE);

        LCD_DrawRectangle(CUB_X2,CUB_Y2,CUB_X2+JIANGE,CUB_Y2+JIANGE);

        LCD_DrawRectangle(CUB_X3,CUB_Y2,CUB_X3+JIANGE,CUB_Y2+JIANGE);

        LCD_DrawRectangle(CUB_X4,CUB_Y2,CUB_X4+JIANGE,CUB_Y2+JIANGE);

         

        LCD_DrawRectangle(CUB_X1,CUB_Y3,CUB_X1+JIANGE,CUB_Y3+JIANGE);

        LCD_DrawRectangle(CUB_X2,CUB_Y3,CUB_X2+JIANGE,CUB_Y3+JIANGE);

        LCD_DrawRectangle(CUB_X3,CUB_Y3,CUB_X3+JIANGE,CUB_Y3+JIANGE);

        LCD_DrawRectangle(CUB_X4,CUB_Y3,CUB_X4+JIANGE,CUB_Y3+JIANGE);

         

        LCD_DrawRectangle(CUB_X1,CUB_Y4,CUB_X1+JIANGE,CUB_Y4+JIANGE);

        LCD_DrawRectangle(CUB_X2,CUB_Y4,CUB_X2+JIANGE,CUB_Y4+JIANGE);

        LCD_DrawRectangle(CUB_X3,CUB_Y4,CUB_X3+JIANGE,CUB_Y4+JIANGE);

        LCD_DrawRectangle(CUB_X4,CUB_Y4,CUB_X4+JIANGE,CUB_Y4+JIANGE);      

}

u8 touch_chack(void)

{

      u8 x2=0;

    if(Pen_Point.Key_Sta==Key_Down)//触摸屏被按下

        {

            if(Read_TP_Once())//得到单次按键值

            {  

                if((Pen_Point.X0>CUB_X1&&Pen_Point.X0CUB_Y1&&Pen_Point.Y0

                {

                    x2='1';

                }              

                if((Pen_Point.X0>CUB_X2&&Pen_Point.X0CUB_Y1&&Pen_Point.Y0

                {

                    x2='2';

                }

                if((Pen_Point.X0>CUB_X3&&Pen_Point.X0CUB_Y1&&Pen_Point.Y0

                {

                    x2='3';

                }

                if((Pen_Point.X0>CUB_X4&&Pen_Point.X0CUB_Y1&&Pen_Point.Y0

                {

                    x2='A';

                }

                if((Pen_Point.X0>CUB_X1&&Pen_Point.X0CUB_Y2&&Pen_Point.Y0

                {

                    x2='4';

                }              

                if((Pen_Point.X0>CUB_X2&&Pen_Point.X0CUB_Y2&&Pen_Point.Y0

                {

                    x2='5';

                }

                if((Pen_Point.X0>CUB_X3&&Pen_Point.X0CUB_Y2&&Pen_Point.Y0

                {

                    x2='6';

                }

                if((Pen_Point.X0>CUB_X4&&Pen_Point.X0CUB_Y2&&Pen_Point.Y0

                

                     x2='B';               

                }

                if((Pen_Point.X0>CUB_X1&&Pen_Point.X0CUB_Y3&&Pen_Point.Y0

                {

                    x2='7';

                }              

                if((Pen_Point.X0>CUB_X2&&Pen_Point.X0CUB_Y3&&Pen_Point.Y0

                {

                    x2='8';

                }

                if((Pen_Point.X0>CUB_X3&&Pen_Point.X0CUB_Y3&&Pen_Point.Y0

                {

                    x2='9';

                }

                if((Pen_Point.X0>CUB_X4&&Pen_Point.X0CUB_Y3&&Pen_Point.Y0

                {  

                    x2='C';            

                }

                if((Pen_Point.X0>CUB_X1&&Pen_Point.X0CUB_Y4&&Pen_Point.Y0

                {  

                    x2='*';

                }  

                if((Pen_Point.X0>CUB_X2&&Pen_Point.X0CUB_Y4&&Pen_Point.Y0

                {

                    x2='0';

                }  

                if((Pen_Point.X0>CUB_X3&&Pen_Point.X0CUB_Y4&&Pen_Point.Y0

                {  

                    x2='#';

                }  

                if((Pen_Point.X0>CUB_X4&&Pen_Point.X0CUB_Y4&&Pen_Point.Y0

                {

                    x2='D';

                }              

          }

         }

         return x2;

}


在正点原子代码基础上增加硬件SPI2读取屏幕值,经过测试,速度为4.5MHZ为妙,也就是SPI2的8分频

你可能感兴趣的:(embedded)