📄 main.c
字号:
#include "S3C2410.h"
#include "config.h"
#include "UART.h"
#define LOOP 1
#define ADCPRS 39
void IRQ_Eint11(void)
{
int i;
int Pt[6];
rINTSUBMSK |=(BIT_SUB_TC); //TC interrupt request can be serviced.
rINTMSK |= (BIT_ADC);
//rINTSUBMSK |= (BIT_SUB_ADC|BIT_SUB_TC); // Mask sub interrupt (ADC and TC)
if(rADCTSC & 0x100)
{
Uart_Printf("\nStylus Up!!\n");
rADCTSC &= 0xff; // Set stylus down interrupt
}
else
{
Uart_Printf("\nStylus Down!!\n");
// <X-Position Read>
rADCTSC=(0<<8)|(0<<7)|(1<<6)|(1<<5)|(0<<4)|(1<<3)|(0<<2)|(1);
// Down,Hi-Z,AIN5,GND,Ext vlt,Pullup Dis,Normal,X-position
for(i=0;i<LOOP;i++); //delay to set up the next channel
for(i=0;i<5;i++)
{
rADCCON|=0x1; // Start X-position conversion
while(rADCCON & 0x1); // Check if Enable_start is low
while(!(0x8000&rADCCON)); // Check ECFLG
Pt[i]=(0x3ff&rADCDAT0);
}
Pt[5]=(Pt[0]+Pt[1]+Pt[2]+Pt[3]+Pt[4])/5;
Uart_Printf("X-Posion[AIN5] is %04d\n", Pt[5]);
// <Y-Position Read>
rADCTSC=(0<<8)|(1<<7)|(0<<6)|(0<<5)|(1<<4)|(1<<3)|(0<<2)|(2);
// Down,GND,Ext vlt,Hi-Z,AIN7,Pullup Dis,Normal,Y-position
for(i=0;i<LOOP;i++); //delay to set up the next channel
for(i=0;i<5;i++)
{
rADCCON|=0x1; // Start X-position conversion
while(rADCCON & 0x1); // Check if Enable_start is low
while(!(0x8000&rADCCON)); // Check ECFLG
Pt[i]=(0x3ff&rADCDAT1);
}
Pt[5]=(Pt[0]+Pt[1]+Pt[2]+Pt[3]+Pt[4])/5;
Uart_Printf("Y-Posion[AIN7] is %04d\n", Pt[5]);
rADCTSC=(1<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3);
// Up,GND,AIN,Hi-z,AIN,Pullup En,Normal,Waiting mode
}
rSUBSRCPND=BIT_SUB_TC;
rSRCPND = BIT_ADC;
rINTPND = rINTPND;
rINTSUBMSK =~(BIT_SUB_TC); //TC interrupt request can be serviced.
rINTMSK = ~(BIT_ADC);
}
void Ts_Sep(void)
{
Uart_Printf("[Touch Screen Test.]\n");
Uart_Printf("Separate X/Y position conversion mode test\n");
rADCDLY = (50000); // ADC Start or Interval Delay
rADCCON = (1<<14)|(ADCPRS<<6)|(0<<3)|(0<<2)|(0<<1)|(0);
// Enable Prescaler,Prescaler,AIN7/5 fix,Normal,Disable read start,No operation
rADCTSC = (0<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3);
// Down,YM:GND,YP:AIN5,XM:Hi-z,XP:AIN7,XP pullup En,Normal,Waiting for interrupt mode
// pISR_ADC = (unsigned)Adc_or_TsSep;
rINTSUBMSK =~(BIT_SUB_TC); //TC interrupt request can be serviced.
rINTMSK =~(BIT_ADC); //ADC interrup Sevice available.
Uart_Printf("\nType any key to exit!!!\n");
Uart_Printf("\nStylus Down, please...... \n");
Uart_Getch();
rINTSUBMSK |=(BIT_SUB_TC); //TC interrupt request can be serviced.
rINTMSK |= (BIT_ADC);
Uart_Printf("[Touch Screen Test.]\n");
}
void main(void)
{
volatile unsigned i;
Uart_Init1(0,115200);
// UART_Init();
UART_Select(0);
// 设置nYPCON、YMON、nXPCON、XMON引脚连接
rGPGUP = rGPGUP | 0xF000;
rGPGCON = rGPGCON | 0xFF000000;
// rINTMSK = 0xFFFFFFFF; // 禁止所有中断 (中断控制器)
// rINTSUBMSK = BIT_SUB_ALLMSK;
// rSRCPND = 0xFFFFFFFF; // 清除中断(源)标志
// rSUBSRCPND=0x7FF;
// rINTPND = 0xFFFFFFFF; // 清除IRQ中断标志
VICVectAddr[31]= (uint32)IRQ_Eint11;
rPRIORITY = 0x00000000; // 使用默认的固定的优先级
rINTMOD = 0x00000000; // 所有中断均为IRQ中断
IRQEnable();
while(1)
{
Ts_Sep();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -