📄 touch.c
字号:
#include "Touch.h"
#include "../../target/2410addr.h"
#include "../../ucos-ii/includes.h"
#include "../../target/2410lib.h"
#include <string.h>
#include "def.h"
#define ADCPRS 39
#define chi 1
#define TOUCH_XSIZE (640)
#define TOUCH_YSIZE (480)
#define TOUCH_AD_LEFT 960//0x16//0x15b//0x120
#define TOUCH_AD_RIGHT 60//0x1fe//0xec8//0xe70
#define TOUCH_AD_TOP 50//0x200//0x1d6//0x230
#define TOUCH_AD_BOTTOM 960//0x3d8//0xdee//0xdf0
int xPhys, yPhys;
void __irq Touch_Isr(void)
{
int i;
U32 Pt[6];
/* calculate Min / Max values */
rINTSUBMSK|=(BIT_SUB_ADC|BIT_SUB_TC); // Mask sub interrupt (ADC and TC)
if(rADCTSC & 0x100)
{
Uart_Printf("\nStylus Up!!\n");
rADCTSC &= 0xff; // Set stylus down interrupt
}
else
{
// Uart_Printf("\nStylus Up!!\n");
rADCTSC=(0<<8)|(0<<7)|(1<<6)|(1<<5)|(0<<4)|(1<<3)|(0<<2)|(1);
//Uart_Printf("\nStylus Down!!\n");
for(i=0;i<chi;i++);
for(i=0;i<5;i++)
{
rADCCON|=0x1; // Start Auto conversion
while(rADCCON & 0x1); //check if Enable_start is low
while(!(0x8000&rADCCON)); // Check ECFLG
Pt[i] = (0x3ff&rADCDAT0);
}
Pt[5]=(Pt[0]+Pt[1]+Pt[2]+Pt[3]+Pt[4])/5;
Uart_Printf("X-Posion[AIN5] is %04d\n", Pt[5]);
xPhys=Pt[5];
rADCTSC=(0<<8)|(0<<7)|(1<<6)|(1<<5)|(0<<4)|(1<<3)|(0<<2)|(2);
for(i=0;i<chi;i++);
for(i=0;i<5;i++)
{
rADCCON|=0x1; // Start Auto conversion
while(rADCCON & 0x1); //check if Enable_start is low
while(!(0x8000&rADCCON)); // Check ECFLG
Pt[i] = (0x3ff&rADCDAT1);
}
Pt[5]=(Pt[0]+Pt[1]+Pt[2]+Pt[3]+Pt[4])/5;
Uart_Printf("Y-Posion[AIN7] is %04d\n", Pt[5]);
yPhys=Pt[5];
rADCTSC=(1<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3);
// Stylus Up,Don't care,Don't care,Don't care,Don't care,XP pullup En,Normal,Waiting mode
}
rSUBSRCPND|=BIT_SUB_TC;
rINTSUBMSK&=~(BIT_SUB_TC); // Unmask sub interrupt (TC)
ClearPending(BIT_ADC);
}
extern void Touch_IsrHandle(void);
void TOUCH_Init(void)
{
rADCDLY=(50000); // 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
pISR_ADC=(unsigned)Touch_Isr;
rINTMSK &= ~(BIT_ADC);
rINTSUBMSK &= ~(BIT_SUB_TC);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -