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

📄 320240mine.c

📁 ra8806触摸屏控制芯片完全c51底层驱动
💻 C
字号:

#include<User.h>
#define tongdaoxuanze     19
#define fanhui            1
#define jiaozhungaodian   2
#define jiaozhun          3
#define shuzi1            4
#define shuzi2            5
#define shuzi3            6
#define shuzi4            7
#define shuzi5            8
#define shuzi6            9
#define shuzi7            10
#define shuzi8            11
#define shuzi9            12
#define shuzi0            13
#define jiaozhunqueding   14
#define tongdao          15
#define tongdao2          16
#define tongdao3          17
#define tongdao4          18
bit monitor1 = 0;
bit monitor2 = 0;
bit monitor3 = 0;
bit keyboard_flag = 0;
uchar code num[]={
0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39
};
void main(void)
{
	CFG836=0x81;
	delay1ms(20);
	Rst();
	Initiate();


	//Wrr_Addr(BTMR);	//光标闪烁时间
	//Wrr_Data(0x20);
	//Wr_Data(ITCR,0xff); 
	//
	Access_2Pages();
	Lcd_Clear();
	//Dis_Blank_Rec(10,10,20,90);
	//Dis_Black_Rec(2,3,7,43);
	/*Dis_Point(0,0,1);
	Dis_Point(1,0,0);
	Dis_Point(2,0,1);
	Dis_Point(3,0,0);
	Dis_Point(4,0,1);
	Dis_Point(5,0,0);
	Dis_Point(6,0,1);*/


	/*Dis_Circle(150,150,20,1);
	Dis_Linexy(0,0,150,150,1);
	delay1ms(10);
	Dis_Linexy(0,0,150,150,0);*/
	
	//Dis_Black_Rec(0,0,20,20,1);
	//Dis_Blank_Rec(30,0,50,20,1);
	//Dis_DDRAM2_Pic();
	//test();
	//Dis_Touch();
	//while(1);
	//Display_Picture();
	//LCD_CmdWrite(ITCR);	
	//LCD_DataWrite(0xff);
	//LCD_LineDist_Adjust(0);

	//Show_Two_Layer();
	//Only_Show_Page2();
	/*Dis_Linexy(5,40,10,35,1);
	Dis_Linexy(10,35,15,40,1);
	Dis_Linexy(10,35,10,230,1);
	Dis_Linexy(10,230,300,230,1);
	Dis_Linexy(300,230,295,225,1);
	Dis_Linexy(295,235,300,230,1);*///用画线函数画坐标系 
	
	Access_Page1();
	Only_Show_Page1();
	Dis_Blank_Rec(0,29,40,239);
	
	Dis_Pos_Pic(0,0,72,28,gImage_pic1);
	Dis_Pos_Pic(10,0,80,28,gImage_pic2);
	Dis_Pos_Pic(21,0,72,28,gImage_pic3);
	Dis_Pos_Pic(31,0,72,28,gImage_pic4);

	Dis_Pos_Pic(1,33,16,200,gImage_vertical);
	Dis_Pos_Pic(2,229,288,7,gImage_horizen);
	Lcd_On();
	draw();
	monitor1 = 1;
	Dis_Touch();//主界面

	/*Dis_Text(8,10,11,4,sRAiO3);
	Dis_Blank_Rec(4,38,34,38);

	Dis_Blank_Rec(4,60,7,84);
	Dis_Linexy(33,72,40,84,1);
	Dis_Linexy(41,83,55,60,1);//对勾图
	Dis_Text(14,64,6,4,sRAiO5);
	Dis_Blank_Rec(4,99,7,123);
	Dis_Text(14,103,6,4,sRAiO6);
	Dis_Blank_Rec(4,138,7,162);
	Dis_Text(14,142,8,4,sRAiO7);
	Dis_Blank_Rec(4,177,7,201);
	Dis_Text(14,181,8,4,sRAiO8);
	Dis_Pos_Pic(31,206,64,32,gImage_back);//通道界面
	Dis_Touch();*/

	/*Dis_Text(12,10,6,4,sRAiO4);
	Lcd_Graphic();
	//Dis_Text(4,38,30,0,sRAiO2);
	Dis_Blank_Rec(4,38,34,38);

	Dis_Blank_Rec(4,60,7,84);
	Dis_Text(26,64,6,0,sRAiO9);
	Dis_Blank_Rec(4,99,7,123);
	Dis_Text(26,103,6,0,sRAi10);
	
	Lcd_Graphic();
	Dis_Linexy(32,72,55,72,1);
	Dis_Linexy(50,67,55,72,1);
    Dis_Linexy(55,72,50,77,1);
	//Dis_Linexy(33,123,260,123,1);
	Dis_Pos_Pic(32,206,64,32,gImage_back);
	Keyboard(4,45);//校准界面
	Dis_Touch();*/


    //Dis_Pos_Pic(0,0,256,10,gImage_pic5);
	//Dis_Pos_Pic(4,30,16,200,gImage_pic6);
	//Only_Show_Page1();
	//Dis_Touch();
	while(1);
	
	//Dis_Ratate_90();
	/*Dis_DDRAM1_Pic();
	Dis_DDRAM2_Pic();
	while(1)
	{
		Only_Show_Page2();
		delay1ms(100);
		Only_Show_Page1();
		delay1ms(100);
	}*/;
}

void Dis_Touch(void)
{
	while(1)
	{
		uchar temp = 0;
		uchar debounce = 0;
		uchar num2[4];
		Wrr_Addr(0xc0);//打开触摸
		Wrr_Data(0xc4);
		temp = Key_Scan();
		while(monitor1 == 1)
		{
			temp = Key_Scan();
	
			if(temp == tongdaoxuanze) 
			{
				Show_Moniter2();
				break;
			}
	
			if(temp == jiaozhun) 
			{
				
				Show_Monitor3();
				break;
			}
		}
			while(monitor3 == 1)
			{
				uchar temp,i,count;
				temp = Key_Scan();
				if((temp == jiaozhungaodian)&&(keyboard_flag==0)) 
				{
					Keyboard(4,45);
					keyboard_flag = 1;
				}
				if((temp == shuzi1)&&(keyboard_flag==1)) 
				{
					LCD_Text();
					LCD_GotoXY((5+count),47);
					Wrr_Addr(0xb0);
					Wrr_Data('1');
					num2[count] = 1;
					count++;
					delay1ms(30);
				}
				if((temp == shuzi2)&&(keyboard_flag==1)) 
				{
					LCD_Text();
					LCD_GotoXY((5+count),47);
					Wrr_Addr(0xb0);
					Wrr_Data('2');
					num2[count] = 2;
					count++;
					delay1ms(30);
				}
				if((temp == shuzi3)&&(keyboard_flag==1)) 
				{
					LCD_Text();
					LCD_GotoXY((5+count),47);
					Wrr_Addr(0xb0);
					Wrr_Data('3');
					num2[count] = 3;
					count++;
					delay1ms(30);
				}
				if((temp == shuzi4)&&(keyboard_flag==1)) 
				{
					LCD_Text();
					LCD_GotoXY((5+count),47);
					Wrr_Addr(0xb0);
					Wrr_Data('4');
					num2[count] = 4;
					count++;
					delay1ms(30);
				}
				if((temp == shuzi5)&&(keyboard_flag==1)) 
				{
					LCD_Text();
					LCD_GotoXY((5+count),47);
					Wrr_Addr(0xb0);
					Wrr_Data('5');
					num2[count] = 5;
					count++;
					delay1ms(30);
				}
				if((temp == shuzi6)&&(keyboard_flag==1)) 
				{
					LCD_Text();
					LCD_GotoXY((5+count),47);
					Wrr_Addr(0xb0);
					Wrr_Data('6');
					num2[count] = 6;
					count++;
					delay1ms(30);
				}
				if((temp == shuzi7)&&(keyboard_flag==1)) 
				{
					LCD_Text();
					LCD_GotoXY((5+count),47);
					Wrr_Addr(0xb0);
					Wrr_Data('7');
					num2[count] = 7;
					count++;
					delay1ms(30);
				}
				if((temp == shuzi8)&&(keyboard_flag==1)) 
				{
					LCD_Text();
					LCD_GotoXY((5+count),47);
					Wrr_Addr(0xb0);
					Wrr_Data('8');
					num2[count] = 8;
					count++;
					delay1ms(30);
				}
				if((temp == shuzi9)&&(keyboard_flag==1)) 
				{
					LCD_Text();
					LCD_GotoXY((5+count),47);
					Wrr_Addr(0xb0);
					Wrr_Data('9');
					num2[count] = 9;
					count++;
					delay1ms(30);
				}
				if((temp == shuzi0)&&(keyboard_flag==1)) 
				{
					LCD_Text();
					LCD_GotoXY((5+count),47);
					Wrr_Addr(0xb0);
					Wrr_Data('0');
					num2[count] = 0;
					count++;
					delay1ms(30);
				}

				if(temp == fanhui) 
				{
					Only_Show_Page1();
					monitor1=1;
					break;
				}
				if((temp == jiaozhunqueding)&&(keyboard_flag==1)) 
				{

					LCD_GotoXY(5,47);
					Clean_Area(2,40,19,235);
					Lcd_Graphic();
					//Dis_Text(4,38,30,0,sRAiO2);
					Dis_Blank_Rec(4,38,34,38);
				
					Dis_Blank_Rec(4,60,7,84);
					Dis_Text(15,64,6,0,sRAiO9);
					Dis_Blank_Rec(4,99,7,123);
					Dis_Text(15,103,6,0,sRAi10);
					
					Lcd_Graphic();
					Dis_Linexy(32,72,55,72,1);
					Dis_Linexy(50,67,55,72,1);
				    Dis_Linexy(55,72,50,77,1);
					//Dis_Linexy(33,123,260,123,1);
					Dis_Pos_Pic(32,206,64,32,gImage_back);

					keyboard_flag=0;
					LCD_Text();
					LCD_GotoXY(22,64);
				
					Wrr_Addr(0xb0);
					for(i=0;i<count;i++)
						Wrr_Data(num[num2[i]]);
				
					num2[0] = 0;
					num2[1] = 0;
					num2[2] = 0;
					num2[3] = 0;
					count = 0;
				}
				
				if(count==4)
				{
					count = 0;
					LCD_GotoXY(5,47);
				}
			}
			while(monitor2 == 1)
			{
				uchar temp;
				temp = Key_Scan();
				
				if(temp == tongdao2)
			    {
					rec(33,72,0);
					rec(33,111,1);
					rec(33,150,0);
					rec(33,189,0);
				}
				if(temp == tongdao3)
			    {
					rec(33,72,0);
					rec(33,111,0);
					rec(33,150,1);
					rec(33,189,0);
				}
				if(temp == tongdao4)
			    {
					rec(33,72,0);
					rec(33,111,0);
					rec(33,150,0);
					rec(33,189,1);
				}
				if(temp == tongdao)
			    {
					rec(33,72,1);
					rec(33,111,0);
					rec(33,150,0);
					rec(33,189,0);
				}
				if(temp == fanhui) 
				{
					Only_Show_Page1();
					monitor1=1;
					break;
				}
			}
	}
}
void Clean_Area(uchar a,uchar b,uchar c,uchar d)
{
	uchar i,length,height,j;
	length = c-a;
	height = d-b;

	//Access_Page1();
	//Only_Show_Page1();
	//LCD_Text();
	Lcd_Graphic();
	for(i=0;i<height;i++)
		{	
			LCD_GotoXY(a,(b+i));
			Wrr_Addr(0xb0);
			for(j=0;j<length;j++)
				Wrr_Data(0);
		}
}
void Keyboard(uchar px,uchar py)
{
	Clean_Area(px,py,(px+14),(py+185));
	Dis_Blank_Rec((px-1),(py-4),(px+15),(py+188));
	Dis_Blank_Rec(px,py,(px+14),(py+24));
	Dis_Pos_Pic(px,(py+32),32,32,gImage_1);
	Dis_Pos_Pic((px+5),(py+32),32,32,gImage_2);
	Dis_Pos_Pic((px+10),(py+32),32,32,gImage_3);
	Dis_Pos_Pic(px,(py+72),32,32,gImage_4);
	Dis_Pos_Pic((px+5),(py+72),32,32,gImage_5);
	Dis_Pos_Pic((px+10),(py+72),32,32,gImage_6);
	Dis_Pos_Pic(px,(py+112),32,32,gImage_7);
	Dis_Pos_Pic((px+5),(py+112),32,32,gImage_8);
	Dis_Pos_Pic((px+10),(py+112),32,32,gImage_9);
	Dis_Pos_Pic((px),(py+152),32,32,gImage_0);
	Dis_Pos_Pic((px+5),(py+152),48,32,gImage_finish);
}
void draw(void)
{
	uchar stack,m;
	xdata uchar mdata[240];
	for(stack = 0;stack<240;stack++)
	{		mdata[stack] = stack;
		if(stack>50) mdata[stack] = (stack-50);
		if(stack>100) mdata[stack] = (stack-100);
		if(stack>150) mdata[stack] = (stack-150);
		if(stack>200) mdata[stack] = (stack-200);
		Dis_Point((20+stack),(mdata[stack]+100),1);

	}
	//for(m = 0;m<240;m++)
		//Dis_Point((20+m),(mdata[m]+100),1);

}
void rec(uchar px,uchar py,uchar att)
{
	Dis_Linexy(px,py,(px+7),(py+11),att);
	Dis_Linexy((px+8),(py+10),(px+21),(py-11),att);
}
/*void draw(void)
{
	uchar i;
	xdata uchar mdata[240];
	for(i=0;i<100;i++)
		mdata[i]=i;
	for(i=99;i>=0;i--)
	{	mdata[i+1] = mdata[i];

		Dis_Point((20+98-i),(mdata[99-i]+100),0);
		Dis_Point((20+99-i),(mdata[99-i]+100),1);
	}
}
void draw(void)
{
	uchar i,j,k;
	xdata uchar mdata[100];
	for(i = 0;i < 100;i++)
	{
		
		if(i<50) mdata[0] = i;
		else mdata[0] = (i-50);
		for(j = i;j > 0;j--)
			mdata[j] = mdata[j-1];
		mdata[0] = 0;
		for(k = 1;k <i+1;k++)
		{
			Dis_Point((k+30),(100+mdata[k+1]),0);
			Dis_Point((k+30),(100+mdata[k]),1);

		}
	}
}*/
uchar Key_Scan(void)
{
	uchar X1,X2,Y1,Y2,temp;
	Wrr_Addr(0x0f);
	Wrr_Data(0x00);
	delay1ms(1);//必须加延迟
	Wrr_Addr(0x0f);
	temp = Read_Data();
	
	if((temp&0x01) == 0x01)
	{

			X1 = ADC_X1_MSB();
			Y1 = ADC_Y1_MSB();
			delay1ms(2);
		if((X1 > 0x18)&&(X1 < 0xF0)&&(Y1 > 0x1B)&&(Y1 < 0xEA))
		{
			X2 = ADC_X1_MSB();
			Y2 = ADC_Y1_MSB();
			if((X2 == X1)&&(Y2 == Y1))
			{
				LCD_Text();
				LCD_FontSize(0);
				LCD_GotoXY(0x20,0x50);
				Print_Hex(X1);
				LCD_GotoXY(0x23,0x50);
				Print_Hex(Y1);	//测绘按钮用代码

				if((Y1>0x1c)&&(Y1<0x30)&&(X1>0xc2)&&(X1<0xeb)) return 19;
			
				if((Y1>0xca)&&(Y1<0xe2)&&(X1>0x1c)&&(X1<0x40)) return 1;
	
				if((Y1>0x4b)&&(Y1<0x62)&&(X1>0xcd)&&(X1<0xdf)) return 2;
	
				if((Y1>0x1c)&&(Y1<0x30)&&(X1>0x55)&&(X1<0x7d)) return 3;
	
				if((Y1>0x5c)&&(Y1<0x73)&&(X1>0xcb)&&(X1<0xde)) return 4;
	
				if((Y1>0x5f)&&(Y1<0x74)&&(X1>0xaf)&&(X1<0xc0)) return 5;
	
				if((Y1>0x5e)&&(Y1<0x74)&&(X1>0x93)&&(X1<0xa5)) return 6;
	
				if((Y1>0x82)&&(Y1<0x97)&&(X1>0xcb)&&(X1<0xdc)) return 7;
	
				if((Y1>0x80)&&(Y1<0x97)&&(X1>0xaf)&&(X1<0xc1)) return 8;
	
				if((Y1>0x81)&&(Y1<0x97)&&(X1>0x93)&&(X1<0xa5)) return 9;
	
				if((Y1>0xa5)&&(Y1<0xba)&&(X1>0xc9)&&(X1<0xdd)) return 10;
	
				if((Y1>0xa5)&&(Y1<0xba)&&(X1>0xaf)&&(X1<0xc1)) return 11;
				if((Y1>0xa5)&&(Y1<0xba)&&(X1>0x93)&&(X1<0xa5)) return 12;
	
				if((Y1>0xc8)&&(Y1<0xdd)&&(X1>0xcb)&&(X1<0xdb)) return 13;
	
				if((Y1>0xc9)&&(Y1<0xdd)&&(X1>0xa4)&&(X1<0xbf)) return 14;
	
				
	
				if((Y1>0x42)&&(Y1<0x69)&&(X1>0xc0)&&(X1<0xe1)) return 15;
	
				if((Y1>0x70)&&(Y1<0x81)&&(X1>0xcf)&&(X1<0xdc)) return 16;
	
				if((Y1>0x91)&&(Y1<0xa6)&&(X1>0xcf)&&(X1<0xdc)) return 17;
	
				if((Y1>0xb5)&&(Y1<0xc8)&&(X1>0xcf)&&(X1<0xdc)) return 18;
			} 
	 	}

   }
}
void Show_Moniter2(void)
{
	Only_Show_Page2();
	Access_Page2();
	if(monitor2==0)
	{
		Lcd_Clear();
		Dis_Text(8,10,11,4,sRAiO3);
		Dis_Blank_Rec(4,38,34,38);
		
		Dis_Blank_Rec(4,60,7,84);
		Dis_Text(14,64,6,4,sRAiO5);
		Dis_Blank_Rec(4,99,7,123);
		Dis_Text(14,103,6,4,sRAiO6);
		Dis_Blank_Rec(4,138,7,162);
		Dis_Text(14,142,8,4,sRAiO7);
		Dis_Blank_Rec(4,177,7,201);
		Dis_Text(14,181,8,4,sRAiO8);
		LCD_Text();
		Dis_Pos_Pic(32,206,64,32,gImage_back);
		monitor1 = 0;
		monitor2 = 1;
		monitor3 = 0;
	}
}
void Show_Monitor3(void)
{
	Only_Show_Page2();
	Access_Page2();
	if(monitor3 == 0)
	{
	Lcd_Clear();
	Dis_Text(12,10,6,4,sRAiO4);
	Lcd_Graphic();
	//Dis_Text(4,38,30,0,sRAiO2);
	Dis_Blank_Rec(4,38,34,38);
	
	Dis_Blank_Rec(4,60,7,84);
	Dis_Text(15,64,6,0,sRAiO9);
	Dis_Blank_Rec(4,99,7,123);
	Dis_Text(15,103,6,0,sRAi10);
	
	Lcd_Graphic();
	Dis_Linexy(32,72,55,72,1);
	Dis_Linexy(50,67,55,72,1);
	Dis_Linexy(55,72,50,77,1);
	//Dis_Linexy(33,123,260,123,1);
	Dis_Pos_Pic(32,206,64,32,gImage_back);
	monitor1 = 0;
	monitor3 = 1;
	monitor2 = 0;
	}
}

⌨️ 快捷键说明

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