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

📄 touch_screen.c

📁 UCOS S3C2440 移植源代码 ADS1.2 可以直接跑在开发板上
💻 C
字号:
/**************************************************************
Touch Screen control
**************************************************************/
#include <string.h>
#include "2440addr.h"
#include "2440lib.h"
#include "Touch_Screen.h"
#include "320240_lcd.h"

#define ADCPRS 39

extern U32 touch_screen_x=0;
extern U32 touch_screen_y=0;
extern U32 touch_occur=0;

/**************************************************************
The interrupt function for Touch Screen
**************************************************************/
void __irq Touch_Screen(void)
{
    rINTSUBMSK |= (BIT_SUB_ADC | BIT_SUB_TC);//Mask sub interrupt (ADC and TC) 
        
      //Auto X-Position and Y-Position Read
    rADCTSC=(1<<7)|(1<<6)|(0<<5)|(1<<4)|(1<<3)|(1<<2)|(0);//读数据前,要先重配rADCTSC
          //[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                
     
    rADCCON |= 0x1;             //Start Auto conversion
    while(!(0x8000&rADCCON));   //Check ECFLG
    
    touch_screen_x = (0x3ff&rADCDAT0);
    touch_screen_y = (0x3ff&rADCDAT1);
    touch_screen_x =touch_screen_x/4;
    touch_screen_y =touch_screen_y/3;
    //Lcd_ClearScr(0xffff);//clear Lcd with some color
  //  Lcd_printf(LCD_BUFER,0,0,0x3f,0xffff,"%d,%d",touch_screen_x,touch_screen_y);//输出坐标数据
    
    touch_occur=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                
    rSUBSRCPND |= BIT_SUB_TC;
    rINTSUBMSK  =~(BIT_SUB_TC);   //Unmask sub interrupt (TC)     
    ClearPending(BIT_ADC);
}
            
/**************************************************************
The Initial of Touch Screen
**************************************************************/
extern void Touch_Screen_Init(void)
{
    rADCDLY = (30000);    // ADC Start or Interval Delay

    rADCCON = (1<<14)|(ADCPRS<<6)|(0<<3)|(0<<2)|(0<<1)|(0); 
      // Enable Prescaler,Prescaler,AIN5/7 fix,Normal,Disable read start,No operation
    rADCTSC = (0<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3);//tark
      // Down,YM:GND,YP:AIN5,XM:Hi-z,XP:AIN7,XP pullup En,Normal,Waiting for interrupt mode

	rSUBSRCPND |= BIT_SUB_TC;
    rINTSUBMSK  =~(BIT_SUB_TC);
    
    pISR_ADC    = (unsigned)Touch_Screen;
    rINTMSK    &= ~(BIT_ADC);
    rINTSUBMSK &= ~(BIT_SUB_TC);
    
   // Touch_Screen_Off() ;
}
//*************************************************************
void Touch_Screen_Off(void)
{
	rINTMSK    |= (BIT_ADC);
    rINTSUBMSK |= (BIT_SUB_TC);
}

⌨️ 快捷键说明

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