Chinaunix首页 | 论坛 | 博客
  • 博客访问: 65063
  • 博文数量: 38
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 138
  • 用 户 组: 普通用户
  • 注册时间: 2014-02-26 16:24
文章分类

全部博文(38)

文章存档

2014年(38)

我的朋友

分类: 嵌入式

2014-03-13 16:57:22

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

#define GLOBAL_CLK 1

#include 

#include 

#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); 

 

}

 

阅读(157) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~