ts.c
上传用户:zbk8730
上传日期:2017-08-10
资源大小:12168k
文件大小:2k
- #include "def1.h"
- #include "2440addr.h"
- #include "2440lib.h"
- #include "ts.h"
- #include "config.h"
- #include "app_cfg.h"
- #define REQCNT 30
- #define ADCPRS 9 //YH 0627
- #define LOOP 1
- #define LCD_XSIZE 240
- #define LCD_YSIZE 320
- #define XDATA_MIN 80//120
- #define XDATA_MAX 942//900
- #define YDATA_MIN 85//145
- #define YDATA_MAX 930//915
- #define XLCD_POS(data) ( (int)((LCD_XSIZE*((data)-XDATA_MIN)) /(XDATA_MAX-XDATA_MIN)))
- #define YLCD_POS(data) (LCD_YSIZE-(( (int)(LCD_YSIZE*((data)-YDATA_MIN)/(YDATA_MAX-YDATA_MIN)) )))
- unsigned long g_tsnum=0;
- OS_EVENT* ts_scan_event;
- volatile int xdata, ydata;
- void open_tp(void)
- {
-
- rADCDLY=50000; //Normal conversion mode delay about (1/3.6864M)*50000=13.56ms
- rADCCON=(1<<14)+(ADCPRS<<6); //ADCPRS En, ADCPRS Value
- rADCTSC=0xd3; //Wfait,XP_PU,XP_Dis,XM_Dis,YP_Dis,YM_En
- pISR_ADC = (int)ts_isr;
- rINTMSK&=~BIT_ADC; //ADC Touch Screen Mask bit clear
- rINTSUBMSK&=~(BIT_SUB_TC);
- }
- void close_tp(void)
- {
- rINTSUBMSK|=BIT_SUB_TC;
- rINTMSK|=BIT_ADC;
- }
- int m_num = 0;
- void ts_isr(void)
- {
- rSUBSRCPND|=BIT_SUB_TC;
- ClearPending(BIT_ADC);
- if(!(rADCDAT0&0x8000))
- {
- ts_read();
- OSPrintf("down XP=%04d, YP=%04dn", XLCD_POS(xdata), YLCD_POS(ydata));
- OSTaskResume(Task0Prio);
- }
- else
- {
- rADCTSC=0xd3;
- OSTaskSuspend(Task0Prio);
- OSPrintf("up XP=%04d, YP=%04dn", XLCD_POS(xdata), YLCD_POS(ydata));
- }
- g_tsnum++;
- }
- void ts_read(void)
- {
- int i;
- U32 saveAdcdly;
- if(rADCDAT0&0x8000)
- {
- //Uart_Printf("nStylus Up!!n");
- rADCTSC&=0xff; // Set stylus down interrupt bit
- }
- rADCTSC=(1<<3)|(1<<2); //Pull-up disable, Seq. X,Y postion measure.
- saveAdcdly=rADCDLY;
- rADCDLY=40000; //Normal conversion mode delay about (1/50M)*40000=0.8ms
- rADCCON|=0x1; //start ADC
- while(rADCCON & 0x1); //check if Enable_start is low
- while(!(rADCCON & 0x8000)); //check if EC(End of Conversion) flag is high, This line is necessary~!!
- ydata=(rADCDAT0&0x3ff);
- xdata=(rADCDAT1&0x3ff);
- rADCDLY=40000;
- rADCTSC =0xd3; //Waiting for interrupt
- rADCTSC=rADCTSC|(1<<8); // Detect stylus up interrupt signal.
- }
- void Task0 (void *pdata)
- {
-
- char *s="msg";
- char i;
- INT8U err;
- open_tp();
- OSTaskSuspend(Task0Prio);
- while (1)
- {
- ts_read();
- OSPrintf("move XP=%04d, YP=%04dn", XLCD_POS(xdata), YLCD_POS(ydata));
- OSTimeDly(OS_TICKS_PER_SEC);
- }
- }