本帖最后由 FSL_TICS_A 于 2014-5-5 11:09 编辑
MCU KEA64 开发环境cw10.5
1,原理图如图:
A/D配置代码如下:
/***********************************************************************************************
*
* @brief main() - Program entry function
* @param none
* @return none
*
************************************************************************************************/
int main(void)
{
UINT32 counter = 0;
UINT8 adc_value = 0;
Clk_Init(); /* Configure clocks to run at 20 Mhz */
GPIO_Init(); /* Configure button pins as inputs and LED pins as outputs */
ADC_Init(3,EIGTH_BIT); /* Configure ADC channel 3 in 8-bit resolution mode */
for(;;) {
counter++;
adc_value=ADC_Read(3); /* Read ADC value from channel 3 */
/* Display ADC value in LED0, LED1, LED2 and LED3*/
adc_value = adc_value >> 4;
GPIOA_PSOR |=adc_value <<16;
adc_value = (char)~adc_value ^ 0b11110000;
GPIOA_PCOR |= (adc_value) << 16;
}
return 0;
}
/***********************************************************************************************
*
* @brief ADC_Init - Initiates the Channel to read the value of the ADC channel
*
* @param Channel to init and resolution
* @return none
*
************************************************************************************************/
void ADC_Init(UINT8 channel, UINT8 mode)
{
SIM_SCGC |= SIM_SCGC_ADC_MASK;
ADC_SC1 = 0 ;
ADC_SC1|= ADC_SC1_ADCO_MASK; /* Continuous mode operation */
ADC_SC3 |= ADC_SC3_MODE(mode); /* 8,10,12 bit mode operation */
ADC_APCTL1 |= ADC_APCTL1_ADPC(1<<channel); /* Channel selection */
}
/***********************************************************************************************
*
* @brief ADC_Read - Read the selected ADC channel
* @param ch - channel to read
* @return result
*
************************************************************************************************/
UINT16 ADC_Read(UINT8 channel)
{
ADC_SC1 |= ADC_SC1_ADCH(channel); /* Select channel to read */
while(!(ADC_SC1 & ADC_SC1_COCO_MASK)); /* Wait conversion to complete */
return ADC_R; /* Return adc value */
}
用OPENSDA调试,PTA7电平是5V,为什么每次读出A/D值都是0?参照原理图A/D配置,A/D应该没有问题,不解,请高手指点!
请问谁手上有详细CW10.5使用手册,英文也行。。
|