本帖最后由 457878 于 2014-4-24 19:07 编辑
官网搜索资料也找不到, mmuuss586 的【官方例程】改过来的也不行,通道7的ADC值是 1023, 10通道,15通道ADC值是70多?
WORD ADC_GetConversionValue(void)
{ WORD temph = 0;
BYTE templ = 0;
if ((ADC_CR2 & 0x08) != 0) /* Right alignment */
{ templ = ADC_DRL;/* Read LSB first */
temph = ADC_DRH;/* Then read MSB */
temph = (WORD)(templ | (WORD)(temph << (BYTE)8));
}
return ((WORD)temph);
}
#define ADC_CH 0x0F
WORD GetADC(void)
{
WORD ADConversion_Value;
ADC_CR2 &= (BYTE)(~0x08);
ADC_CR2 |= (BYTE)(0x08);
ADC_CR1 |= 0x02;
ADC_CSR &= (BYTE)(~0x0F);
ADC_CSR |= (BYTE)(ADC_CH); //channel
ADC_CR1 &= (BYTE)(~0x70);
ADC_CR1 |= (BYTE)(0x70);
ADC_CR2 &= (BYTE)(~0x30);
ADC_CR2 &= (BYTE)(~0x40);
ADC_CR2 |= (BYTE)(0x00);
#if (ADC_CH >8)
ADC_TDRL |= (BYTE)((BYTE)0x01 << (BYTE)ADC_CH); //0x07
#else
ADC_TDRH |= (BYTE)((BYTE)0x01 << ((BYTE)ADC_CH - (BYTE)8)); //0x0F
#endif
ADC_CR1 |= 0x01;
ADConversion_Value = ADC_GetConversionValue();
return ADConversion_Value;
}
|