while (!awaitkey(0))// 串口无输入,则不断测试

{

vol0 = (ReadAdc(0)*3)/1024;// 计算电压值

vol1 = (ReadAdc(1)*3)/1024;// 计算电压值

printf(“AIN0 = %dAIN1 = %dr”, vol0,vol1);

}

printf(“n”);

}

static void Isr_Tc(void)

{

if (ADCDAT0 & 0x8000)//ADCDAT0[15]为1表示触摸屏被松开

{

printf(“rnStylus Up!!nr”);

//wait_down_int();//进入“等待中断模式”,等待触摸屏被按下

}

else

{

printf(“rnStylus Down: ”);

mode_auto_xy();//进入自动(连续)X/Y轴坐标转换模式

ADCCON |= ADC_START;//设置位[0]为1,启动A/D转换

}

// 清INT_TC中断

。..

}

static void Isr_Adc(void)

{

printf(“xdata = %4d, ydata = %4drn”,(int)(ADCDAT0 & 0x3ff),(int)(ADCDAT1 & 0x3ff));

//wait_down_int();//进入“等待中断模式”,等待触摸屏被松开

//清INT_ADC中断

。..

}

void AdcTsIntHandle(void)

{

if (SUBSRCPND & BIT_SUB_TC)

Isr_Tc();

if (SUBSRCPND & BIT_SUB_ADC)

Isr_Adc();

}

/*

*测试触摸屏,打印触点坐标

*/

void Test_Ts(void)

{

isr_handle_array[ISR_ADC_OFT] = AdcTsIntHandle;// 设置ADC中断服务程序

INTMSK &= ~BIT_ADC;//开启ADC总中断

INTSUBMSK &= ~BIT_SUB_TC;//开启INT_TC中断,即触摸屏被按下或松开时产生中断

INTSUBMSK &= ~BIT_SUB_ADC;//开启INT_ADC中断,即A/D转换结束时产生中断

//使能预分频功能,设置A/D转换器的时钟 = PCLK/(49+1)

ADCCON = PRESCALE_EN | PRSCVL(49);

/*

*采样延时时间 = (1/3.6864M)*50000 = 13.56ms

*即按下触摸屏后,再过13.56ms才采样

*/

ADCDLY = 50000;

wait_down_int();/*进入“等待中断模式”,等待触摸屏被按下*/

printf(“Touch the screem to test, press any key to exit!nr”);

getc();

// 屏蔽ADC中断

。..

}

       责任编辑:pj

关于模拟技术就介绍完了,您有什么想法可以联系小编。