今天看了一下s3c2440的touch screen control借口,完成了裸机程序的调试,把代码记录如下
其他的代码和前面做的实验基本一样,只是在ad中断里面添加了对于触摸屏的处理,初始化ad的函数有了一点点修改,只记录ad.c
ad.c
#define ADCCON (*((volatile unsigned long*)(0x58000000)))
#define ADCTSC (*((volatile unsigned long*)(0x58000004)))
#define ADCDLY (*((volatile unsigned long*)(0x58000008)))
#define ADCDAT0 (*((volatile unsigned long*)(0x5800000C)))
#define ADCDAT1 (*((volatile unsigned long*)(0x58000010)))
#define SUBSRCPND (*((volatile unsigned long*)(0X4A000018)))
#define SRCPND (*((volatile unsigned long*)(0X4A000000)))
#define INTPND (*((volatile unsigned long*)(0X4A000010)))
#define PURE_RED 0b0000011111100000
extern void change_num_string(unsigned short num, char *buffer);
extern void put_char(char ch);
extern void put_string(char *string);
unsigned short read_ad(unsigned char chanel_num)
{
/*
enable prescale operation, the value of prescaling is 49+1=50
PCLK has been set to 50MHz, so the clock of ad conventer is 1MHz
*/
ADCCON = (1<<14)|(49<<6)|(chanel_num<<3);
//set ad conventer to normal working mode
ADCTSC &= ~(1<<2);
//set ADCCON[0] to 1 in order to starting converting operation
ADCCON |= 1;
//wait converting operation to start, at that moment ADCCON[0] will be cleared
while (ADCCON & 1);
//wait till convertion operatioin stops
while (!(ADCCON&(1<<15)));
//return the result (10bits)
return (unsigned short)(ADCDAT0 & 0x3ff);
}
void init_ad(unsigned char chanel_num)
{
/*
enable prescale operation, the value of prescaling is 49+1=50
PCLK has been set to 50MHz, so the clock of ad conventer is 1MHz
*/
//ADCCON = (1<<14)|(49<<6)|(chanel_num<<3);
ADCCON = (1<<14)|(49<<6);
/*
after touch screen interrupt happens, cpu will delay 1/3.68M*50000 = 13.5ms
and start the ad converting operation for x and y
*/
ADCDLY = 50000;
//set ad conventer to normal working mode and waiting for touch screen down interrupt
ADCTSC = 0b011010011;
}
inline void start_ad()
{
//set ADCCON[0] to 1 in order to starting converting operation
ADCCON |= 1;
}
void delay(int times);
void ad_interrupt_handler()
{
if(SUBSRCPND&(1<<10)) //standard ad interrupt
{
char buffer[4];
int x, y;
unsigned short adc_result = ADCDAT0&0x3ff;
x = adc_result;
put_string("x:0x");
change_num_string(x, buffer);
put_string(buffer);
adc_result = ADCDAT1&0x3ff;
y = adc_result;
put_string(" y:0x");
change_num_string(y, buffer);
put_string(buffer);
put_char('r');
delay(10); //give com0 enough time to print information
//wait screen up interrupt
ADCTSC = 0b111010011;
//clear ad screen interrupt
SUBSRCPND = SUBSRCPND;
SRCPND |= (1<<31);
INTPND = INTPND;
}
else if(SUBSRCPND&(1<<9)) //touch screen interrupt
{
//put_string("touch screen interrupt!rn");
if(ADCTSC & (1<<8)) //it is touch up interrupt currently
{
ADCTSC = 0b011010011;
//put_string("touch screen up interrupt!rn");
//clear touch screen interrupt
SUBSRCPND = SUBSRCPND;
SRCPND |= (1<<31);
INTPND = INTPND;
}
else //it is touch down interrupt currently
{
//put_string("touch screen down interrupt!rn");
//clear touch screen interrupt first, so that standard ad interrupt can be served
SUBSRCPND = SUBSRCPND;
SRCPND |= (1<<31);
INTPND = INTPND;
ADCTSC = 0x0c; //auto xy mode
ADCCON |= (1<<0); //start the ad converting operation
}
}
}
显示16进制的xy坐标的ad转换结果:
上一篇:2440 norflash 启动进不了中断解决
下一篇:mini2440 按键驱动添加输入子系统,让按键可以真正当做键盘一样用
设计资源 培训 开发板 精华推荐
- LDK120C31R 3.1V低压降稳压器典型应用(D版)电路
- 优联HHKB-K375S带F区和拨码
- 使用符合 EN50121-3-2 标准的带有 EMC 滤波的 RP40-4805SFR DC/DC 转换器的典型应用(单输出)
- LTC4062EDD 演示板,带比较器的单节锂离子电池充电器,+Vin = 4.3V-8V,Bat = 4.2V@0.5A/1A
- LTC6259HDC 1.3MHz、20uA 高功率高效轨至轨 I/O 运算放大器的典型应用
- OP484FPZ 运算放大器噪声电路模型的典型应用,用于确定总电路等效输入噪声电压
- AKD4631-VN,带 MIC/SPK 放大器的 AK4631VN 16 位单声道编解码器评估板
- STM32F103C最小系统
- 使用 ON Semiconductor 的 ADP1148 的参考设计
- 使用 Infineon Technologies AG 的 OMR7815NM 的参考设计
- 【EEWORLD第三十七届】2012年04月社区明星人物揭晓!
- 下载Mentor白皮书,迎接电路板与晶片日益复杂的设计挑战,还有好礼相送哟!
- 雅特力AT32WB415系列蓝牙BLE 5.0 MCU,免费抢鲜体验!
- 【开发板试用】89美金FPGA开发板试用风暴来袭!
- 泰克 MSO6B 探索营:设计资源集锦
- 安森美半导体重磅推出超低功耗蓝牙芯片 RSL10 — 观视频答题送样片 更有丰富礼品等你拿!
- TE Connectivity的智能建筑解决方案——传感和连接,智能楼宇设计的关键
- TE有奖直播:未来感知 由我先知-传感器在物联网中的最新应用
- 读PI 汽车电子参考设计,赢京东卡!
- TI 工业知识挑战赛开启,一起争霸前20强,赢取属于你的荣耀!