OCMJ815触摸屏使用范例

源代码在线查看: ocmj815b.c

软件大小: 50 K
上传用户: haoding306
关键词: OCMJ 815 触摸屏 范例
下载地址: 免注册下载 普通下载 VIP

相关代码

				/*^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ */
				/*&&&&&&&&&&&&&&&&&&&&&&& START &&&&&&&&&&&&&&&&&&&&&&&&&&*/
				//函数名:    main()
				//功能:      主函数,先显示一行字和X=,Y=然后判断INT是否中断,中断了再显示
				              //触摸处内容和触摸处坐标值
				//输入:      无
				//输出:      无
				//By:       李 平 2007.7.11
				//备注:
				#include 
				#include 
				#include "Portini.h"
				#include "function.h"
				#include "Data.h"
				#include "delay.h"
				
				void main ()
				{
				   uchar j=0	  ;
				    DDRA=0XFF;
				    DDRB=0X1e;
				     req_clr;
				     DDRB=0x1f;    //busy=1;
				       busy_set;
				     DDRB=0x1e;
				while(1)
				 {  
				  disp1line(code0);          //显示一行字
				  write(0xf9,24,0);          //显示X
				    send(0x58);
				  write(0xf9,24,16);         //显示Y
				    send(0x59);
				  write(0xf9,25,0);          //显示‘= ’
				    send(0x3d);
				  write(0xf9,25,16);         //显示‘= ’
				    send(0x3d);
				for(j=0;j				  {
				       write(0xf2,239,j);
				      // send(1);
				  }
				 // disp_img(img);
				    /*
					    write(0xf9,5,16);
						   send(0x31);      //1
						write(0xf9,5,48);
						   send(0x32);      //2
						write(0xf9,5,80);
						   send(0x33);      //3
						write(0xf9,5,112);
						   send(0x34);      //4
						   
				        write(0xf9,12,16);
						   send(0x35);      //5
						write(0xf9,12,48);
						   send(0x36);      //6
						write(0xf9,12,80);
						   send(0x37);      //7
						write(0xf9,12,112);
						   send(0x38);      //8
					
				        write(0xf9,20,16);
						   send(0x39);      //9
						write(0xf9,20,48);
						   send(0x41);      //A
						write(0xf9,20,80);
						   send(0x42);      //B
						write(0xf9,20,112);
						   send(0x43);      //C
						  
				       // write(0xf9,27,16);
						  // send(0x44);      //D
						write(0xf9,27,48);
						   send(0x45);      //E
						write(0xf9,27,80);
						   send(0x46);      //F
						write(0xf9,27,112);
						   send(0x47);      //G
						   
					//send(0xf5);              //上移一个点阵
					*/
				  if(!(intt))
				     {
				       delay_nus(10000);
				        if(!(intt))                   
				           {
				               DDRB=0X5e;      //ip=1;
				               int_set;        //而非clr;
				               DDRB=0X1e;
				               bang();
				           }
				     }   
				  }
				}
				/*^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ */
				/*&&&&&&&&&&&&&&&&&&&&&&& START &&&&&&&&&&&&&&&&&&&&&&&&&&*/
				//函数名:         bang()
				//功能:           有触摸的时候,显示触摸处的X,Y值并执行触摸操作
				//输入:          条件int=0
				//输出:           无
				//By:             李 平 2007.7.11
				//备注:
				void bang(void)
				{
				unsigned int X=0,Y=0;
				//delay(10000);
				//中断后延时以消除抖动,使得采样数据更准确
				     spi_start(); //启动SPI
				         delay_nus(2);
				     WriteCharTo7843(0x90); //送控制字 10010000 即用差分方式读X坐标 详细请见有关资料
				         delay_nus(2);
				     clk_set;
							asm("nop");
							asm("nop");
							asm("nop");
				     clk_clr;
							asm("nop");
							asm("nop");
							asm("nop");
				     X=ReadFromCharFrom7843();  //读X轴坐标
				     WriteCharTo7843(0xD0); //送控制字 11010000 即用差分方式读Y坐标 详细请见有关资料
				     clk_set;
							asm("nop");
							asm("nop");
							asm("nop");
				     clk_clr;
							asm("nop");
							asm("nop");
							asm("nop");
				     Y=ReadFromCharFrom7843();  //读Y轴坐标
				     cs_set;
				         DDRB=0X5e;    //ip=1;
				         int_set;
				         DDRB=0x1e;
				    tabx[0]=(X/1000);
				    tabx[1]=(X-tabx[0]*1000)/100;
				    tabx[2]=(X-tabx[0]*1000-tabx[1]*100)/10;
				    tabx[3]=(X-tabx[0]*1000-tabx[1]*100-tabx[2]*10);
				    taby[0]=(Y/1000);
				    taby[1]=(Y-taby[0]*1000)/100;
				    taby[2]=(Y-taby[0]*1000-taby[1]*100)/10;
				    taby[3]=(Y-taby[0]*1000-taby[1]*100-taby[2]*10);
				   /*   if(X>3000)
				        if(Y>2600)
				          disp2lines(code1);
				      if(X				        if(X>1600)
				           if(Y>2600)
				              disp_img(img);
				      if(X				        if(Y>2600)
				           disp1line(code2);
				      if(Y				        send(0xf4);
					*/
				//以下引处为将屏幕分为1-G份,显示用8*16,按下后在旁边显示8*8汉字
					/*
					if(X>3000)
					  if(Y>3000)
					   {
					    write(0xf1,2,20);
						send(0x31);      //1
					   }
					 if(X>2000&&X					   if(Y>3000)
					     {
					       write(0xf1,2,52);
						   send(0x32);      //2
						 }
					 if(X>1000&&X					   if(Y>3000)
					     {
					       write(0xf1,2,84);
						   send(0x33);      //3
						 }
					 if(X>0&&X					   if(Y>3000)
					     {
					       write(0xf1,2,116);
						   send(0x34);      //4
						 }		 
						 
						 
					if(X>3000)
					  if(Y2000)
					   {
					    write(0xf1,9,20);
						send(0x35);      //5
					   }
					 if(X>2000&&X					  if(Y2000)
					     {
					       write(0xf1,9,52);
						   send(0x36);      //6
						 }
					 if(X>1000&&X					  if(Y2000)
					     {
					       write(0xf1,9,84);
						   send(0x37);      //7
						 }
					 if(X>0&&X					  if(Y2000)
					     {
					       write(0xf1,9,116);
						   send(0x38);      //8
						 }		
						 
					if(X>3000)
					  if(Y1000)
					   {
					    write(0xf1,17,20);
						send(0x39);      //9
					   }
					 if(X>2000&&X					  if(Y1000)
					     {
					       write(0xf1,17,52);
						   send(0x41);      //A
						 }
					 if(X>1000&&X					  if(Y1000)
					     {
					       write(0xf1,17,84);
						   send(0x42);      //B
						 }
					 if(X>0&&X					  if(Y1000)
					     {
					       write(0xf1,17,116);
						   send(0x43);      //C
						 }		
				
					/*if(X>3000)
					  if(Y0)
					   {
					    write(0xf1,24,20);
						send(0x44);      //d
					   }
					
					 if(X>2000&&X					  if(Y0)
					     {
					       write(0xf1,24,52);
						   send(0x45);      //e
						 }
					 if(X>1000&&X					   if(Y0)
					     {
					       write(0xf1,24,84);
						   send(0x46);      //f
						 }
					 if(X>0&&X					  if(Y0)
					     {
					       write(0xf1,24,116);
						   send(0x47);      //g
						 }
				  */
				    disptouch();                 //显示触摸坐标
					disp_ciclr(X,Y);	         //根据触摸处画轨迹//
					//send(0x01);
					//send(0xfb);                //开光标
					//send(0x07);
					//send(0xfc);                //移动速度为16点
					//send(0x0f);
					//send(0xf8);                 //右移一个点阵
					
				}
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
							

相关资源