/*---------------------------------------------------------------------------------------------------------*/
/* MAIN function */
/*---------------------------------------------------------------------------------------------------------*/
int main(void)
{
/* Unlock protected registers */
SYS_UnlockReg();
/* Init System, IP clock and multi-function I/O */
SYS_Init();
/* Lock protected registers */
SYS_LockReg();
/* Init UART0 for printf */
UART0_Init();
TIM0_Init();
GPIO_SetMode(PA,BIT9,GPIO_PMD_OUTPUT);
/*---------------------------------------------------------------------------------------------------------*/
/* SAMPLE CODE */
/*---------------------------------------------------------------------------------------------------------*/
// printf("\nSystem clock rate: %d Hz", SystemCoreClock);
/* Set the ADC operation mode as single-cycle, input mode as single-end and
enable the analog input channel 0, 1, 2 and 3 */
ADC_Open(ADC, ADC_ADCR_DIFFEN_SINGLE_END, ADC_ADCR_ADMD_SINGLE_CYCLE, 0x07);
/* Power on ADC module */
ADC_POWER_ON(ADC);
while(1)
{
/* Clear the A/D interrupt flag for safe */
ADC_CLR_INT_FLAG(ADC, ADC_ADF_INT);
/* Start A/D conversion */
ADC_START_CONV(ADC);
/* Wait conversion done */
while(!ADC_GET_INT_FLAG(ADC, ADC_ADF_INT));
i32ConversionData0 = ADC_GET_CONVERSION_DATA(ADC, 0);
i32ConversionData1 = ADC_GET_CONVERSION_DATA(ADC, 1);
i32ConversionData2 = ADC_GET_CONVERSION_DATA(ADC, 2);
if(T0_flag==1)
{
T0_flag=0;
PA9=~PA9;
printf("$ADC,%d,%d,%d,\r\n", i32ConversionData0, i32ConversionData1,i32ConversionData2);
}
}
}
|