GPIOIntTypeSet(GPIO_PORTF_BASE , // 设置PF1的中断类型
GPIO_PIN_1,
GPIO_LOW_LEVEL);
GPIOPinIntEnable(GPIO_PORTF_BASE , GPIO_PIN_1); // 使能PF1管脚中断
IntEnable(INT_GPIOF); // 使能GPIOF端口中断
}
//中断服务函数
void GPIO_Port_F_ISR(void)
{
unsigned long ulStatus;
uint8 t=0;
do
{
ulStatus = GPIOPinIntStatus(GPIO_PORTF_BASE , true);// 读取中断状态
t=ulStatus;
Read_Ads7846(&x,&y);
}while(t==0);
GPIOPinIntClear(GPIO_PORTF_BASE , ulStatus); // 清除中断状态,重要
}
//分别读XY坐标值10次,进行从小到大排序,取中间三位平均值
void Read_Ads7846(unsigned int *XX,unsigned int *YY)
{
uint8 t,t1,count=0;
uint16 databuffer[2][10]={{5,7,9,3,2,6,4,0,3,1},{5,7,9,3,2,6,4,0,3,1}}; //数据组
uint16 temp=0;
do //循环读数10次
{
t=ADS7843_IRQ;
if(ADS7846_Read_XY(CHX)!=0)//读数成功
{
databuffer[0][count]=ADS7846_Read_XY(CHX);
databuffer[1][count]=ADS7846_Read_XY(CHY);
count++;
}
}while(!t&&count<10);
if(count==10)//一定要读到10次数据,否则丢弃
{
do//将数据X升序排列
{
t1=0;
for(t=0;t<count-1;t++)
{
if(databuffer[0][t]>databuffer[0][t+1])//升序排列
{
temp=databuffer[0][t+1];
databuffer[0][t+1]=databuffer[0][t];
databuffer[0][t]=temp;
t1=1;
}
}
}while(t1);
do//将数据Y升序排列
{
t1=0;
for(t=0;t<count-1;t++)
{
if(databuffer[1][t]>databuffer[1][t+1])//升序排列
{
temp=databuffer[1][t+1];
databuffer[1][t+1]=databuffer[1][t];
databuffer[1][t]=temp;
t1=1;
}
}
}while(t1);
*XX=240-(databuffer[0][3]+databuffer[0][4]+databuffer[0][5])/24;
*YY=(databuffer[1][3]+databuffer[1][4]+databuffer[1][5])/18;
x=*XX;
y=*YY;
// drawbigpoint(*XX,*YY);
// return;
}
}
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>