本帖最后由 weishengdianqi 于 2020-5-8 10:02 编辑
大家好,ADC P2.0对地短接就变成0,其它时间ADC采集到的ADC值一直是2048,我是用官网提供的历程
/*---------------------------------------------------------------------------------------------------------*/
/* */
/* Copyright(c) 2019 Nuvoton Technology Corp. All rights reserved. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
//***********************************************************************************************************
// Website: http://www.nuvoton.com
// E-Mail : MicroC-8bit@nuvoton.com
//***********************************************************************************************************
//***********************************************************************************************************
// File Function: ML51 series ADC software trigger on shot demo code
//***********************************************************************************************************
#include "ML51.h"
unsigned int ADCRESULT;
/******************************************************************************
* FUNCTION_PURPOSE: ADC interrupt Service Routine
******************************************************************************/
void ADC_ISR (void) interrupt 11
{
clr_ADCCON0_ADCF; //clear ADC interrupt flag
printf ("ADCRH = 0x%BX ",ADCRH); //include uart.c before use printf function.
printf ("ADCRL = 0x%BX \n ",ADCRL); //include uart.c before use printf function.
}
/******************************************************************************
The main C function. Program execution starts
here after stack initialization.
******************************************************************************/
void main ()
{
/*
For UART0 P0.5 TXD output setting
* include gipo.c in Library for GPIO mode setting
* include uart.c in Library Setting for UART0
*/
MFP_P31_UART0_TXD; // UART0 TXD use P0.5
P31_QUASI_MODE; // set P0.5 as Quasi mode for UART0 trasnfer
UART_Open(24000000,UART0_Timer3,115200); // Open UART0 use timer1 as baudrate generate and baud rate = 115200
ENABLE_UART0_PRINTF;
/*
ADCS to trig ADC convert
* include adc.c in Library for ADC initial setting
*/
ADC_Open(ADC_SINGLE,5); //Enable ADC_CH4
ADC_ConvertTime(2,7);
ADC_Interrupt(Enable,ADC_INT_SINGLE); //Enable ADC interrupt
ENABLE_GLOBAL_INTERRUPT; // Enable global interrupt
/* find ADC result in ADC interrupt*/
while(1)
{
set_ADCCON0_ADCS; // Software trig adc start
Timer0_Delay(24000000,100,1000);
ADCRESULT = (ADCRH<<4)+ADCRL;
}
}//ADCRESULT这个值一直是2048
|