• TSC触摸屏



    默认情况下,输入通道已被接到触摸屏上 

     

     

    nXPON  

    Plus X-axis on-off control signal     

    x轴正极开关控制信号

    XMON

    Minus X-axis on-off control signal

    x轴负极开关控制信号

    nYPON

    Plus Y-axis on-off control signal

    y轴正极开关控制信号

    YMON

    Minus Y-axis on-off control signal

    y轴负极开关控制信号

     

     /*触摸屏初始化*/

    void Test_Touchpanel(void)
    {
       
        rADCDLY=50000;  //ADC启动延时 (1/3.6864M)*50000=13.56ms
        
        /*设置AD转频率*/
        preScaler = ADC_FREQ;
        preScaler = 50000000/ADC_FREQ - 1//PCLK=50M
        rADCCON = (1<<14)|(preScaler<<6); //使能分频,  分频值PRSCVL=19
                                                              
    //转换频率=50MHz/(19+1)=2.5HMz
                                                              
    //转换时间=1/(2.5MHz/5)=2×10^(-6)秒 
                                                              
    //一秒钟转换5×10^5次
        /*设置触摸屏为等待中断模式,等待触摸笔被按下*/
        rADCTSC=0xd3;  //Wfait,XP_PU,XP_Dis,XM_Dis,YP_Dis,YM_En                          第一次设置中断
                                  
    //11010011  来自2440手册
        
        /*clear irq*/
        rSRCPND = 0x80000000;     //清除挂起状态
        rINTPND = 0x80000000;
        ClearSubPending(BIT_SUB_TC);  

        pISR_ADC = (U32)AdcTsAuto;   //中断服务函数

        /*enable INT_TC irq*/ 
        rINTMSK = 0x7fffffff;            //打开屏蔽
        EnableSubIrq(BIT_SUB_TC);
    }

    static void __irq AdcTsAuto(void)  //中断服务函数
    {
        U32 saveAdcdly;
        /****************stylus down************************/
        /*检测子中断源,判断是否是INT_TC中断,且触摸笔按下*/
        if(rSUBSRCPND & (BIT_SUB_TC))
        {
    if( !(rADCDAT0&0x8000))  //是否落下状态
       Uart_Printf(" Stylus down ");
    else 
                Uart_Printf(" Stylus up "); 
        }
        rADCTSC = (1<<3)|(1<<2);      关闭上拉电阻, X,Y方向自动转换
        saveAdcdly=rADCDLY;
        rADCDLY=40000;    //ADC启动延迟    (1/50M)*40000=0.8ms

          rADCCON|=0x1;                   //开始ADC
        while(rADCCON & 0x1);      //转换是否开始  
      while(!(rADCCON & 0x8000));  //转换是否结束
    while(!(rSRCPND & 0x80000000));  //检测是否产生INT_ADC中断

        /*获取X,Y坐标*/
        xdata=(rADCDAT0&0x3ff);   //[9:0]存储X值
        ydata=(rADCDAT1&0x3ff);   //[9:0]存储Y值
     Uart_Printf("count=%03d  XP=%04d, YP=%04d ", count++, xdata, ydata);    
         
         /*3个PND         2个MSK*/ 
        ClearSubPending(BIT_SUB_TC);
        rSRCPND = 0x80000000;
        rINTPND = 0x80000000;  
        EnableSubIrq(BIT_SUB_TC);
        rINTMSK = 0x7fffffff;
        /****************stylus down************************/

    /*????????????,???????*/
        rADCTSC =0xd3;    //Waiting for interrupt                                    第二次设置中断
    rADCTSC=rADCTSC|(1<<8); // 设置成检测抬起信号

    while(1)  //to check Pen-up state
    {
    if(rSUBSRCPND & (BIT_SUB_TC))//check if ADC is finished with interrupt bit
    {
    Uart_Printf("Stylus Up Interrupt~! ");
    break;  //if Stylus is up(1) state
    }

    /****************stylus up**************************/

    Uart_Printf("count=%03d  XP=%04d, YP=%04d ", count++, xdata, ydata);  

    rADCDLY=saveAdcdly; 
    /*????????????,?????????*/
        rADCTSC =0xd3;    //Waiting for interrupt                                    第三次设置中断
        
    ClearSubPending(BIT_SUB_TC);  
        //ClearPending(BIT_ADC);
        rSRCPND = 0x80000000;
    rINTPND = 0x80000000;


        EnableSubIrq(BIT_SUB_TC);
        //EnableIrq(BIT_ADC);
        rINTMSK = 0x7fffffff;
    }
       
  • 相关阅读:
    机器学习笔记之K近邻算法
    [C++基础]在子类中向父类的构造函数传递参数的小例子,包括类中常量的初始化
    POJ2709 染料贪心
    POJ2337 欧拉路径字典序输出
    POJ2337 欧拉路径字典序输出
    POJ1042 贪心钓鱼
    POJ3228二分最大流
    POJ3228二分最大流
    POJ3498最大流,枚举终点,企鹅,基础最大流
    POJ3498最大流,枚举终点,企鹅,基础最大流
  • 原文地址:https://www.cnblogs.com/liuchengchuxiao/p/4197389.html
Copyright © 2020-2023  润新知