ini2440 触摸屏实验

来源:互联网 发布:office2003是什么软件 编辑:程序博客网 时间:2024/06/02 17:55



本实验为mini2440触摸屏裸机驱动实验,通过点击触摸屏获得该点的坐标,然后通过UART显示在电脑上,主要配置ADCCON控制寄存器,利用中断模式读取X,Y坐标,并显示出来,代码后注释已经详细给出,具体实验代码如下:

#define GLOBAL_CLK 1

#include <stdlib.h>

#include <string.h>

#include "def.h"

#include "option.h"

#include "2440addr.h"

#include "2440lib.h"

#include "2440slib.h"

#include "lcdlib.c"

#include "lcdlib.h"

 

volatile int  xdata,ydata,count;

 

void __irq AdcTsauto(void)//中断处理函数

{

U32 saveAdcdly;

if (rADCDAT0&0x8000)//判断是否为提起状态

{

Uart_Printf("\nStylus Up!\n");

rADCTSC &= 0xFF;

}

else

{

Uart_Printf("\nStylus Down!\n");

}

rADCTSC (1<<3)|(1<<2);//自动连续测量X坐标和Y坐标

saveAdcdly rADCDLY;

rADCDLY 40000;

rADCCON |= 0x01;//AD转换开始且该位在开始后清零

while (rADCCON 0x01);//判断是否开始

while (!(rADCCON 0x8000));//是否被按下

while (!(rSRCPND (BIT_ADC)));//是否发生中断

xdata (rADCDAT0 0x3FF);

ydata (rADCDAT1 0x3FF);

//Check Stylus Up Interrupt.

rSUBSRCPND |= BIT_SUB_TC;//清中断除

ClearPending(BIT_ADC);

rINTSUBMSK ~(BIT_SUB_TC);//打开屏蔽

rINTMSK ~(BIT_ADC);//打开屏蔽

rADCTSC 0xD3;

rADCTSC rADCTSC (1<<8);//检测光标抬起中断信号

while (1)

{

if (rSUBSRCPND (BIT_SUB_TC))//如果按下中断发生

{

Uart_Printf("Stylus Up Interrupt!\n");

break;

}

}

Uart_Printf("count=%d XP=d, YP=d\n", count++, xdata, ydata);

rADCTSC &=~(1<<8);//检测按下中断信号

rSUBSRCPND |= BIT_SUB_TC;

rINTSUBMSK ~(BIT_SUB_TC);

ClearPending(BIT_ADC);

}

 

void AdcTs_Test(void)

{

 

rADCDLY 50000;//设置延时

 

rADCCON (1<<14)+(9<<6);//设置a/d预分频

 

Uart_Printf("\n[ADC touch screen test.]\n");

rADCTSC 0xD3;//XP,YP输出驱动无效传

pISR_ADC (int)AdcTsauto;//中断函数入口地址向量表

rINTMSK ~BIT_ADC;//打开adc中断屏蔽

rINTSUBMSK ~(BIT_SUB_TC);//打开子中断屏蔽

Uart_Printf("\nType any key to exit.\n");

Uart_Printf("\nStylus down, please... \n");

Uart_Getch();

rINTSUBMSK |= BIT_SUB_TC;//禁止中断

rINTMSK |= BIT_ADC;//禁止中断

Uart_Printf("[Touch Screen Test.]\n");

}

 

 

 

void Main(void)

 

{

MMU_Init();//初始化内存,实现内存地址重定向

 

AdcTs_Test();

 

while(1); 

 

}

 


原创粉丝点击