📄 tp.c
字号:
#include <string.h>
#include "..\inc\def.h"
#include "..\inc\44b.h"
#include "..\inc\44blib.h"
#include "..\inc\tp.h"
volatile unsigned char adcend=0;
//unsigned int LOOP = 1000;
void __irq Adc_or_TsSep(void);
//writed by liangweidong 2005-9-7
//initinlization the ADC channels and the ADC interrupte
void adc_init(void)
{
//TSPX(GPE4) TSPY(GPE5) TSMY(GPE6) TSMX(GPE7)
// 0 1 1 0
rPUPE=0x0;
rPDATE=0X68; //should be enabled
Delay(100); //delay to set up the next channel
// Uart_Printf("[Touch Screen Test.]\n");
rEXTINT=0x22222222;
rINTCON=0x5;
pISR_EINT3=(int)Adc_or_TsSep;
rCLKCON=0x7ff8;
rADCPSR=0x4;
rINTMSK=~(BIT_GLOBAL|BIT_EINT3);
}
//writed by liangweidong 2005-9-7
//start converat the current ADC chennal
void adc_start(void)
{
rADCCON = 0x1 | (0x0<<2);
}
//writed by liangweidong 2005-9-7
//close the ADC interrupte
void adc_close(void)
{
rINTMSK |=BIT_GLOBAL|BIT_EINT3;
}
//writed by liangweidong 2005-9-7
//get voltage in the current channel
void __irq get_voltage(void)
{
int i;
U32 Pt[6];
rI_ISPC=BIT_EINT3; //clear pending_bit
//TSPX(GPE4) TSPY(GPE5) TSMY(GPE6) TSMX(GPE7)
// 0 1 0 1
rPDATE=0XA8;
// <X-Position Read>
rADCCON=0x1<<2; // AIN1
Delay(100); //delay to set up the next channel
for(i=0;i<5;i++)
{
rADCCON|=0x1; // Start X-position conversion
while(rADCCON & 0x1); // Check if Enable_start is low
while(!(rADCCON & 0x40)); // Check ECFLG
Pt[i]=(0x3ff&rADCDAT);
}
Pt[5]=(Pt[0]+Pt[1]+Pt[2]+Pt[3]+Pt[4])/5;
// Uart_Printf("X-Posion[AIN1] is %04d\n", Pt[5]);
// <Y-Position Read>
//TSPX(GPE4) TSPY(GPE5) TSMY(GPE6) TSMX(GPE7)
// 1 0 1 0
rPDATE=0X58;
rADCCON=0x0<<2; // AIN0
Delay(100); //delay to set up the next channel
for(i=0;i<5;i++)
{
rADCCON|=0x1; // Start X-position conversion
while(rADCCON & 0x1); // Check if Enable_start is low
while(!(rADCCON & 0x40)); // Check ECFLG
Pt[i]=(0x3ff&rADCDAT);
}
Pt[5]=(Pt[0]+Pt[1]+Pt[2]+Pt[3]+Pt[4])/5;
// Uart_Printf("Y-Posion[AIN0] is %04d\n", Pt[5]);
adcend=1;
Delay(100); //delay to set up the next channel
rPDATE=0X68; //should be enabled
Delay(100); //delay to set up the next channel
}
void __irq Adc_or_TsSep(void)
{
int i;
U32 Pt[6];
rI_ISPC=BIT_EINT3; //clear pending_bit
//TSPX(GPE4) TSPY(GPE5) TSMY(GPE6) TSMX(GPE7)
// 0 1 0 1
rPDATE=0XA8;
// <X-Position Read>
rADCCON=0x1<<2; // AIN1
// for(i=0;i<LOOP;i++); //delay to set up the next channel
for(i=0;i<5;i++)
{
rADCCON|=0x1; // Start X-position conversion
while(rADCCON & 0x1); // Check if Enable_start is low
while(!(rADCCON & 0x40)); // Check ECFLG
Pt[i]=(0x3ff&rADCDAT);
}
Pt[5]=(Pt[0]+Pt[1]+Pt[2]+Pt[3]+Pt[4])/5;
Uart_Printf("X-Posion[AIN1] is %04d\n", Pt[5]);
// <Y-Position Read>
//TSPX(GPE4) TSPY(GPE5) TSMY(GPE6) TSMX(GPE7)
// 1 0 1 0
rPDATE=0X58;
rADCCON=0x0<<2; // AIN0
// for(i=0;i<LOOP;i++); //delay to set up the next channel
for(i=0;i<5;i++)
{
rADCCON|=0x1; // Start X-position conversion
while(rADCCON & 0x1); // Check if Enable_start is low
while(!(rADCCON & 0x40)); // Check ECFLG
Pt[i]=(0x3ff&rADCDAT);
}
Pt[5]=(Pt[0]+Pt[1]+Pt[2]+Pt[3]+Pt[4])/5;
Uart_Printf("Y-Posion[AIN0] is %04d\n", Pt[5]);
adcend=1;
// for(i=0;i<LOOP;i++); //delay to set up the next channel
rPDATE=0X68; //should be enabled
// for(i=0;i<LOOP;i++); //delay to set up the next channel
}
void Ts_Sep(void)
{
// int i;
//TSPX(GPE4) TSPY(GPE5) TSMY(GPE6) TSMX(GPE7)
// 0 1 1 0
rPUPE=0x0;
rPDATE=0X68; //should be enabled
// for(i=0;i<LOOP;i++); //delay to set up the next channel
Uart_Printf("[Touch Screen Test.]\n");
Uart_Printf("Separate X/Y position conversion mode test\n");
Uart_Printf("\nType any key to exit!!!\n");
Uart_Printf("\nStylus Down, please...... \n");
rEXTINT=0x22222222;
rINTCON=0x5;
pISR_EINT3=(int)Adc_or_TsSep;
rCLKCON=0x7ff8;
rADCPSR=0x4;
rINTMSK=~(BIT_GLOBAL|BIT_EINT3);
Uart_Getch();
rINTMSK |=BIT_GLOBAL|BIT_EINT3;
Uart_Printf("[Touch Screen Test Over]\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -