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

📄 touch_screen.c

📁 某培训中心的实验代码
💻 C
字号:
/**************************************************************
Touch Screen control
**************************************************************/
#include <string.h>
#include "2410addr.h"
#include "2410lib.h"
#include "Touch_Screen.h"

#define ADCPRS 39
#define ITERATION 5	
unsigned int buf[ITERATION][2];
//*************************************************************

/*************************************************************
          The interrupt function for Touch Screen
**************************************************************/  
void __irq Touch_Screen(void)
{
    int i;
    
    DisableIrq(BIT_ADC);
	DisableSubIrq(BIT_SUB_TC);    //Mask sub interrupt (ADC and TC) 

    Uart_Printf("\n Touch_Screen Down!\n");
       
    //Auto X-Position and Y-Position Read
    //[7] YM=GND, [6] YP is connected with AIN[5], [5] XM=Hi-Z, 
    //[4] XP is connected with AIN[7], [3] XP pull-up disable, 
    //[2] Auto(sequential) X/Y position conversion mode, 
    //[1:0] No operation mode   
    rADCTSC=(1<<7)|(1<<6)|(0<<5)|(1<<4)|(1<<3)|(1<<2)|(0);
 
    for(i=0;i<ITERATION;i++)
    {
        rADCTSC  = (1<<7)|(1<<6)|(0<<5)|(1<<4)|(1<<3)|(1<<2)|(0);            
        rADCCON |= 0x01;             //A/D conversion starts and this bit is cleared after the start-up.
        while(rADCCON & 0x01);       //Check if Enable_start is low
        while(!(0x8000&rADCCON));    //Check End of conversion flag ?
       
        buf[i][0] = (0x3ff&rADCDAT0);//X-position conversion data value.
        buf[i][1] = (0x3ff&rADCDAT1);//Y-position conversion data value.
    }

    for(i=0;i<ITERATION;i++)    
        Uart_Printf("X %4d, Y %4d\n", buf[i][0], buf[i][1]);
         
    rADCTSC = (1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3);  
      //[7] YM=GND, [6] YP is connected with AIN[5], [5] XM=Hi-Z, [4] XP is connected with AIN[7]
      //[3] XP pull-up enable, [2] Normal ADC conversion, [1:0] Waiting for interrupt mode                
    
    ClearSubPending(BIT_SUB_TC);
    ClearPending(BIT_ADC);   
    EnableSubIrq(BIT_SUB_TC);
    EnableIrq(BIT_ADC);
}
            
/**************************************************************
The Initial of Touch Screen
**************************************************************/
void Touch_Screen_Init(void)
{
    rADCDLY = (30000);    // ADC Start or Interval Delay
    
    // Enable Prescaler,Prescaler,AIN5/7 fix,Normal,Disable read start,No operation
    rADCCON = (1<<14)|(ADCPRS<<6)|(0<<3)|(0<<2)|(0<<1)|(0); 
    // Down,YM:GND,YP:AIN5,XM:Hi-z,XP:AIN7,XP pullup En,Normal,Waiting for interrupt mode  
    rADCTSC = (0<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3);//tark
    	
    pISR_ADC    = (unsigned)Touch_Screen;
    ClearSubPending(BIT_SUB_TC);
    EnableIrq(BIT_ADC);
    EnableSubIrq(BIT_SUB_TC);
    
    Uart_Printf( "\nNow touchpanel controler is initial!\n" ) ;
    Uart_Printf( "Please Press it with touch pen and see what happend\n" ) ;
    Uart_Printf( "\nAny key to exit the touchpanel test\n" ) ;
    Uart_Getch() ;
    
    Touch_Screen_Off() ;
}
//*************************************************************
void Touch_Screen_Off(void)
{
	DisableIrq(BIT_ADC);
	DisableSubIrq(BIT_SUB_TC);
}

⌨️ 快捷键说明

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