main.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include <stdarg.h>
  2. #include "yc11xx.h"
  3. #include "yc11xx_gpio.h"
  4. #include "yc11xx_uart.h"
  5. #include "yc_timer.h"
  6. #include "Drv_adc.h"
  7. #include "system.h"
  8. #include "btreg.h"
  9. //#define hvin_test
  10. void ADC_Configuration(void);
  11. void ADC_Test(void);
  12. /**
  13. * @brief ADC initialization function.
  14. * @param None
  15. * @retval None
  16. */
  17. void ADC_Configuration(void)
  18. {
  19. GPIO_SetGpioMultFunction(GPIO_23,GPCFG_NO_IE);
  20. ADC_InitTypeDef ADCInitStruct;
  21. ADCInitStruct.ADC_Channel = ADC_CHANNEL_5;
  22. ADCInitStruct.ADC_Mode = ADC_GPIO;
  23. #ifdef hvin_test
  24. ADCInitStruct.ADC_Mode = ADC_HVIN;
  25. #endif
  26. ADC_Init(&ADCInitStruct);
  27. #ifdef DEBUG_ADC
  28. // printf("adc_init suc, gpio mode test 0-1.2V!\n");
  29. MyPrintf("testing channel %d\n",ADCInitStruct.ADC_Channel);
  30. #endif
  31. }
  32. /**
  33. * @brief ADC test function.
  34. * @param None
  35. * @retval None
  36. */
  37. void ADC_Test(void)
  38. {
  39. int result=0;
  40. SYS_delay_ms(500);
  41. result=ADC_GetVoltage(ADC_CHANNEL_5);
  42. #ifdef DEBUG_ADC
  43. MyPrintf("ADC_Result: %d mV\n", result);
  44. #endif
  45. }
  46. int main(void)
  47. {
  48. #ifdef DEBUG_ADC
  49. printport_init();
  50. MyPrintf("This is YC11XX ADC gpio mode demo v1.0. \n");
  51. #endif
  52. SYS_TimerInit();
  53. ADC_Configuration();
  54. while(1)
  55. {
  56. SYS_delay_ms(500);
  57. ADC_Test();
  58. }
  59. }