?? tsp_test.c
字號:
/*********************************************************************************************
* File: tsp_test.c
* Author: embest
* Desc: Touch Screen Test
* History:
* H.T.Zhang, Programming modify, September 14, 2005
*********************************************************************************************/
/*------------------------------------------------------------------------------------------*/
/* include files */
/*------------------------------------------------------------------------------------------*/
#include <string.h>
#include "2410lib.h"
#include "tsp_test.h"
#include "demo.h"
/*------------------------------------------------------------------------------------------*/
/* constants define */
/*------------------------------------------------------------------------------------------*/
#define ADCPRS 39
int nSampleNo=5;
int j=0;
unsigned int f_unPosX, f_unPosY;
extern void isrADC(void); // touch screen interrupt entry point, call_int.s
/*********************************************************************************************
* name: tsp_int
* func: Touch screen interrupt handler (ADC)
* para: none
* ret: none
* modify: R.X.Huang, March 12, 2005
* comment:
*********************************************************************************************/
void tsp_int(void)
{
int i;
char buf[50];
UINT32T szPos[40];
rINTSUBMSK |= (BIT_SUB_ADC | BIT_SUB_TC);// Mask sub interrupt (ADC and TC)
// TC(Touch screen Control) Interrupt
if( rADCTSC & 0x100)
{
uart_printf(" Stylus Up!!\n");
rADCTSC&=0xff; // Set stylus down interrupt
}
else
{
uart_printf(" Stylus Down!!\n");
szPos[30] = g_nPosX;
szPos[34] = g_nPosY;
// <X-Position Read>
//Hi-Z,AIN5,GND,Ext vlt,Pullup Dis,Normal,X-position
rADCTSC = (0<<8)|(0<<7)|(1<<6)|(1<<5)|(0<<4)|(0<<3)|(0<<2)|(1);
//adc input ain5
rADCCON = (1<<14)|(39<<6)|(5<<3)|(0<<2)|(1<<1)|(0);
rADCDAT0;
delay(10);
for(i = 0; i<nSampleNo; i++)
{
while(!(0x8000 & rADCCON)); // Check ECFLG
szPos[i] = (0x3ff & rADCDAT0);
g_nPosX += szPos[i];
}
g_nPosX = g_nPosX/nSampleNo;
f_unPosX = g_nPosX;
uart_printf(" X-Posion[AIN5] is %04d\n", g_nPosX);
// <Y-Position Read>
//GND,Ext vlt,Hi-Z,AIN7,Pullup Dis,Normal,Y-position
rADCTSC = (0<<8)|(1<<7)|(0<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(2);
//adc input ain7
rADCCON = (1<<14)|(39<<6)|(7<<3)|(0<<2)|(1<<1)|(0);
rADCDAT1;
delay(10);
for(i = 0; i<nSampleNo; i++)
{
while(!(0x8000 & rADCCON)); // Check ECFLG
szPos[i] = (0x3ff & rADCDAT1);
g_nPosY += szPos[i];
}
g_nPosY = g_nPosY/nSampleNo;
f_unPosY = g_nPosY;
uart_printf(" Y-Posion[AIN7] is %04d\n", g_nPosY);
//GND,AIN,Hi-z,AIN,Pullup En,Normal,Waiting mode
rADCTSC=(1<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3);
sprintf(buf, "(X%d,Y%d):(%04d,%04d)",j,j,f_unPosX,f_unPosY);
/*
lcd_clr_rect(85,90+16*j,237,90+16*(j+1),BLUE);
lcd_disp_ascii8x16(85,90+16*j,WHITE,(UINT8T *)buf);
if (++j > 6) j = 0;
*/ }
rSUBSRCPND |= BIT_SUB_TC;
rINTSUBMSK = ~(BIT_SUB_TC); // Unmask sub interrupt (TC)
ClearPending(BIT_ADC);
}
/*********************************************************************************************
* name: tsp_test
* func:
* para: none
* ret: none
* modify: R.X.Huang, March 12, 2005
* comment:
*********************************************************************************************/
void tsp_test(void)
{
uart_printf(" Touch Screen Test Example.\n");
// lcd_disp_ascii8x16(f_nDescCol,f_nDescRow,BLUE,"Touch Screen Test Example.");
lcd_disp_ascii8x16(f_nDescCol,f_nDescRow,BLUE,"Please touch the four rectangle:");
g_nPosX = 0;
g_nPosY = 0;
// lcd_disp_ascii8x16(f_nDescCol,f_nDescRow+f_nPadRow,BLUE,"Please touch the screen:");
rADCDLY = 50000; // ADC Start or Interval Delay
rGPGCON |= 0xFF000000;
rGPGUP = 0xFFFF;
rADCTSC = (0<<8) | (1<<7) | (1<<6) | (0<<5) | (1<<4) | (0<<3) | (1<<2) | (0);
//auto sequential x/y position conversion,no operation, XP pull-up
rADCCON = (1<<14) | (ADCPRS<<6) | (5<<3) | (0<<2) | (0<<1) | (0);
// Enable Prescaler,Prescaler,AIN7/5 fix,Normal,Disable read start,No operation
rADCTSC = (0<<8) | (1<<7) | (1<<6) | (0<<5) | (1<<4) | (0<<3) | (0<<2) | (3);
//YM:GND,YP:AIN5,XM:Hi-z,XP:external voltage,XP pullup En,AUTO sequential,Waiting for interrupt mode
delay(100);
pISR_ADC = (unsigned)isrADC; // pISR_ADC
rINTMSK &= ~(BIT_ADC);
rINTSUBMSK = ~(BIT_SUB_TC);
uart_printf(" Press any key to exit...\n");
Glib_Rectangle(60,100,260,200,RED);
Glib_Line(60,150,260,150,RED);
Glib_Line(160,100,160,200,RED);
f_nKeyPress = 0;
while(1)
{
if((g_nPosX>200)&&(g_nPosX<450))
{
if((g_nPosY>430)&&(g_nPosY<600)) //1
lcd_clr_rect(60,100,160,150,GREEN);
else if((g_nPosY>250)&&(g_nPosY<420)) //3
lcd_clr_rect(60,150,160,200,WHITE);
}
if((g_nPosX>460)&&(g_nPosX<700))
{
if((g_nPosY>430)&&(g_nPosY<600)) //2
lcd_clr_rect(160,100,260,150,RED);
else if((g_nPosY>250)&&(g_nPosY<420)) //4
lcd_clr_rect(160,150,260,200,BLUE);
}
if(f_nKeyPress)
{
f_nKeyPress = 0;
j = 0;
break;// any key to exit.
}
}
rINTSUBMSK |= BIT_SUB_TC;
rINTMSK |= BIT_ADC;
uart_printf(" end.\n");
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -