ADC.c 823 B

1234567891011121314151617181920212223242526272829303132
  1. #include <p33FJ64MC204.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include "ADC.h"
  5. /*******************************************************************************
  6. * 函数名称:InitADC
  7. * 功能描述:配置ADC控制寄存器
  8. *******************************************************************************/
  9. void InitADC(void)
  10. {
  11. AD1CON1bits.AD12B=1;
  12. AD1CON2=0;
  13. AD1CON2bits.VCFG=0;
  14. AD1CON3bits.ADRC=0;
  15. AD1CON3bits.SAMC=20;
  16. AD1CON3bits.ADCS=5;
  17. AD1CHS0=0;
  18. AD1CSSL=0;
  19. AD1CON1bits.FORM=0;
  20. AD1CON1bits.SSRC=7;
  21. AD1CON1bits.ASAM=0;
  22. }
  23. unsigned int AD_Get(unsigned int num)
  24. {
  25. AD1CHS0bits.CH0SA = num;
  26. AD1CON1bits.ADON = 1;
  27. AD1CON1bits.SAMP = 1;
  28. while (!AD1CON1bits.DONE);
  29. return (ADC1BUF0);
  30. }