本帖最后由 gaoyang9992006 于 2020-10-26 09:44 编辑
优化一下源代码
//***********************************************************************************************************
// File Function: ML51 series ADC software trigger on shot demo code
//***********************************************************************************************************
#include "ML51.h"
#include "math.h"
/******************************************************************************
The main C function. Program execution starts
here after stack initialization.
******************************************************************************/
#define K 273.15
#define T0 (25.0+K)
#define R0 10000.0
#define B 3455.0
void main ()
{
unsigned int ADCRESULT;
float Rval;
float temp;
/*
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,1); //Enable ADC_CH4
ADC_ConvertTime(3,7);
//* find ADC result in ADC interrupt*/
while(1)
{
set_ADCCON0_ADCS; // Software trig adc start
while((ADCCON0|CLR_BIT7)==CLR_BIT7); // wait ADCF = 1;
ADCRESULT = (ADCRH<<4)+ADCRL;
printf("\n ADC result = %d ", ADCRESULT);
Timer0_Delay(24000000,100,5000);
Rval=1000*((ADCRESULT*6.2)/(4095-ADCRESULT));
printf("\n Rval=%d Ohm",(unsigned int)Rval);
temp=1/((1/T0)+(log(Rval/R0)/B));
printf("\n temp=%.2f",temp-K);
printf("\n----------------");
}
}
|