ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
实验:当触笔点击在触摸屏上时,SecureCRT上显示触点的X,Y坐标; 目的:测试电阻触摸屏驱动程序; 开发板:S3C2440 ~~~ /* *版权所有(C)2015,ZJU * *文件名称:ts.c *内容摘要:关于触摸屏的配置 *其它说明:开发板型号: TX2440 * 电阻屏 *当前版本:V1.0 *作 者:Frank *完成日期:2015.12.22 * */ #define ADCCON (*(volatile unsigned int *)0x58000000) //ADC control register #define ADCTSC (*(volatile unsigned int *)0x58000004) //ADC Touch Screen Control Register #define ADCDLY (*(volatile unsigned int *)0x58000008) //ADC Start or interval delay register #define ADCDATA0 (*(volatile unsigned int *)0x5800000C) //ADC conversion data register #define ADCDATA1 (*(volatile unsigned int *)0x58000010) //ADC conversion data register /*interrupt register*/ #define SRCPND (*(volatile unsigned long *)0x4A000000) #define INTMSK (*(volatile unsigned long *)0x4A000008) #define INTPND (*(volatile unsigned long *)0x4A000010) #define INTOFFSET (*(volatile unsigned long *)0x4A000014) #define SUBSRCPND (*(volatile unsigned long *)0x4A000018) #define INTSUBMSK (*(volatile unsigned long *)0x4A00001C) int xdata=0; int ydata=0; /******************************************************************* *函数名称:Ts_Init() *功能描述:触摸屏工作初始化 *其他说明:配置ADC为触摸屏工作模式 *创建日期:2015.12.22 *******************************************************************/ void Ts_Init(void) { /*1、设置AD转换时钟*/ ADCCON = (1 << 14) | (49 << 6); //AD转换频率=PCLK/(Val + 1),此处设为 1MHz /*2、设置中断屏蔽位*/ INTMSK = ~(1 << 31); INTSUBMSK = ~(1 << 9); /*3、进入等待中断的模式*/ ADCTSC = 0xd3; /***清除CPSR寄存器中的第7位I(IRQ disable),因为在start.S中关闭了中断****/ //这一步的目的是开启总中断 __asm__( "mrs r0, cpsr\n" "bic r0, r0, #0x80\n" "msr cpsr_c, r0\n" : : ); } /******************************************************************* *函数名称:Ts_Handler() *功能描述:触摸屏中断处理 *其他说明:按下触摸屏后的中断处理 *创建日期:2015.12.22 *******************************************************************/ void Ts_Handler(void) { /*1、启动XY坐标自动转换*/ ADCTSC = (1 << 2); ADCCON |= (1 << 0); /*2、等待转换完成*/ while(!(ADCCON & (1 << 15))); /*3、获取坐标*/ xdata = ADCDATA0 & 0x3ff; ydata = ADCDATA1 & 0x3ff; /*4、清除按下中断*/ SUBSRCPND |= (1 << 9); SRCPND = (1 << 31); INTPND = (1 << 31); /*5、进入等待弹起中断*/ ADCTSC = 0xd3; ADCTSC |= (1 << 8); while(1) { if (SUBSRCPND & (1 << 9)) break; } /*6、清除弹起中断*/ SUBSRCPND |= (1 << 9); SRCPND = (1 << 31); INTPND = (1 << 31); //对读取到的X,Y坐标进行处理 printf("X is %d, Y is %d\n", xdata, ydata); printf("\n\r"); /*7、再次进入等待按下中断的状态*/ ADCTSC = 0xd3; } ~~~ 中断处理文件interrupt.c中触摸屏中断函数的调用程序: ~~~ /******************************************************************* *函数名称:handle_int() *功能描述:中断处理函数 *其他说明: *******************************************************************/ void handle_int() { /*判断产生中断的中断源*/ unsigned long value = *(INTOFFSET); switch (value) { case 31 : Ts_Handler(); //触摸屏中断 break; default : break; } } ~~~