本帖最后由 wulinwl 于 2018-5-11 21:18 编辑
每次中断只转换一个通道,分三次转换,如此反复。
/*----------------------------
Initial ADC sfr
----------------------------*/
void InitADC()
{
P1ASF = 0x07; //设置P1.0~1.2口为AD口
ADC_RES = 0; //清除结果寄存器高8位
ADC_LOW2= 0; //清除结果寄存器低2位
ADC_CONTR = ADC_POWER | ADC_SPEEDLL | ADC_START | 0x00;//启动转换
Delay(2); //ADC上电并延时
}
/*----------------------------
ADC interrupt service routine
----------------------------*/
void adc_isr() interrupt 5 using 1
{
static unsigned char CH=0;
switch(CH)
{
case 0:
ADC_CONTR &= !ADC_FLAG; //Clear ADC interrupt flag
ADC_CONTR = ADC_POWER | ADC_SPEEDLL | ADC_START |CH;
ad_out0 = (ADC_RES << 2) + ADC_LOW2; //高8位+低2位
CH++;
break;
case 1:
ADC_CONTR &= !ADC_FLAG; //Clear ADC interrupt flag
ADC_CONTR = ADC_POWER | ADC_SPEEDLL | ADC_START |CH;
ad_out1 = (ADC_RES << 2) + ADC_LOW2;//高8位+低2位
CH++;
break;
case 2:
ADC_CONTR &= !ADC_FLAG; //Clear ADC interrupt flag
ADC_CONTR = ADC_POWER | ADC_SPEEDLL | ADC_START |CH;
ad_out2 = (ADC_RES << 2) + ADC_LOW2;//高8位+低2位
CH=0;
break;
}
}
本帖最后由 wulinwl 于 2018-5-11 21:18 编辑
每次中断只转换一个通道,分三次转换,如此反复。
/*----------------------------
Initial ADC sfr
----------------------------*/
void InitADC()
{
P1ASF = 0x07; //设置P1.0~1.2口为AD口
ADC_RES = 0; //清除结果寄存器高8位
ADC_LOW2= 0; //清除结果寄存器低2位
ADC_CONTR = ADC_POWER | ADC_SPEEDLL | ADC_START | 0x00;//启动转换
Delay(2); //ADC上电并延时
}
/*----------------------------
ADC interrupt service routine
----------------------------*/
void adc_isr() interrupt 5 using 1
{
static unsigned char CH=0;
switch(CH)
{
case 0:
ADC_CONTR &= !ADC_FLAG; //Clear ADC interrupt flag
ADC_CONTR = ADC_POWER | ADC_SPEEDLL | ADC_START |CH;
ad_out0 = (ADC_RES << 2) + ADC_LOW2; //高8位+低2位
CH++;
break;
case 1:
ADC_CONTR &= !ADC_FLAG; //Clear ADC interrupt flag
ADC_CONTR = ADC_POWER | ADC_SPEEDLL | ADC_START |CH;
ad_out1 = (ADC_RES << 2) + ADC_LOW2;//高8位+低2位
CH++;
break;
case 2:
ADC_CONTR &= !ADC_FLAG; //Clear ADC interrupt flag
ADC_CONTR = ADC_POWER | ADC_SPEEDLL | ADC_START |CH;
ad_out2 = (ADC_RES << 2) + ADC_LOW2;//高8位+低2位
CH=0;
break;
}
}
举报