📄 ts_sep.c
字号:
#include <string.h>
#include "2410addr.h"
#include "2410lib.h"
#include "Ts_sep.h"
#include "def.h"
#define LOOP 1
#define ADCPRS 39
/*****************************************
触摸屏SEP方式中断请求函数
函数名: Adc_or_TsSep
描述: 触摸屏SEP方式中断请求函数
返回值:void
*****************************************/
void __irq Adc_or_TsSep(void)
{
int i;
U32 Pt[6];
//INTSUBMSK INT_TC [ 9] = 1 Mask sub interrupt
//INTSUBMSK INT_ADC [10] = 1 Mask sub interrupt
rINTSUBMSK |= (BIT_SUB_ADC|BIT_SUB_TC);
// TC(Touch screen Control) Interrupt
if(rADCTSC & 0x100)
{
Uart_Printf("\nStylus Up!!\n");
//ADCTSC XY_PST [1:0] = 11 : Waiting for Interrupt Mode
//ADCTSC AUTO_PST [2 ] = 1 : Auto (Sequential) X/Y Position Conversion Mode
//ADCTSC PULL_UP [3 ] = 1 : XP pull-up disable
//ADCTSC XP_SEN [4 ] = 1 : nXPON output is 1 (XP is connected with AIN[7]).
//ADCTSC XM_SEN [5 ] = 1 : XMON output is 1 (XM = GND).
//ADCTSC YP_SEN [6 ] = 1 : nYPON output is 1 (YP is connected with AIN[5]).
//ADCTSC YM_SEN [7 ] = 1 : YMON output is 1 (YM = GND).
rADCTSC &= 0xff; // Set stylus down interrupt
}
else
{
Uart_Printf("\nStylus Down!!\n");
// <X-Position Read>
//ADCTSC XY_PST [1:0] = 11 : Waiting for Interrupt Mode
//ADCTSC AUTO_PST [2 ] = 0 : Normal ADC conversion
//ADCTSC PULL_UP [3 ] = 1 : XP pull-up disable
//ADCTSC XP_SEN [4 ] = 0 : nXPON output is 0 (XP = External voltage).
//ADCTSC XM_SEN [5 ] = 1 : XMON output is 1 (XM = GND).
//ADCTSC YP_SEN [6 ] = 1 : nYPON output is 1 (YP is connected with AIN[5]).
//ADCTSC YM_SEN [7 ] = 0 : YMON output is 0 (YM = Hi-Z).
rADCTSC=(0<<8)|(0<<7)|(1<<6)|(1<<5)|(0<<4)|(1<<3)|(0<<2)|(1);
for(i=0;i<LOOP;i++); //delay to set up the next channel
for(i=0;i<5;i++) //5 times
{
rADCCON|=0x1; // Start X-position 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]);
// <Y-Position Read>
//ADCTSC XY_PST [1:0] = 10 : Y-position measurement
//ADCTSC AUTO_PST [2 ] = 0 : Normal ADC conversion
//ADCTSC PULL_UP [3 ] = 1 : XP pull-up disable
//ADCTSC XP_SEN [4 ] = 0 : nXPON output is 0 (XP = External voltage).
//ADCTSC XM_SEN [5 ] = 1 : XMON output is 1 (XM = GND).
//ADCTSC YP_SEN [6 ] = 1 : nYPON output is 1 (YP is connected with AIN[5]).
//ADCTSC YM_SEN [7 ] = 0 : YMON output is 0 (YM = Hi-Z).
rADCTSC=(0<<8)|(0<<7)|(1<<6)|(1<<5)|(0<<4)|(1<<3)|(0<<2)|(2);
// Down,GND,Ext vlt,Hi-Z,AIN7,Pullup Dis,Normal,Y-position
for(i=0;i<LOOP;i++); //delay to set up the next channel
for(i=0;i<5;i++) //5 times
{
rADCCON|=0x1; // Start Y-position 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]);
//ADCTSC XY_PST [1:0] = 11 : Waiting for Interrupt Mode
//ADCTSC AUTO_PST [2 ] = 0 : Normal ADC conversion
//ADCTSC PULL_UP [3 ] = 0 : XP pull-up enable
//ADCTSC XP_SEN [4 ] = 1 : nXPON output is 1 (XP is connected with AIN[7]).
//ADCTSC XM_SEN [5 ] = 0 : XMON output is 0 (XM = Hi-Z).
//ADCTSC YP_SEN [6 ] = 1 : nYPON output is 1 (YP is connected with AIN[5]).
//ADCTSC YM_SEN [7 ] = 1 : YMON output is 1 (YM = GND).
rADCTSC=(1<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3);
// Up,GND,AIN,Hi-z,AIN,Pullup En,Normal,Waiting mode
}
//SUBSRCPND INT_TC [9] = 1 : Requested
rSUBSRCPND |= BIT_SUB_TC;
//INTSUBMSK INT_TC [9] = 0 : Service available,
rINTSUBMSK =~ (BIT_SUB_TC); // Unmask sub interrupt (TC)
ClearPending(BIT_ADC);
}
//============================================================
/*****************************************
触摸屏SEP方式测试函数
函数名: Adc_or_TsSep
描述: 触摸屏SEP方式测试函数
返回值:void
*****************************************/
void Ts_Sep(void)
{
Uart_Printf("[Touch Screen Test.]\n");
Uart_Printf("Separate X/Y position conversion mode test\n");
//ADCDLY DELAY [15:0] : DC Start or Interval Delay
rADCDLY = (50000);
//ADCCON ENABLE_START [0 ] = 0 : No operation
//ADCCON READ_START [1 ] = 0 : Disable start by read operation
//ADCCON STDBM [2 ] = 0 : Normal operation mode
//ADCCON SEL_MUX [5 : 3] = 111 : AIN7/5 fix
//ADCCON PRSCVL [13: 6] = 0x27 : A/D converter prescaler value.
//ADCCON PRSCEN [14 ] = 1 : A/D converter prescaler Enable
rADCCON = (1<<14)|(ADCPRS<<6)|(0<<3)|(0<<2)|(0<<1)|(0);
//ADCTSC XY_PST [1:0] = 11 : Waiting for Interrupt Mode
//ADCTSC AUTO_PST [2 ] = 0 : Normal ADC conversion
//ADCTSC PULL_UP [3 ] = 0 : XP pull-up enable
//ADCTSC XP_SEN [4 ] = 1 : nXPON output is 1 (XP is connected with AIN[7]).
//ADCTSC XM_SEN [5 ] = 0 : XMON output is 0 (XM = Hi-Z).
//ADCTSC YP_SEN [6 ] = 1 : nYPON output is 1 (YP is connected with AIN[5]).
//ADCTSC YM_SEN [7 ] = 1 : YMON output is 1 (YM = GND).
rADCTSC = (0<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3);
pISR_ADC = (unsigned)Adc_or_TsSep; //定义中断响应函数
//INTMSK INT_ADC [31] = 0 : Service available,
rINTMSK =~(BIT_ADC);
//INTSUBMSK INT_TC [9] = 0 : Service available,
rINTSUBMSK =~(BIT_SUB_TC);
Uart_Printf("\nType any key to exit!!!\n");
Uart_Printf("\nStylus Down, please...... \n");
Uart_Getch();
//INTSUBMSK INT_TC [9] = 0 : Masked
rINTSUBMSK |= BIT_SUB_TC;
//INTMSK INT_ADC [31] = 0 : Masked
rINTMSK |= BIT_ADC;
Uart_Printf("[Touch Screen Test.]\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -