📄 tp.c
字号:
#include <stdio.h>
#include "..\inc\option.h"
#include "..\inc\def.h"
#include "..\inc\44b.h"
#include "..\inc\44blib.h"
#include "..\inc\tp.h"
#include "..\inc\44blcd.h"
#include "..\inc\lcdlib.h"
volatile unsigned char adcend=0;
#define frameBuffer1 0xc400000
void display(U32 xdot,U32 line);
void Adc_or_TsSep(void);
void Adc_or_TsSep(void)
{
int i,x,y;
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(400); //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);
}
y=(Pt[0]+Pt[1]+Pt[2]+Pt[3]+Pt[4])/5;
// <Y-Position Read>
//TSPX(GPE4) TSPY(GPE5) TSMY(GPE6) TSMX(GPE7)
// 1 0 1 0
rPDATE=0X58;
rADCCON=0x0<<2; // AIN0
Delay(400); //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);
}
x=(Pt[0]+Pt[1]+Pt[2]+Pt[3]+Pt[4])/5;
if(x>1000)
return;
x=((900-x)/38);
if(y>700)
y=((y-50)/17);
else if(y>200)
y=((y-50)/18);
else
y=((y-60)/24);
Uart_Printf(" X-Posion[AIN0] is %04d ",x);
Uart_Printf(" Y-Posion[AIN1] is %04d\n", y);
clrscreen();
display(x,y);
adcend=1;
rPDATE=0X78; //should be enabled
Delay(200); //delay to set up the next channel
}
void Ts_Sep(void)
{
int i;
//TSPX(GPE4) TSPY(GPE5) TSMY(GPE6) TSMX(GPE7)
// 1 1 1 0
rPUPE=0x1;
rPDATE=0x78; //should be enabled
Delay(200); //delay to set up the next channel
Uart_Printf("[Touch Screen Test.]\n");
Uart_Printf("Separate X/Y position conversion mode test\n");
LcdInit();
rEXTINT=0x22222222;
rINTCON=0x5;
pISR_EINT3=(int)Adc_or_TsSep;
rCLKCON=0x7ff8;
rADCPSR=0x4;
rINTMSK=~(BIT_GLOBAL|BIT_EINT3);
Uart_Printf("\nType any key to exit!!!\n");
Uart_Printf("\nStylus Down, please...... \n");
while(1);
rINTMSK |=BIT_GLOBAL|BIT_EINT3;
Uart_Printf("[Touch Screen Test Over]\n");
}
void LcdInit(void)
{
Lcd_MonoInit();
clrscreen();
}
void Lcd_MonoInit(void)
{
//160x240 1bit/1pixel LCD
#define MVAL_USED 0
rLCDCON1=(0)|(1<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_MONO<<12);
// disable,4B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
rLCDCON2=(LINEVAL)|(HOZVAL<<10)|(10<<21);
//LINEBLANK=10 (without any calculation)
rLCDSADDR1= (0x0<<27) | ( ((U32)frameBuffer1>>22)<<21 ) | M5D((U32)frameBuffer1>>1);
// monochrome, LCDBANK, LCDBASEU
rLCDSADDR2= M5D( (((U32)frameBuffer1+(SCR_XSIZE*LCD_YSIZE/8))>>1) ) | (MVAL<<21)|(1<<29);
rLCDSADDR3= (LCD_XSIZE/16) | ( ((SCR_XSIZE-LCD_XSIZE)/16)<<9 );
rLCDCON1=(1)|(1<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_MONO<<12);
// enable,4B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
}
void clrscreen(void)
{
int i,j;
U32 *pbuffer;
pbuffer =(U32*) frameBuffer1;
for (i=0;i<1200;i++)
{
pbuffer[i] =0x0;
}
}
void display(U32 xdot,U32 line)
{
unsigned char *pbuffer;
unsigned char i;
pbuffer =(U8*) frameBuffer1;
for (i=0;i<8;i++)
{
pbuffer[20*5*line+xdot+i*20]=0xff;}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -