国嵌实验:触摸屏 分类: mini2440 裸机程序 2011-09-27 15:28 17人阅读 评论(0) 收藏 举报 #define GLOBAL_CLK 1 #include <st
2012-04-28 22:41
375 查看
#define GLOBAL_CLK1
#include <stdlib.h>
#include <string.h>
#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
#include "mmu.h"
#include "profile.h"
#include "memtest.h"
#define ADC_FREQ 2500000
int count = 0;
volatile U32 preScaler;
int xdata,ydata;
void Test_Touchpanel(void);
static void __irq AdcTsAuto(void);
static void cal_cpu_bus_clk(void);
void Set_Clk(void);
/*延时函数*/
void delay(int times)
{
int i,j;
for(i=0;i<times;i++)
for(j=0;j<400;j++);
}
/*主函数*/
int Main(void)
{
int Scom=0;
Set_Clk();
Uart_Init(0,115200);
Uart_Select(Scom);
Test_Touchpanel();
while(1);
return 0;
}
/*触摸屏初始化*/
void Test_Touchpanel(void)
{
rADCDLY=50000; //Normal conversion mode delay about (1/3.6864M)*50000=13.56ms
/*设置AD转频率*/
preScaler = ADC_FREQ;
preScaler = 50000000/ADC_FREQ - 1; //PCLK=50M
rADCCON = (1<<14)|(preScaler<<6); //ADCPRS En,PRSCVL
/*设置触摸屏为等待中断模式,等待触摸笔被按下*/
rADCTSC=0xd3; //Wfait,XP_PU,XP_Dis,XM_Dis,YP_Dis,YM_En
/*clear irq*/
rSRCPND = 0x80000000;
rINTPND = 0x80000000;
ClearSubPending(BIT_SUB_TC);
pISR_ADC = (U32)AdcTsAuto;
/*enable INT_TC irq*/
rINTMSK = 0x7fffffff;
EnableSubIrq(BIT_SUB_TC);
}
/*************************************************
Function name: AdcTsAuto
Parameter : void
Description : 中断服务程序
Return : void
Argument : void
Autor & date : Daniel
**************************************************/
static void __irq AdcTsAuto(void)
{
U32 saveAdcdly;
/****************stylus down************************/
/*检测子中断源,判断是否是INT_TC中断,且触摸笔按下*/
if(rSUBSRCPND & (BIT_SUB_TC))
{
if( !(rADCDAT0&0x8000))
Uart_Printf("\nStylus down\n");
else
Uart_Printf("\nStylus up\n");
}
/*pull-up disable,自动连续X,Y坐标转换*/
rADCTSC = (1<<3)|(1<<2);
saveAdcdly=rADCDLY;
rADCDLY=40000; //Normal conversion mode delay about (1/50M)*40000=0.8ms
/*开始AD转换*/
rADCCON|=0x1; //start ADC
while(rADCCON & 0x1); //check if Enable_start is low
while(!(rADCCON & 0x8000)); //check if EC(End of Conversion) flag is high, This line is necessary~!!
while(!(rSRCPND & 0x80000000)); //check if ADC is finished with interrupt bit
/*获取X,Y坐标*/
xdata=(rADCDAT0&0x3ff);
ydata=(rADCDAT1&0x3ff);
ClearSubPending(BIT_SUB_TC);
//ClearPending(BIT_ADC);
rSRCPND = 0x80000000;
rINTPND = 0x80000000;
EnableSubIrq(BIT_SUB_TC);
//EnableIrq(BIT_ADC);
rINTMSK = 0x7fffffff;
/****************stylus down************************/
/****************stylus up**************************/
/*设置触摸屏为等待中断模式,等待触摸笔抬起*/
rADCTSC =0xd3; //Waiting for interrupt
rADCTSC=rADCTSC|(1<<8); // Detect stylus up interrupt signal.
while(1)
//to check Pen-up state
{
if(rSUBSRCPND & (BIT_SUB_TC))//check if ADC is finished with interrupt bit
{
Uart_Printf("Stylus Up Interrupt~!\n");
break;
//if Stylus is up(1) state
}
}
/****************stylus up**************************/
Uart_Printf("count=%03d XP=%04d, YP=%04d\n", count++, xdata, ydata);
rADCDLY=saveAdcdly;
/*设置触摸屏为等待中断模式,等待下次触摸笔按下*/
rADCTSC =0xd3; //Waiting for interrupt
ClearSubPending(BIT_SUB_TC);
//ClearPending(BIT_ADC);
rSRCPND = 0x80000000;
rINTPND = 0x80000000;
EnableSubIrq(BIT_SUB_TC);
//EnableIrq(BIT_ADC);
rINTMSK = 0x7fffffff;
}
/*************************************************
Function name: Set_Clk()
Parameter : void
Description : 设置CPU的时钟频率
Return : void
Argument : void
Autor & date : Daniel
**************************************************/
void Set_Clk(void)
{
int i;
U8 key;
U32 mpll_val = 0 ;
i = 2 ;
//don't use 100M!
//boot_params.cpu_clk.val = 3;
switch ( i ) {
case 0:
//200
key = 12;
mpll_val = (92<<12)|(4<<4)|(1);
break;
case 1:
//300
key = 13;
mpll_val = (67<<12)|(1<<4)|(1);
break;
case 2:
//400
key = 14;
mpll_val = (92<<12)|(1<<4)|(1);
break;
case 3:
//440!!!
key = 14;
mpll_val = (102<<12)|(1<<4)|(1);
break;
default:
key = 14;
mpll_val = (92<<12)|(1<<4)|(1);
break;
}
//init FCLK=400M, so change MPLL first
ChangeMPllValue((mpll_val>>12)&0xff, (mpll_val>>4)&0x3f, mpll_val&3); //set the register--rMPLLCON
ChangeClockDivider(key, 12); //the result of rCLKDIVN [0:1:0:1] 3-0 bit
cal_cpu_bus_clk(); //HCLK=100M PCLK=50M
}
/*************************************************
Function name: cal_cpu_bus_clk
Parameter : void
Description : 设置PCLK\HCLK\FCLK的频率
Return : void
Argument : void
Autor & date : Daniel
**************************************************/
static void cal_cpu_bus_clk(void)
{
static U32 cpu_freq;
static U32 UPLL;
U32 val;
U8 m, p, s;
val = rMPLLCON;
m = (val>>12)&0xff;
p = (val>>4)&0x3f;
s = val&3;
//(m+8)*FIN*2 不要超出32位数!
FCLK = ((m+8)*(FIN/100)*2)/((p+2)*(1<<s))*100; //FCLK=400M FIN=12000000
val = rCLKDIVN;
m = (val>>1)&3;
p = val&1;
val = rCAMDIVN;
s = val>>8;
switch (m) {
case 0:
HCLK = FCLK;
break;
case 1:
HCLK = FCLK>>1;
break;
case 2:
if(s&2)
HCLK = FCLK>>3;
else
HCLK = FCLK>>2;
break;
case 3:
if(s&1)
HCLK = FCLK/6;
else
HCLK = FCLK/3;
break;
}
if(p)
PCLK = HCLK>>1;
else
PCLK = HCLK;
if(s&0x10)
cpu_freq = HCLK;
else
cpu_freq = FCLK;
val = rUPLLCON;
m = (val>>12)&0xff;
p = (val>>4)&0x3f;
s = val&3;
UPLL = ((m+8)*FIN)/((p+2)*(1<<s));
UCLK = (rCLKDIVN&8)?(UPLL>>1):UPLL;
}
相关文章推荐
- uboot启动后在内存中运行裸机程序hello 分类: HI3531 arm-linux-Ubuntu 2013-12-12 10:20 836人阅读 评论(0) 收藏
- 分类: linux程序设计 2012-03-06 22:01 10646人阅读 评论(5) 收藏 举报 linux语言c工具gcc程序开发 调试是每个程序员都会面临的问题. 如何提高程序员的调
- hibernate学习-实体类与数据库表映射 分类: Hibernate 2012-11-01 17:21 541人阅读 评论(0) 收藏 举报 1.根据实体类名获取表名 Map<String, A
- 让web程序也能自动安装 分类: WEB项目应用 2009-12-01 17:02 488人阅读 评论(0) 收藏
- iOS库 .a与.framework区别 2015-01-25 15:54 7452人阅读 评论(0) 收藏 举报 分类: iOS(278) 目录(?) [+] 一、什么是库? 库是共享程序代
- 《Go语言入门》第一个Go语言程序——HelloWorld 标签: go语言helloworld 2015-11-29 18:46 4066人阅读 评论(4) 收藏 举报 分类: go语言入门(3)
- android主题Theme.NoTitleBar.Fullscreen下如何设置程序的字体颜色为黑色 分类: Android界面和组件 2014-06-21 14:04 162人阅读 评论(0) 收藏
- 利用NuSoap开发WebService(PHP) 分类: php 2010-09-08 12:00 5832人阅读 评论(1) 收藏 举报 webservicephpsoapstringencod
- Merge k Sorted Lists 分类: Leetcode(树) 2015-04-09 09:35 17人阅读 评论(0) 收藏
- Error LNK2001 无法解析的外部符号 的几种情况及解决办法 标签: mfc编译器编程c 2011-08-18 22:48 199753人阅读 评论(10) 收藏 举报 分类: Debug
- C# 中的委托和事件 分类: .NET 接口+泛型+委托+继承 2011-08-30 10:09 20人阅读 评论(0) 收藏 举报 引言 委托 和 事件在 .Net Framework中的应用非
- RHEL64 缺少ISO 9660图像 安装程序试图挂载映像#1,在硬盘上无法找到该映像 分类: arm-linux-Ubuntu 2015-01-20 16:47 644人阅读 评论(0) 收藏
- Volecity模板引擎学习笔记<一> 标签: 模板引擎volecity 2016-03-20 17:29 1229人阅读 评论(0) 收藏 举报 分类: Java开发(36) web前端(13
- jsp中,ajax提交表单用法 分类: ajax 2011-07-29 14:59 3746人阅读 评论(0) 收藏 举报 jspajaxinputbuttonactionfunction 一:
- 多线程之GCD(一) 分类: ios开发 2015-04-17 17:58 357人阅读 评论(0) 收藏
- Android自定义控件系列二:自定义开关按钮(一) 标签: Android自定义控件Java开关按钮自定义组件 2014-11-03 10:55 2735人阅读 评论(6) 收藏 举报 分类: J
- UI基础:UI程序执行顺序(UIApplicationMain()函数),自定义视图 分类: iOS学习-UI 2015-07-02 22:09 68人阅读 评论(0) 收藏
- 金融风控-->申请评分卡模型-->特征工程(特征分箱,WOE编码) 标签: 金融特征分箱-WOE编码 2017-07-16 21:26 4086人阅读 评论(2) 收藏 举报 分类: 金融风
- 数据结构实验:连通分量个数 分类: 图论 2015-06-09 17:33 8人阅读 评论(0) 收藏