/********************************************************************* Name: touchscreen.c* Author: d* Time: 2015.11.23* function: * Touch screen driver, because the MINI2440 uses a first-line touch, and not four-wire resistive touch, touch screen * drive is not available. ********************************************************************//***************************************** Macro Definition ********************************************************************/#define Intmsk ((* (volatile unsigned long *) 0x4a000008)//Interrupt Mask Register # define INTSUBMSK ((* (volatile unsigned long *) 0x4a00001 C)//Sub-interrupt Mask Register # define ADCCON ((* (volatile unsigned long *) 0x58000000))//ADC Control Register # define ADCTSC ((* (Volatile Unsig Ned long *) 0x58000004))//ADC Touch screen Control Register # define ADCDAT0 ((* (volatile unsigned long *) 0x5800000c)//adc0 convert data Register # define ADCDAT1 ((* (volatile unsigned long *) 0x58000010)//ADC1 convert Data Register # define SUBSRCPND ((* (volatile unsigned long *) 0x4a00 0018)//Sub-interrupt Mask Register # define SRCPND ((* (volatile unsigned long *) 0x4a000000)//Interrupt Source Request Register # define INTPND ((* (volatile unsigned long *)0X4A000010)//Interrupt Request Register/********************************************************************* name: Init_touchscreen * Parameter: *none* return: *none* function: Initialize touch screen *********************************************************************/void init_ Touchscreen () {//Set ADC conversion frequency Adccon = (1<<14) | ( 49<<6); Prscen[14]:1, prscvl[13:6]:49 adc_freqeuncy=pclk/(prscvl+1) Pclk=50mhz adc_freqeuncy=1mhz//wait to press interrupt ADCTSC = (0< <8) | (1<<7) | (1<<6) | (1<<4) | (0x3<<0); ud_sen[8]:0, Ym_sen[7]:1, Yp_sen[6]:1, xm_sen[5]:0, Xp_sen[4]:1, pull_up[3]:0, auto_pst[2]:0, XY_PST[1:0]:0b11// Set sub-interrupt mask Intsubmsk &= ~ (1<<9); int_tc[9]:0//Set Interrupt Mask Intmsk &= ~ (1<<31); int_adc[31]:0}/********************************************************************* Name: touchscreen_irq* parameter: * none* return: *none* function: Touch screen interrupt Service *********************************************************************/void Touchscreen_ IRQ () {int x, y;if (!) ( adctsc& (1<<8)) {//If the touch screen is pressed, ud_sen[8]:0//set the touch screen to auto-convert ADCTSC = (1<<2); auto_pst[2]:1//start ADC conversion Adccon |= (1<<0); enable_start[0]:1//wait for ADC conversion to end while (!) ( adccon& (1<<15)); ecflg[15]//get coordinates x = adcdat0& (0x3ff<<0); Xpdata[9:0]y = adcdat1& (0x3ff<<0); ypdata[9:0]//Cleanup Interrupt Request SUBSRCPND |= (1<<9); int_tc[9]:0//clears the interrupt source request SRCPND |= (1<<31); int_adc[31]:0//Clear Interrupt Request INTPND |= (1<<31); int_adc[31]:0//waiting for bounce interrupt adctsc = (1<<8) | (1<<7) | (1<<6) | (1<<4) | (0x3<<0); Ud_sen[8]:1, xy_pst[1:0]:0b11}else{//If the touch screen bounces up, ud_sen[8]:1//clears the sub-interrupt request SUBSRCPND |= (1<<9); int_tc[9]:0//clears the interrupt source request SRCPND |= (1<<31); int_adc[31]:0//Clear Interrupt Request INTPND |= (1<<31); int_adc[31]:0//waiting to press interrupt ADCTSC = (0<<8) | (1<<7) | (1<<6) | (1<<4) | (0x3<<0); ud_sen[8]:0, XY_PST[1:0]:0B11}}
[Country EMBED strategy] [063] [Resistance screen driver design]