void ADC_Init(void) { CLK_PCKENR2 |= 0x08; ADC_CR1 = 0X02; //Fadc = 8MHz 连续转换 禁止ADC ADC_CR2 = 0X08; //右对齐 禁止扫描 禁止外部触发 ADC_TDRL = 0x01; //禁用施密特 ADC_TDRH = 0x01; //禁用施密特 ADC_DRL = 0x00; ADC_DRH = 0x00; } unsigned int ADC_GetHexValue() //CH = 0 ~ F { unsigned char AD_ValueH = 0x00; unsigned char AD_ValueL = 0x00; while((ADC_CSR & 0x80) == 0); //等待转换完毕 AD_ValueL = ADC_DRL; //存储数据 右对齐先读低位 AD_ValueH = ADC_DRH; ADC_CSR &= 0x7f; //清除ADC标志 return((unsigned int)((AD_ValueH << 8) | ADC_DRL)); |