void light_init(void) { MAP_WDT_A_holdTimer();//关闭看门狗 curADCResult = 0;//参数初始化 //配置Flash MAP_FlashCtl_setWaitState(FLASH_BANK0, 2); MAP_FlashCtl_setWaitState(FLASH_BANK1, 2); //设置DCO 为48MHz MAP_PCM_setPowerState(PCM_AM_LDO_VCORE1); //MAP_CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48); //使能FPU,进行小数点运算 MAP_FPU_enableModule(); MAP_FPU_enableLazyStacking(); //从这里开始配置ADC MAP_ADC14_enableModule(); //时钟配置 MAP_ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_4, 0); //MAP_ADC14_initModule(ADC_CLOCKSOURCE_ACLK,0,0,0); //GPIO配置,将P5.5配置为ADC输入 MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5 , GPIO_PIN5, GPIO_TERTIARY_MODULE_FUNCTION); //配置ADC存储器、通道、采样方式 MAP_ADC14_configureSingleSampleMode(ADC_MEM0, true); MAP_ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS, ADC_INPUT_A0, false); //配置采样定时器 MAP_ADC14_enableSampleTimer(ADC_MANUAL_ITERATION); //使能转换 MAP_ADC14_enableConversion(); MAP_ADC14_toggleConversionTrigger(); //中断配置 MAP_ADC14_enableInterrupt(ADC_INT0); MAP_Interrupt_enableInterrupt(INT_ADC14); MAP_Interrupt_enableMaster(); } void ADC14_IRQHandler(void) { uint64_t status = MAP_ADC14_getEnabledInterruptStatus(); MAP_ADC14_clearInterruptFlag(status);//清除中断标志 if (ADC_INT0 & status) { curADCResult = MAP_ADC14_getResult(ADC_MEM0);//得到ADC转结果 normalizedADCRes = (curADCResult * 3.3) / 16384;//结果转换为电压 //printf("%d\n", normalizedADCRes); //printf("%f\n", normalizedADCRes); //printf("%f\n", 3.3); //printf("%d.%d\n", ???); MAP_ADC14_toggleConversionTrigger();//手动开启ADC转换 } } 请将它改为DCO为6MHz的msp432的代码
时间: 2024-04-12 11:34:32 浏览: 87
meson_wdt.rar_Linux/Unix编程_Unix_Linux_
void light_init(void)
{
MAP_WDT_A_holdTimer(); //关闭看门狗
curADCResult = 0; //参数初始化
//配置Flash
MAP_FlashCtl_setWaitState(FLASH_BANK0, 2);
MAP_FlashCtl_setWaitState(FLASH_BANK1, 2);
//设置DCO为6MHz
MAP_CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_6);
//使能FPU,进行小数点运算
MAP_FPU_enableModule();
MAP_FPU_enableLazyStacking();
//从这里开始配置ADC
MAP_ADC14_enableModule();
//时钟配置
MAP_ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_4, 0);
//GPIO配置,将P5.5配置为ADC输入
MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN5, GPIO_TERTIARY_MODULE_FUNCTION);
//配置ADC存储器、通道、采样方式
MAP_ADC14_configureSingleSampleMode(ADC_MEM0, true);
MAP_ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS, ADC_INPUT_A0, false);
//配置采样定时器
MAP_ADC14_enableSampleTimer(ADC_MANUAL_ITERATION);
//使能转换
MAP_ADC14_enableConversion();
MAP_ADC14_toggleConversionTrigger();
//中断配置
MAP_ADC14_enableInterrupt(ADC_INT0);
MAP_Interrupt_enableInterrupt(INT_ADC14);
MAP_Interrupt_enableMaster();
}
void ADC14_IRQHandler(void)
{
uint64_t status = MAP_ADC14_getEnabledInterruptStatus();
MAP_ADC14_clearInterruptFlag(status); //清除中断标志
if (ADC_INT0 & status)
{
curADCResult = MAP_ADC14_getResult(ADC_MEM0); //得到ADC转结果
normalizedADCRes = (curADCResult * 3.3) / 16384; //结果转换为电压
//printf("%d\n", normalizedADCRes);
//printf("%f\n", normalizedADCRes);
//printf("%f\n", 3.3);
//printf("%d.%d\n", ???);
MAP_ADC14_toggleConversionTrigger(); //手动开启ADC转换
}
}
阅读全文