⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ads7843.c

📁 本程序是FS44B0XII V3.00开发板C57和G57液晶屏套件程序
💻 C
字号:
/****************************************************************************
【文  件  名  称】ADS7843.c
【功  能  描  述】ADS7843触摸屏驱动程序
【程  序  版  本】1.0
【创建人及创建日期】龚俊/2004-5-5 16:43
【修改人及修改日期】龚俊/2004-5-9 22:08
****************************************************************************/

//***************************************************************************
#include "44b.h"
#include "def.h"
#include "option.h"
#include "utils.h"

#include "ads7843.h"

#include "lcdlib.h"
#include "glib.h"
//***************************************************************************

/****************************************************************************
【功能说明】
****************************************************************************/
void ADS7843_SPI_Start( void )
{
    TP_DCLK(0);
	TP_CS(1);
	TP_DIN(1);
    TP_DCLK(1);
    TP_CS(0);	      		//芯片允许
}
//***************************************************************************

/****************************************************************************
【功能说明】向ADS7843
****************************************************************************/
void ADS7843_Write ( U8 cmd )
{
	U8 buf, i, j ;

    TP_DCLK(0);
    
	for( i = 0; i < 8; i++ )
	{
		buf = (cmd >> (7-i)) & 0x1 ;	//MSB在前,LSB在后
		TP_DIN(buf);	 	//时钟上升沿锁存DIN
		
		for( j = 0; j < 25; j++ );	//200ns
		TP_DCLK(1);			//开始发送命令字
		
		for( j = 0; j < 25; j++ );	//200ns
		TP_DCLK(0);			//时钟脉冲,一共8个
	}
}
//***************************************************************************

/****************************************************************************
【功能说明】读取ADS7843的ADC数据
****************************************************************************/
U16 ADS7843_Read ( void )
{
	U16 buf = 0 ;
	U8 i, j ;
	
	for( i = 0; i < 12; i++ )
	{
		buf = buf << 1 ;
		
		TP_DCLK(1);
		for( j = 0; j < 25; j++ );		//200ns
		TP_DCLK(0);			
		for( j = 0; j < 5; j++ );	//时钟下降沿读取,一共12个,MSB在前,LSB在后

		if ( TP_DOUT )		buf = buf + 1 ;

		for( j = 0; j < 20; j++ );		//200ns
	}
/*	
	for( i = 0; i < 4; i++ )
	{
		TP_DCLK(1);
		for( j = 0; j < 25; j++ );		//200ns
		TP_DCLK(0);			
		for( j = 0; j < 25; j++ );	//4个没用时钟
	}	
*/
	return( buf ) ;
}
//***************************************************************************

/****************************************************************************
【功能说明】触摸屏和256色LCD处理子程序
****************************************************************************/
void ADS7843_Get_XY( U16 *x, U16 *y )
{
	U16 j ;
	
	//for( j = 0; j < 10000; j++ );		//延时一下再响应其请求,消除抖动使得采样更准确
	//for( j = 0; j < 1000; j++ );		//延时一下再响应其请求,消除抖动使得采样更准确
	
	ADS7843_SPI_Start() ;
	for( j = 0; j < 5; j++ );		//40ns
	//while ( TP_BUSY ) ;		//如果BUSY,等待直到转换完毕,这个可以不用
	
	ADS7843_Write( CHX ) ;
	for( j = 0; j < 25; j++ );		//200ns
	*y = ADS7843_Read() ;
	
	ADS7843_Write( CHY ) ;
	for( j = 0; j < 25; j++ );		//200ns
	*x = ADS7843_Read() ;

    TP_CS(1);	      		//芯片禁止

	//printf( "\tx = %04d y = %04d\n", x, y );
}
//***************************************************************************

/****************************************************************************
【功能说明】ADS7843触摸屏和256色伪彩液晶屏测试程序
****************************************************************************/
void ADS7843_C256LCD_Test( void )
{	
	U16 lcd_x, lcd_y ;
	
	printf( "\nADS7843 Touch Panel and Color256 LCD Test!\n" );

	//***************************************************************************
    Lcd_Init(MODE_COLOR);
    Glib_Init(MODE_COLOR);
    Lcd_DispON();
    Lcd_BlackLight_ON() ;
    Glib_ClearScr( (7<<5)|(7<<2)|(3) );
	//***************************************************************************

	//ADS7843触摸屏初始化
	//***************************************************************************
    rINTMSK = 0x7ffffff;	  // All interrupt is masked.
	rPCONB = rPCONB & (~(3<<4)) ;		//GPB4,GPB5 set OUTPUT
	
	rPCONE = rPCONE & (~(3)) & (~(3<<14)) | (1) ;		//GPE0 set OUTPUT, GPE7 set INPUT
	rPUPE = rPUPE | (1) | (1<<7) ;		//pull up resistor is disable
	
	rPCONF = rPCONF & (~(7<<16)) ;		//GPF7 set INPUT
	rPUPF = rPUPF | (1<<7) ;		//pull up resistor is disable

	rPCONG = rPCONG & (~(3<<6)) ;		//GPG3 set INPUT
	rPUPG = rPUPG | ((1<<3)) ;		//pull up resistor is disable

	//***************************************************************************
    rPCONG = rPCONG & (~( 0x3f<<10 )) ;		//GPG5,GPG6,GPG7 is input
	//***************************************************************************
	
	printf( "\nWait for hit the touch panel!   Press ESC to Exit!\n" );

    while( !( kbhit && (getkey()==ESC_KEY) ) )
    {
		ADS7843_Get_XY( &lcd_x, &lcd_y ) ;
    	if( TP_IRQ == 0 )
    	{
   			ADS7843_Get_XY( &lcd_x, &lcd_y ) ;
   			
   			if( (lcd_x != 4095)&&(lcd_y != 4095)&&(lcd_x != 0)&&(lcd_y != 0) )
   			{
				lcd_x = ( lcd_x/(4095/320) ) ;
				lcd_y = 240 - ( lcd_y/(4095/240) ) ;

				printf( "\tlcd_x = %04d lcd_y = %04d\n", lcd_x, lcd_y );
				PutPixel( (lcd_x+0), (lcd_y+0), (0<<5)|(0<<2)|(0) ) ;
				PutPixel( (lcd_x+0), (lcd_y+1), (0<<5)|(0<<2)|(0) ) ;
				PutPixel( (lcd_x+1), (lcd_y+0), (0<<5)|(0<<2)|(0) ) ;
				PutPixel( (lcd_x+1), (lcd_y+1), (0<<5)|(0<<2)|(0) ) ;
			}
    	}

    	if( (rPDATG&0xe0) != 0xe0 )
    	{
    		Glib_ClearScr( 0xff ) ;
    	}
    }

}
//***************************************************************************

/****************************************************************************
【功能说明】ADS7843触摸屏和黑白液晶屏测试程序
****************************************************************************/
void ADS7843_LCD_MONO_Test( void )
{
	//signed short m, n ;
	//U16 TP_X[16], TP_Y[16] ;
	U16 lcd_x, lcd_y ;

	printf( "\nADS7843 Touch Panel and MONO LCD Test!\n" );

	//***************************************************************************
    Lcd_Init(MODE_MONO);
    Glib_Init(MODE_MONO);
    Lcd_DispON();
    Lcd_BlackLight_ON() ;
    Glib_ClearScr( 0x01 ) ;
	//***************************************************************************

	//ADS7843触摸屏初始化
	//***************************************************************************
    rINTMSK = 0x7ffffff;	  // All interrupt is masked.
	rPCONB = rPCONB & (~(3<<4)) ;		//GPB4,GPB5 set OUTPUT
	
	rPCONE = rPCONE & (~(3)) & (~(3<<14)) | (1) ;		//GPE0 set OUTPUT, GPE7 set INPUT
	rPUPE = rPUPE | (1) | (1<<7) ;		//pull up resistor is disable
	
	rPCONF = rPCONF & (~(7<<16)) ;		//GPF7 set INPUT
	rPUPF = rPUPF | (1<<7) ;		//pull up resistor is disable

	rPCONG = rPCONG & (~(3<<6)) ;		//GPG3 set INPUT
	rPUPG = rPUPG | ((1<<3)) ;		//pull up resistor is disable

	//***************************************************************************
    rPCONG = rPCONG & (~( 0x3f<<10 )) ;		//GPG5,GPG6,GPG7 is input
	//***************************************************************************
	
	printf( "\nWait for hit the touch panel!   Press ESC to Exit!\n" );

    while( !( kbhit && (getkey()==ESC_KEY) ) )
    {
		ADS7843_Get_XY( &lcd_x, &lcd_y ) ;
    	if( TP_IRQ == 0 )
    	{
   			ADS7843_Get_XY( &lcd_x, &lcd_y ) ;
   			
   			if( (lcd_x != 4095)&&(lcd_y != 4095)&&(lcd_x != 0)&&(lcd_y != 0) )
   			{
				lcd_x = ( lcd_x/(4095/320) ) ;
				lcd_y = 240 - ( lcd_y/(4095/240) ) ;

				printf( "\tlcd_x = %04d lcd_y = %04d\n", lcd_x, lcd_y );
				PutPixel( (lcd_x+0), (lcd_y+0), (0<<5)|(0<<2)|(0) ) ;
				PutPixel( (lcd_x+0), (lcd_y+1), (0<<5)|(0<<2)|(0) ) ;
				PutPixel( (lcd_x+1), (lcd_y+0), (0<<5)|(0<<2)|(0) ) ;
				PutPixel( (lcd_x+1), (lcd_y+1), (0<<5)|(0<<2)|(0) ) ;
			}
    	}

    	if( (rPDATG&0xe0) != 0xe0 )
    	{
    		Glib_ClearScr( 1 ) ;
    	}
    }

}
//***************************************************************************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -