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

📄 main.c

📁 7843的妙用。有7843的初始化、等等。
💻 C
字号:
#include "at89x52.h"
#include "common.h"
#include "intrins.h"

//uchar X=0,Y=0;

uint X=0,Y=0;
uint X_LCD=0;Y_LCD=0;
unsigned long int TchScr_Xmin=0,TchScr_Ymin=0,TchScr_Xmax=0xfff,TchScr_Ymax=0xfff;
unsigned long int LCDWIDTH=320,LCDHEIGHT=240;//width=0x140 height=0xf0

uint keytable[][4]={
{20,20,60,60},		//red
{140,100,180,140},		//green
};

void initial(void)
{
//	P1=P2=P3=P0=0xff;
	SCON=0x50;			// UART_mode=1,REN=1
	RCAP2H=0xFF; 
	RCAP2L=0xDC;		// 9600,
	T2MOD=0;  
	T2CON=0x34;        // Set T2 to baud rate register  
	EX0=1;   
	EA=1;

}

void delay(unsigned char i)
{
	while(i--);
}


void delay_1ms(uint x) 
{ 
	uint j; 
	uchar i; 
	for(j=0;j<x;j++) 
		for(i=0;i<120;i++)
			; 
}


void send232 (uchar ch)
{	
    SBUF=ch;
    while(TI==0);
    TI=0;
}


void start7843(void)
{
	DCLK=0;
	CS=1;
	DIN=1;
	DCLK=1;
	CS=0;
}
/*
void stop7843(void)
{
	DCLK=0;
	DIN=0;
	DOUT=1;
	CS=1;
}
*/
void write7843 (uchar num)
{
	uchar count;
	DCLK=0;
	for(count=0;count<8;count++)
	{
		num<<=1;
		DIN=CY;
		DCLK=0;
		_nop_();_nop_();_nop_();
		DCLK=1;
		_nop_();_nop_();_nop_();
	}
}

uint read7843 (void)
{
	uchar count;
	uint codata;
	codata=0;
	DCLK=0;
	for (count=0;count<12;count++)
	{
		codata<<=1;
		DCLK=1;
		_nop_();_nop_();_nop_();
		DCLK=0;
		_nop_();_nop_();_nop_();
		if(DOUT)
			codata++;
	}
	return(codata);
}


void IT0_int(void) interrupt 0   
{
	start7843();
	delay(2);
 	write7843(0x94);
	DCLK=1;
	_nop_();_nop_();_nop_();_nop_();
	DCLK=0;
	_nop_();_nop_();_nop_();_nop_();
	X=read7843();
	write7843(0xD4);
	DCLK=1;
	_nop_();_nop_();_nop_();_nop_();
	DCLK=0; 
	_nop_();_nop_();_nop_();_nop_();
	Y=read7843();
	CS=1;
}


void switchXY (void)
{
	unsigned long int s;
	s=((unsigned long int)X-TchScr_Xmin)*LCDWIDTH;
	X_LCD=(uint)(s/(TchScr_Xmax-TchScr_Xmin));
	s=((unsigned long int)Y-TchScr_Ymin)*LCDHEIGHT;
	Y_LCD=(uint)(s/(TchScr_Ymax-TchScr_Ymin));
}
void checkkey(void)
{
	if((X_LCD>keytable[0][0])&&(X_LCD<keytable[0][2]))
		if((Y_LCD>keytable[0][1])&&(Y_LCD<keytable[0][3]))
		{
			red=0;
			delay_1ms(1000);
			red=1;
		}
	if((X_LCD>keytable[1][0])&&(X_LCD<keytable[1][2]))
		if((Y_LCD>keytable[1][1])&&(Y_LCD<keytable[1][3]))
		{
			green=0;
			delay_1ms(1000);
			green=1;
		}
}	
void main(void)
{
	uchar X_L,X_H,Y_L,Y_H;
	initial();
	while(1)
	{
		if((X!=0)&&(Y!=0))
		{
			EX0=0;
			switchXY();
			checkkey();
			X_L=(unsigned char)(X_LCD);
 			X_H=(X_LCD>>8); 
			Y_L=(unsigned char)(Y_LCD);
 			Y_H=(Y_LCD>>8);
			send232(X_H);send232(X_L);
			send232(Y_H);send232(Y_L);		
			X=Y=0;
//			delay_1ms(1000);
			EX0=1;
		}
	}
}

⌨️ 快捷键说明

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