ADC与触摸屏试验--TQ2440

#define adc_mod_auto() {ADCTSC=(1<<2)|(1<<3);} #define adc_mod_wait() {ADCTSC=(1<<6)|(1<<7);} /* 触屏中断。down中断进入自动adc转换模式,up中断就进入等待中断模式 */ static void adc_tc() { //先判断是按下还是抬起,通过读取adctsc的8bit if(ADCTSC&(1<<8)) // 1就是抬起 { printf("up the screen/n"); adc_mod_wait(); } else // 0就是按下 { printf("down the screen/n"); adc_mod_auto(); //既然是自动模式,就是不需要我们自己去配置xp xm yp ym了 } //清理中断 SUBSRCPND|=int_tc; SRCPND |=int_adc; INTPND |=int_adc; } /* adc转换完毕中断。转换完毕,读取xy值,然后进入等待中断模式 */ static void adc_s() { int x,y; x=ADCDAT0 & 0x3ff; y=ADCDAT1 & 0x3ff; printf("x=%d y=%d/n",x,y); adc_mod_wait(); //转换为等待中断模式 //清理中断 SUBSRCPND |=int_adc_s; //还需要处理下面的吗?待解决 SRCPND |=int_adc; INTPND |=int_adc; } void adc_fun() { if(SUBSRCPND & int_tc) //int_tc { adc_tc(); } if(SUBSRCPND & int_adc_s) //int_adc_s { adc_s(); } } /*adc主函数,进行各项初始化工作*/ void adc_main() {//关联adc中断 irq_list[int_adc]=adc_fun; //不能带() //开启中断 INTMSK &=~(1<<int_adc); //开启adc总中断 INTSUBMSK &=~(1<<int_adc_s); //adc子中断 INTSUBMSK &=~(1<<int_tc); //adc子中断 //使能预分频并且设置预分频adc clock =PCLK/(PRSCVL+1) ADCCON |=(1<<14)|((49)<<6); //49便于计算 //采样有延迟 ADCDLY=50000; //ok 等待中断吧 adc_mod_wait(); printf("Please touch the srceen to test,prease anykey to exit/n"); //如果有按任何键退出,get_char函数是个死循环,如果不按键就卡在这里等候中断,如果按键来就执行下去 get_char(); //屏蔽中断 INTSUBMSK |=1<<int_tc; INTSUBMSK |=1<<int_adc_s; INTMSK |=1<<int_adc; } /*测试adc的小程序,这里设置了按任何键退出,这里按任何键跟上面的不一样,getchar是个死循环,我们这里不能这样 否则无法继续while里面的测试了 */ void adc_test() { printf(" will test voltage of AIN0 and AIN1, press any key to exit /n"); while(any_key()==0) //串口无输入则进入 { printf("hello jay/n"); } }

你可能感兴趣的:(list,测试,XP,UP,化工,fun)